com.atlassian.crowd.manager.token
Class SwitchableTokenManagerImpl

java.lang.Object
  extended by com.atlassian.crowd.manager.token.SwitchableTokenManagerImpl
All Implemented Interfaces:
SearchableTokenStorage, SessionTokenStorage, SearchableTokenService, SwitchableTokenManager, TokenManager

@ThreadSafe
@Transactional
public class SwitchableTokenManagerImpl
extends Object
implements SwitchableTokenManager, SearchableTokenService

Proxies the concrete TokenDAO implementations, and allows runtime swapping between implementations, along with copying of data between during swap.


Constructor Summary
SwitchableTokenManagerImpl(boolean initialUseIsMemory, TokenDAO daoMemory, TokenDAO daoHibernate, PropertyManager propertyManager)
           
SwitchableTokenManagerImpl(TokenDAO daoMemory, TokenDAO daoHibernate, PropertyManager propertyManager)
           
 
Method Summary
 Token add(Token token)
          Persists a new token.
 Token findByIdentifierHash(String identifierHash)
          Finds token by identifier hash.
 Token findByRandomHash(String randomHash)
          Finds token by random hash.
 boolean isUsingDatabaseStorage()
          Returns true if the memory token manager is in use.
protected  void move(TokenDAO to, TokenDAO from)
          Copies tokens from hibernate to in-memory DAO or vice versa, and upon success deletes the tokens from the source.
 void remove(long directoryID, String name)
          Remove token.
 void remove(Token token)
          Removes a token.
 void removeAll()
          Removes all tokens from all implementations.
 void removeAll(long directoryId)
          Remove all tokens associated with the given directory id.
 void removeExcept(long directoryId, String name, String exclusionToken)
          Remove all tokens for the user except for the token specified by exclusionToken.
 void removeExpiredTokens(Date currentTime, long maxLifeSeconds)
          Remove all tokens that have expired.
 List<Token> search(EntityQuery<? extends Token> query)
          Searches for token based on criteria.
 void setUsingDatabaseStorage(boolean useDatabaseStorage)
          Performs the switch, if necessary.
 void switchToHibernate()
          If the In-memory DAO is in use, transparently switches to Hibernate DAO.
 void switchToMemory()
          If the Hibernate DAO is in use, transparently switches to In-memory DAO.
 Token update(Token token)
           
 void updateTokenStorage()
          Updates the switchable token manager to match the current configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwitchableTokenManagerImpl

public SwitchableTokenManagerImpl(boolean initialUseIsMemory,
                                  TokenDAO daoMemory,
                                  TokenDAO daoHibernate,
                                  PropertyManager propertyManager)

SwitchableTokenManagerImpl

public SwitchableTokenManagerImpl(TokenDAO daoMemory,
                                  TokenDAO daoHibernate,
                                  PropertyManager propertyManager)
Method Detail

findByRandomHash

public Token findByRandomHash(String randomHash)
                       throws org.springframework.dao.DataAccessException,
                              ObjectNotFoundException
Description copied from interface: SessionTokenStorage
Finds token by random hash.

Specified by:
findByRandomHash in interface SessionTokenStorage
Parameters:
randomHash - Random hash.
Returns:
Token.
Throws:
ObjectNotFoundException - if the token identified by the random hash cannot be found.
org.springframework.dao.DataAccessException

findByIdentifierHash

public Token findByIdentifierHash(String identifierHash)
                           throws ObjectNotFoundException
Description copied from interface: SessionTokenStorage
Finds token by identifier hash.

Specified by:
findByIdentifierHash in interface SessionTokenStorage
Parameters:
identifierHash - Identifier hash.
Returns:
Token.
Throws:
ObjectNotFoundException - if the token identified by the identifier hash cannot be found.

add

public Token add(Token token)
          throws org.springframework.dao.DataAccessException,
                 ObjectAlreadyExistsException
Description copied from interface: SessionTokenStorage
Persists a new token.

Specified by:
add in interface SessionTokenStorage
Parameters:
token - Token.
Returns:
The persisted token.
Throws:
ObjectAlreadyExistsException - if a token with the same identifier hash already exists.
org.springframework.dao.DataAccessException

