anon.pay
Class PayAccount

java.lang.Object
  extended by anon.pay.PayAccount
All Implemented Interfaces:
IXMLEncodable

public class PayAccount
extends java.lang.Object
implements IXMLEncodable

This class encapsulates one account and all additional data associated to one account. This includes the key pair, the account number, the transfer certificates for charging the account, cost confirmations and a balance certificate. - XMLAccountcertificate (public key + additional info (creation date etc)) - Key Pair - XMLTransCert (one per charge) - XMLAccountInfo (XMLBalance + cost confirmations) - XMLGenericText : contains the terms and conditions (as current at the time of account creation) For storing the account data in a file the toXmlElement() method is provided. It is recommended to encrypt the output of this method before storing it to disk, because it includes the secret private key. The XML structure is as follows: ... // see anon.pay.xml.XMLAccountCertificate ... // the secret key. this can be either RSA or DSA ... // see anon.pay.xml.XMLTransCert .... ... // see anon.pay.xml.XMLAccountInfo Zipped Text!! //cf. anon.pay.xml.XMLGenericText

Author:
Andreas Mueller, Grischan Glänzel, Bastian Voigt, Tobias Bayer

Field Summary
static long ACCOUNT_MAX_UPDATE_INTERVAL_MS
           
static long ACCOUNT_MIN_UPDATE_INTERVAL_MS
           
private  XMLAccountCertificate m_accountCertificate
          contains the account certificate
private  XMLAccountInfo m_accountInfo
          contains the current account info (balance and cost confirmations)
private  java.util.Vector m_accountListeners
           
private  boolean m_bAccountInfoUpdateRunning
           
private  long m_currentBytes
          the number of bytes which have been used but not confirmed yet
private  org.w3c.dom.Document m_encryptedPrivateKey
           
private  long m_lastAccountInfoUpdate
           
private  long m_lBackupDone
           
private  java.util.Vector m_messageListeners
           
private  long m_mySpent
          internal value for spent bytes.
private  IMyPrivateKey m_privateKey
          contains the private key associated with this account
private  java.lang.String m_strBiID
           
private  XMLGenericText m_terms
          contains the terms and conditions as gotten from the JPI when the account was created
private  java.util.Calendar m_termsDate
           
private  PaymentInstanceDBEntry m_theBI
           
private  java.util.Vector m_transCerts
          contains zero or more xml transfer certificates as XMLTransCert
static int MAX_KBYTES_COUNTING_AS_EMPTY
           
private static long NEW_ACCOUNT_EXPIRATION_TIME
           
private  java.lang.Object SYNC_BYTES
           
private static long TRANSACTION_EXPIRATION
           
private static java.lang.String VERSION
           
private static java.lang.String XML_ATTR_ACTIVE
           
private static java.lang.String XML_BACKUP_DONE
           
static java.lang.String XML_ELEMENT_NAME
           
 
Fields inherited from interface anon.util.IXMLEncodable
FIELD_XML_ELEMENT_CONTAINER_NAME, FIELD_XML_ELEMENT_NAME, XML_ATTR_ID, XML_ATTR_LANGUAGE, XML_ATTR_VERSION
 
Constructor Summary
PayAccount(org.w3c.dom.Element elemRoot, IMiscPasswordReader a_passwordReader)
           
PayAccount(XMLAccountCertificate certificate, IMyPrivateKey privateKey, PaymentInstanceDBEntry theBI, XMLGenericText terms)
          Creates a PayAccount Objekt from the account certificate and the private key.
 
Method Summary
 void addAccountListener(IAccountListener listener)
           
 long addCostConfirmation(XMLEasyCC cc)
          addCostConfirmation
 void addMessageListener(IMessageListener listener)
           
 void addTransCert(XMLTransCert cert)
           
 XMLTransCert charge(XMLGenericStrings a_parameters)
          Request a transfer certificate from the BI
static java.lang.String checkCouponCode(java.lang.String a_code)
           
private  void deactivate(org.w3c.dom.Element elemKey)
           
 void decryptPrivateKey(IMiscPasswordReader a_passwordReader)
           
private  void decryptPrivateKey(org.w3c.dom.Node a_elemRoot, IMiscPasswordReader a_passwordReader, boolean a_bDeactivated)
           
 boolean equals(java.lang.Object a_account)
           
 void fetchAccountInfo(boolean a_bForce)
          Requests an AccountInfo XML structure from the BI.
 void fetchAccountInfo(boolean a_bForce, int a_connectionTimeout)
           
private  void fireChangeEvent()
           
private  void fireMessageReceived(PayMessage message)
           
