Class SwitchableTokenManagerImpl
java.lang.Object
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
ConstructorsConstructorDescriptionSwitchableTokenManagerImpl(boolean initialUseIsMemory, TokenDAO daoMemory, TokenDAO daoHibernate, PropertyManager propertyManager, ClusterService clusterService) SwitchableTokenManagerImpl(TokenDAO daoMemory, TokenDAO daoHibernate, PropertyManager propertyManager, ClusterService clusterService) -
Method Summary
Modifier and TypeMethodDescriptionPersists a new token.findByIdentifierHash(String identifierHash) Finds token by identifier hash.findByRandomHash(String randomHash) Finds token by random hash.booleanReturns true if the memory token manager is in use.voidRemove token.voidRemoves a token.voidRemoves all tokens from all implementations.voidremoveAll(long directoryId) Remove all tokens associated with the given directory id.voidremoveExcept(long directoryId, String name, String exclusionToken) Remove all tokens for the user except for the token specified byexclusionToken.voidremoveExpiredTokens(Date currentTime, long maxLifeSeconds) Remove all tokens that have expired.search(EntityQuery<? extends AuthenticationToken> query) Searches for token based on criteria.voidsetUsingDatabaseStorage(boolean useDatabaseStorage) Performs the switch, if necessary.voidIf the In-memory DAO is in use, transparently switches to Hibernate DAO.voidIf the Hibernate DAO is in use, transparently switches to In-memory DAO.voidUpdates the switchable token manager to match the current configuration.
-
Constructor Details
-
SwitchableTokenManagerImpl
public SwitchableTokenManagerImpl(boolean initialUseIsMemory, TokenDAO daoMemory, TokenDAO daoHibernate, PropertyManager propertyManager, ClusterService clusterService) -
SwitchableTokenManagerImpl
public SwitchableTokenManagerImpl(TokenDAO daoMemory, TokenDAO daoHibernate, PropertyManager propertyManager, ClusterService clusterService)
-
-
Method Details
-
findByRandomHash
public Token findByRandomHash(String randomHash) throws org.springframework.dao.DataAccessException, ObjectNotFoundException Description copied from interface:SessionTokenStorageFinds token by random hash.- Specified by:
findByRandomHashin interfaceSessionTokenStorage- Parameters:
randomHash- Random hash.- Returns:
- Token.
- Throws:
ObjectNotFoundException- if the token identified by the random hash cannot be found.org.springframework.dao.DataAccessException
-
findByIdentifierHash
Description copied from interface:SessionTokenStorageFinds token by identifier hash.- Specified by:
findByIdentifierHashin interfaceSessionTokenStorage- 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:SessionTokenStoragePersists a new token.- Specified by:
addin interfaceSessionTokenStorage- Parameters:
token- Token.- Returns:
- The persisted token.
- Throws:
ObjectAlreadyExistsException- if a token with the same identifier hash already exists.org.springframework.dao.DataAccessException
-
update
- Specified by:
updatein interfaceSessionTokenStorage- Parameters:
token- token to update.- Returns:
- updates the last accessed date on the token (sets it to now).
- Throws:
ObjectNotFoundException
-
remove
Description copied from interface:SessionTokenStorageRemoves a token.- Specified by:
removein interfaceSessionTokenStorage- Parameters:
token- Token.- Throws:
org.springframework.dao.DataAccessException
-
search
Description copied from interface:SearchableTokenStorageSearches for token based on criteria.- Specified by:
searchin interfaceSearchableTokenStorage- 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:SessionTokenStorageRemove token.- Specified by:
removein interfaceSessionTokenStorage- Parameters:
directoryID- Directory id.name- User or application name.- Throws:
org.springframework.dao.DataAccessException
-
removeExcept
Description copied from interface:SessionTokenStorageRemove all tokens for the user except for the token specified byexclusionToken.- Specified by:
removeExceptin interfaceSessionTokenStorage- 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:SessionTokenStorageRemove all tokens associated with the given directory id.- Specified by:
removeAllin interfaceSessionTokenStorage- Parameters:
directoryId- Directory id.
-
removeExpiredTokens
Description copied from interface:SessionTokenStorageRemove all tokens that have expired. For a store that performs expiry asynchronously this may be a no-op.- Specified by:
removeExpiredTokensin interfaceSessionTokenStorage- Parameters:
currentTime- Current datemaxLifeSeconds- Max lifespan for tokens, unless they specific a shorter one.
-
removeAll
public void removeAll()Removes all tokens from all implementations.- Specified by:
removeAllin interfaceSessionTokenStorage
-
isUsingDatabaseStorage
public boolean isUsingDatabaseStorage()Returns true if the memory token manager is in use. False if the Hibernate manager is being used.- Specified by:
isUsingDatabaseStoragein interfaceSwitchableTokenManager
-
setUsingDatabaseStorage
Performs the switch, if necessary.- Specified by:
setUsingDatabaseStoragein interfaceSwitchableTokenManager- 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. -
updateTokenStorage
public void updateTokenStorage()Description copied from interface:SwitchableTokenManagerUpdates the switchable token manager to match the current configuration. This method must be called when the configuration has been changed externally (i.e., not throughSwitchableTokenManager.setUsingDatabaseStorage(boolean)), for instance, after a backup restore.- Specified by:
updateTokenStoragein interfaceSwitchableTokenManager
-