update

public Token update(Token token)
             throws ObjectNotFoundException
Specified by:
update in interface SessionTokenStorage
Parameters:
token - token to update.
Returns:
updates the last accessed date on the token (sets it to now).
Throws:
ObjectNotFoundException

remove

public void remove(Token token)
            throws org.springframework.dao.DataAccessException
Description copied from interface: SessionTokenStorage
Removes a token.

Specified by:
remove in interface SessionTokenStorage
Parameters:
token - Token.
Throws:
org.springframework.dao.DataAccessException

search

public List<Token> search(EntityQuery<? extends Token> query)
Description copied from interface: SearchableTokenStorage
Searches for token based on criteria.

Specified by:
search in interface SearchableTokenStorage
Parameters:
query - Query.
Returns:
List of tokens which qualify for the criteria.

remove

public void remove(long directoryID,
                   String name)
            throws org.springframework.dao.DataAccessException
Description copied from interface: SessionTokenStorage
Remove token.

Specified by:
remove in interface SessionTokenStorage
Parameters:
directoryID - Directory id.
name - User or application name.
Throws:
org.springframework.dao.DataAccessException

removeExcept

public void removeExcept(long directoryId,
                         String name,
                         String exclusionToken)
Description copied from interface: SessionTokenStorage
Remove all tokens for the user except for the token specified by exclusionToken.

Specified by:
removeExcept in interface SessionTokenStorage
Parameters:
directoryId - Directory id.
name - User or application name.
exclusionToken - the random hash of the token to retain, if present

removeAll

public void removeAll(long directoryId)
Description copied from interface: SessionTokenStorage
Remove all tokens associated with the given directory id.

Specified by:
removeAll in interface SessionTokenStorage
Parameters:
directoryId - Directory id.

removeExpiredTokens

public void removeExpiredTokens(Date currentTime,
                                long maxLifeSeconds)
Description copied from interface: SessionTokenStorage
Remove all tokens that have expired. For a store that performs expiry asynchronously this may be a no-op.

Specified by:
removeExpiredTokens in interface SessionTokenStorage
Parameters:
currentTime - Current date
maxLifeSeconds - Max lifespan for tokens, unless they specific a shorter one.

removeAll

public void removeAll()
Removes all tokens from all implementations.

Specified by:
removeAll in interface SessionTokenStorage

isUsingDatabaseStorage

public boolean isUsingDatabaseStorage()
Returns true if the memory token manager is in use. False if the Hibernate manager is being used.

Specified by:
isUsingDatabaseStorage in interface SwitchableTokenManager
Returns:

setUsingDatabaseStorage

public void setUsingDatabaseStorage(boolean useDatabaseStorage)
                             throws PropertyManagerException
Performs the switch, if necessary.

Specified by:
setUsingDatabaseStorage in interface SwitchableTokenManager
Parameters:
useDatabaseStorage -
Throws:
PropertyManagerException

switchToMemory

public void switchToMemory()
If the Hibernate DAO is in use, transparently switches to In-memory DAO. Does nothing if the In-memory DAO is already in use. Acquires write lock for safety.


switchToHibernate

public void switchToHibernate()
If the In-memory DAO is in use, transparently switches to Hibernate DAO. Does nothing if the hibernate DAO is already in use. Acquires write lock for safety.


move

protected void move(TokenDAO to,
                    TokenDAO from)
Copies tokens from hibernate to in-memory DAO or vice versa, and upon success deletes the tokens from the source. Acquires write lock, so make sure the lock you use is reentrant!


updateTokenStorage

public void updateTokenStorage()
Description copied from interface: SwitchableTokenManager
Updates the switchable token manager to match the current configuration. This method must be called when the configuration has been changed externally (i.e., not through SwitchableTokenManager.setUsingDatabaseStorage(boolean)), for instance, after a backup restore.

Specified by:
updateTokenStorage in interface SwitchableTokenManager


Copyright © 2013 Atlassian. All Rights Reserved.