private  void fireMessageRemoved(PayMessage message)
           
 XMLAccountCertificate getAccountCertificate()
           
 XMLAccountInfo getAccountInfo()
           
 long getAccountNumber()
          Returns the account's accountnumber
 long getBackupTime()
           
 XMLBalance getBalance()
          getBalance
 java.sql.Timestamp getBalanceValidTime()
          liefert zurueck, wann das Guthaben ungueltig wird (bei flatrate modellen)
 PaymentInstanceDBEntry getBI()
           
 java.sql.Timestamp getCreationTime()
          Liefert das Erstellungsdatum des Kontos.
 long getCurrentBytes()
           
 long getCurrentCredit()
          Returns the current credit (i.
 long getCurrentCreditCalculated()
          Returns the current credit (i.
 long getCurrentCreditCalculatedAlsoNegative()
           
 long getCurrentCreditFromBalance()
           
 long getCurrentSpent()
          returns totalBytes - getCurrentCredit() in BYTES or 0 if no accountInfo is given.
 long getDeposit()
          Returns the initial amount of the account (i.
 java.lang.String getPIID()
           
 IMyPrivateKey getPrivateKey()
          Returns the private key or null if the account is encrypted and not usable.
 IMyPublicKey getPublicKey()
           
 long getSpent()
          Returns the amount already spent.
 XMLGenericText getTerms()
           
 java.util.Calendar getTermsDate()
           
 java.util.Vector getTransCerts()
          Returns a vector with all transfer certificates
 boolean hasAccountInfo()
          Returns true when an accountInfo object exists.
 boolean hasExpired()
           
 boolean hasExpired(java.sql.Timestamp a_time)
           
 int hashCode()
           
 boolean isAccountInfoUpdated()
          Returns true if the account info/balance has been updated at least once at runtime.
 boolean isBackupDone()
           
 boolean isCharged(java.sql.Timestamp a_time)
          Returns true if this account currently has a positive and usable balance.
 boolean isFlatrateActive()
           
 boolean isTransactionExpired()
           
 void removeMessageListener(IMessageListener listener)
           
 void resetCurrentBytes()
           
private  void setAccountInfo(XMLAccountInfo info)
          This is not just a setter method.
 void setBackupDone(long a_backupTime)
           
 void setTerms(XMLGenericText xmlTerms)
           
private  void setValues(org.w3c.dom.Element elemRoot, IMiscPasswordReader a_passwordReader)
           
 boolean shouldUpdateAccountInfo()
           
 org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
          Returns the xml representation of the account
 org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc, java.lang.String a_password)
           
 void updateCurrentBytes(long a_additionalBytes)
           
 long updateCurrentBytes(PacketCounter a_packetCounter)
          Asks the PacketCounter for the current number of transferred bytes and updates the internal value.
 void updated()
          Marks the account as updated so a ChangeEvent gets fired
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_ELEMENT_NAME

public static final java.lang.String XML_ELEMENT_NAME
See Also:
Constant Field Values

XML_ATTR_ACTIVE

private static final java.lang.String XML_ATTR_ACTIVE
See Also:
Constant Field Values

XML_BACKUP_DONE

private static final java.lang.String XML_BACKUP_DONE
See Also:
Constant Field Values

ACCOUNT_MIN_UPDATE_INTERVAL_MS

public static final long ACCOUNT_MIN_UPDATE_INTERVAL_MS
See Also:
Constant Field Values

ACCOUNT_MAX_UPDATE_INTERVAL_MS

public static final long ACCOUNT_MAX_UPDATE_INTERVAL_MS
See Also:
Constant Field Values

SYNC_BYTES

private final java.lang.Object SYNC_BYTES

NEW_ACCOUNT_EXPIRATION_TIME

private static final long NEW_ACCOUNT_EXPIRATION_TIME
See Also:
Constant Field Values

VERSION

private static final java.lang.String VERSION
See Also:
Constant Field Values

m_transCerts

private java.util.Vector m_transCerts
contains zero or more xml transfer certificates as XMLTransCert


m_accountCertificate

private XMLAccountCertificate m_accountCertificate
contains the account certificate


m_accountInfo

private XMLAccountInfo m_accountInfo
contains the current account info (balance and cost confirmations)


m_terms

private XMLGenericText m_terms
contains the terms and conditions as gotten from the JPI when the account was created


m_privateKey

private IMyPrivateKey m_privateKey
contains the private key associated with this account


m_encryptedPrivateKey

private org.w3c.dom.Document m_encryptedPrivateKey

m_currentBytes

private long m_currentBytes
the number of bytes which have been used but not confirmed yet


m_accountListeners

private java.util.Vector m_accountListeners

m_messageListeners

private java.util.Vector m_messageListeners

m_lBackupDone

private long m_lBackupDone

m_lastAccountInfoUpdate

private long m_lastAccountInfoUpdate

m_bAccountInfoUpdateRunning

private boolean m_bAccountInfoUpdateRunning

m_termsDate

private java.util.Calendar m_termsDate

TRANSACTION_EXPIRATION

private static final long TRANSACTION_EXPIRATION
See Also:
Constant Field Values

MAX_KBYTES_COUNTING_AS_EMPTY

public static final int MAX_KBYTES_COUNTING_AS_EMPTY
See Also:
Constant Field Values

m_mySpent

private long m_mySpent
internal value for spent bytes. Basically this is the same as spent in XMLBalance, but the value in XMLBalance is calculated by the BI while this here is calculated by the Jap. So the value here might be more up to date in case the XMLBalance certificate is old.


m_theBI

private PaymentInstanceDBEntry m_theBI

m_strBiID

private java.lang.String m_strBiID
Constructor Detail

PayAccount

public PayAccount(org.w3c.dom.Element elemRoot,
                  IMiscPasswordReader a_passwordReader)
           throws java.lang.Exception
Throws:
java.lang.Exception

PayAccount

public PayAccount(XMLAccountCertificate certificate,
                  IMyPrivateKey privateKey,
                  PaymentInstanceDBEntry theBI,
                  XMLGenericText terms)
Creates a PayAccount Objekt from the account certificate and the private key.

Parameters:
certificate - account certificate issued by the BI
privateKey - the private key
Method Detail

isTransactionExpired

public boolean isTransactionExpired()

setValues

private void setValues(org.w3c.dom.Element elemRoot,
                       IMiscPasswordReader a_passwordReader)
                throws java.lang.Exception
Parameters:
elemRoot - Element
a_passwordReader - a password reader; this method adds the account number as message object
Throws:
java.lang.Exception

toXmlElement

public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
Returns the xml representation of the account

Specified by:
toXmlElement in interface IXMLEncodable
Parameters:
a_doc - a document
Returns:
XML-Document

toXmlElement

public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc,
                                        java.lang.String a_password)

addTransCert

public void addTransCert(XMLTransCert cert)
                  throws java.lang.Exception
Throws:
java.lang.Exception

setAccountInfo

private void setAccountInfo(XMLAccountInfo info)
                     throws java.lang.Exception
This is not just a setter method. If an accountInfo is already present, only older information is overwritten with newer information. (i.e. does NOT replace the old saved balance, only those parts you explicitly set)

Parameters:
info - XMLAccountInfo
Throws:
java.lang.Exception

equals

public boolean equals(java.lang.Object a_account)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getAccountNumber

public long getAccountNumber()
Returns the account's accountnumber

Returns:
accountnumber

hasExpired

public boolean hasExpired()

hasExpired

public boolean hasExpired(java.sql.Timestamp a_time)

isCharged

public boolean isCharged(java.sql.Timestamp a_time)
Returns true if this account currently has a positive and usable balance.

Returns:
boolean

isBackupDone

public boolean isBackupDone()

getBackupTime

public long getBackupTime()

setBackupDone

public void setBackupDone(long a_backupTime)

hasAccountInfo

public boolean hasAccountInfo()
Returns true when an accountInfo object exists. New accounts don't have this, it is created when we first fetch a balance certificate or sign the first CC.


getAccountCertificate

public XMLAccountCertificate getAccountCertificate()

getCreationTime

public java.sql.Timestamp getCreationTime()
Liefert das Erstellungsdatum des Kontos.

Returns:
Erstellungsdatum

getBalanceValidTime

public java.sql.Timestamp getBalanceValidTime()
liefert zurueck, wann das Guthaben ungueltig wird (bei flatrate modellen)

Returns:
Date Gueltigkeitsdatum

getPrivateKey

public IMyPrivateKey getPrivateKey()
Returns the private key or null if the account is encrypted and not usable.

Returns:
the private key or null if the account is encrypted and not usable

getPublicKey

public IMyPublicKey getPublicKey()

getSpent

public long getSpent()
Returns the amount already spent.

Returns:
Gesamtsumme

getDeposit

public long getDeposit()
Returns the initial amount of the account (i. e. the sum of all incoming payment)

Returns:
Gesamtsumme

getCurrentCreditCalculated

public long getCurrentCreditCalculated()
Returns the current credit (i. e. deposit - spent) as certified by the BI. It is possible that this value is outdated, so it may be a good idea to call Pay.fetchAccountInfo(long) first.

Returns:
Guthaben

getCurrentCreditCalculatedAlsoNegative

public long getCurrentCreditCalculatedAlsoNegative()

getCurrentCreditFromBalance

public long getCurrentCreditFromBalance()

getCurrentCredit

public long getCurrentCredit()
Returns the current credit (i. e. deposit - spent) as counted by the Jap itself. It is possible that this value is outdated, so it may be a good idea to call updateCurrentBytes() first.

Returns:
current credit in KBYTES (for some weird compatibility reasons)

getCurrentSpent

public long getCurrentSpent()
returns totalBytes - getCurrentCredit() in BYTES or 0 if no accountInfo is given. (the methods getCurentSpent and getCurrentCredit are self calculated counterparts of the PI-determined getBalance().getSpent() and getBalance.getVolumeKBytesLeft(). Because one of them returns kbytes and the other bytes getCurentSpent and getCurrentCredit have to behave the same way)

Returns:

getAccountInfo

public XMLAccountInfo getAccountInfo()

getTerms

public XMLGenericText getTerms()

setTerms

public void setTerms(XMLGenericText xmlTerms)

getTermsDate

public java.util.Calendar getTermsDate()

getTransCerts

public java.util.Vector getTransCerts()
Returns a vector with all transfer certificates

Returns:
Vector von XMLTransCert

updateCurrentBytes

public long updateCurrentBytes(PacketCounter a_packetCounter)
                        throws java.lang.Exception
Asks the PacketCounter for the current number of transferred bytes and updates the internal value.

Returns:
the updated currentBytes value
Throws:
java.lang.Exception

resetCurrentBytes

public void resetCurrentBytes()

updateCurrentBytes

public void updateCurrentBytes(long a_additionalBytes)

getCurrentBytes

public long getCurrentBytes()

addCostConfirmation

public long addCostConfirmation(XMLEasyCC cc)
                         throws java.lang.Exception
addCostConfirmation

Throws:
java.lang.Exception

addAccountListener

public void addAccountListener(IAccountListener listener)

addMessageListener

public void addMessageListener(IMessageListener listener)

removeMessageListener

public void removeMessageListener(IMessageListener listener)

fireChangeEvent

private void fireChangeEvent()

fireMessageReceived

private void fireMessageReceived(PayMessage message)

fireMessageRemoved

private void fireMessageRemoved(PayMessage message)

getBalance

public XMLBalance getBalance()
getBalance

Returns:
XMLBalance

isFlatrateActive

public boolean isFlatrateActive()

fetchAccountInfo

public void fetchAccountInfo(boolean a_bForce)
                      throws java.lang.SecurityException,
                             java.lang.Exception
Requests an AccountInfo XML structure from the BI.

Parameters:
a_bForce - if the update is forced; if not, it might be prevented by PayAccountsFile.isBalanceAutoUpdateEnabled()
Throws:
java.lang.Exception
java.lang.SecurityException - if the account is encrypted and therefore not usable

fetchAccountInfo

public void fetchAccountInfo(boolean a_bForce,
                             int a_connectionTimeout)
                      throws java.lang.SecurityException,
                             java.lang.Exception
Throws:
java.lang.SecurityException
java.lang.Exception

isAccountInfoUpdated

public boolean isAccountInfoUpdated()
Returns true if the account info/balance has been updated at least once at runtime.

Returns:

shouldUpdateAccountInfo

public boolean shouldUpdateAccountInfo()

charge

public XMLTransCert charge(XMLGenericStrings a_parameters)
                    throws java.lang.SecurityException,
                           java.lang.Exception
Request a transfer certificate from the BI

Parameters:
accountNumber - account number
Returns:
xml transfer certificate
Throws:
java.lang.Exception
java.lang.SecurityException - if the account is encrypted an not usable

updated

public void updated()
Marks the account as updated so a ChangeEvent gets fired


getPIID

public java.lang.String getPIID()

getBI

public PaymentInstanceDBEntry getBI()

checkCouponCode

public static java.lang.String checkCouponCode(java.lang.String a_code)

decryptPrivateKey

public void decryptPrivateKey(IMiscPasswordReader a_passwordReader)
                       throws java.lang.Exception
Throws:
java.lang.Exception

decryptPrivateKey

private void decryptPrivateKey(org.w3c.dom.Node a_elemRoot,
                               IMiscPasswordReader a_passwordReader,
                               boolean a_bDeactivated)
                        throws java.lang.Exception
Throws:
java.lang.Exception

deactivate

private void deactivate(org.w3c.dom.Element elemKey)
                 throws java.lang.Exception
Throws:
java.lang.Exception