Cumulus4j API
(1.1.0)

org.cumulus4j.store.crypto
Class AbstractCryptoSession

java.lang.Object
  extended by org.cumulus4j.store.crypto.AbstractCryptoSession
All Implemented Interfaces:
CryptoSession
Direct Known Subclasses:
KeyManagerCryptoSession

public abstract class AbstractCryptoSession
extends Object
implements CryptoSession

Abstract base-class for implementing CryptoSessions.

Author:
Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de

Field Summary
 
Fields inherited from interface org.cumulus4j.store.crypto.CryptoSession
PROPERTY_CRYPTO_SESSION_ID
 
Constructor Summary
AbstractCryptoSession()
           
 
Method Summary
protected  void assertNotClosed()
          Throws an IllegalStateException, if this session is already closed.
 void close()
          Close the session.
 Date getCreationTimestamp()
           
 CryptoManager getCryptoManager()
           Get the CryptoManager to which this session belongs.
 String getCryptoSessionID()
           
 String getKeyStoreID()
           
 Date getLastUsageTimestamp()
           Get the timestamp of the last call to #release().
 boolean isClosed()
          Indicate, whether the session was already closed.
 void setCryptoManager(CryptoManager cryptoManager)
           Set the CryptoManager to which this session belongs.
 void setCryptoSessionID(String cryptoSessionID)
           Set the cryptoSessionID.
 void updateLastUsageTimestamp()
           Set the lastUsageTimestamp to now, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.cumulus4j.store.crypto.CryptoSession
decrypt, encrypt
 

Constructor Detail

AbstractCryptoSession

public AbstractCryptoSession()
Method Detail

getCryptoManager

public CryptoManager getCryptoManager()
Description copied from interface: CryptoSession

Get the CryptoManager to which this session belongs.

Specified by:
getCryptoManager in interface CryptoSession
Returns:
the CryptoManager to which this session belongs.

setCryptoManager

public void setCryptoManager(CryptoManager cryptoManager)
Description copied from interface: CryptoSession

Set the CryptoManager to which this session belongs.

If you subclass AbstractCryptoManager (instead of directly implementing the CryptoManager interface) you must never call this method. Otherwise, it is expected, that you call this method once in CryptoManager.getCryptoSession(String) after creating a new CryptoSession, before returning it.

Specified by:
setCryptoManager in interface CryptoSession
Parameters:
cryptoManager - the CryptoManager to which this session belongs.
See Also:
CryptoSession.getCryptoManager()

getCryptoSessionID

public String getCryptoSessionID()
Specified by:
getCryptoSessionID in interface CryptoSession

setCryptoSessionID

public void setCryptoSessionID(String cryptoSessionID)
Description copied from interface: CryptoSession

Set the cryptoSessionID.

If you subclass AbstractCryptoManager (instead of directly implementing the CryptoManager interface) you must never call this method. Otherwise, it is expected, that you call this method once in CryptoManager.getCryptoSession(String) after creating a new CryptoSession, before returning it.

Specified by:
setCryptoSessionID in interface CryptoSession
Parameters:
cryptoSessionID - the identifier of this session.
See Also:
CryptoSession.getCryptoSessionID()

getKeyStoreID

public String getKeyStoreID()
Specified by:
getKeyStoreID in interface CryptoSession

getCreationTimestamp

public Date getCreationTimestamp()
Specified by:
getCreationTimestamp in interface CryptoSession

getLastUsageTimestamp

public Date getLastUsageTimestamp()
Description copied from interface: CryptoSession

Get the timestamp of the last call to #release(). If #release() was not yet called, get the time when this instance was created (just like CryptoSession.getCreationTimestamp() does).

Therefore, this method always returns the time when the session was stopped being used the last time.

This timestamp is used for automatic closing of expired sessions.

Specified by:
getLastUsageTimestamp in interface CryptoSession
Returns:
the timestamp of the last usage of this session.

updateLastUsageTimestamp

public void updateLastUsageTimestamp()
Description copied from interface: CryptoSession

Set the lastUsageTimestamp to now, i.e. new Date().

This method should be called by CryptoManager.getCryptoSession(String).

Specified by:
updateLastUsageTimestamp in interface CryptoSession
See Also:
CryptoSession.getLastUsageTimestamp()

isClosed

public boolean isClosed()
Indicate, whether the session was already closed.

Implementors should use assertNotClosed() in their subclasses to check whether the operation is still allowed.

Specified by:
isClosed in interface CryptoSession
Returns:
true, if CryptoSession.close() was already called; false otherwise.

assertNotClosed

protected void assertNotClosed()
Throws an IllegalStateException, if this session is already closed.


close

public void close()

Close the session.

After closing, the CryptoSession cannot be used for encryption/decryption anymore, i.e. CryptoSession.encrypt(CryptoContext, Plaintext) and CryptoSession.decrypt(CryptoContext, Ciphertext) very likely throw an exception. The other methods might still work.

This method can be called multiple times - every following call will be silently ignored.

When overriding this method, you should first call super.close(); and then perform your own closing operations.

Specified by:
close in interface CryptoSession

Cumulus4j API
(1.1.0)

Copyright © 2013 NightLabs Consulting GmbH. All Rights Reserved.