com.atlassian.crowd.manager.token
Class TokenManagerImpl

java.lang.Object
  extended by com.atlassian.crowd.manager.token.TokenManagerImpl
All Implemented Interfaces:
TokenManager

public class TokenManagerImpl
extends Object
implements TokenManager

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


Constructor Summary
TokenManagerImpl(boolean initialUseIsMemory, TokenDAO daoMemory, TokenDAO daoHibernate, PropertyManager propertyManager, com.atlassian.event.api.EventPublisher eventPublisher)
           
TokenManagerImpl(TokenDAO daoMemory, TokenDAO daoHibernate, PropertyManager propertyManager, com.atlassian.event.api.EventPublisher eventPublisher)
           
 
Method Summary
 Token add(Token token)
           
 Token findByID(long ID)
           
 Token findByIdentifierHash(String identifierHash)
           
 Token findByRandomHash(String randomHash)
           
 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 onApplicationStartedEvent(com.atlassian.config.lifecycle.events.ApplicationStartedEvent event)
          On the application stated event, change to the correct token storage that has been stored in the database
 void onXMLRestoreFinishedEvent(XMLRestoreFinishedEvent event)
           
 void remove(long directoryID, String name)
           
 void remove(Token token)
           
 void removeAccessedBefore(Date expiryTime)
           
 void removeAll()
          Removes all tokens from all implementations.
 void removeAll(long directoryId)
           
 List<Token> search(EntityQuery<? extends Token> query)
           
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TokenManagerImpl

public TokenManagerImpl(boolean initialUseIsMemory,
                        TokenDAO daoMemory,
                        TokenDAO daoHibernate,
                        PropertyManager propertyManager,
                        com.atlassian.event.api.EventPublisher eventPublisher)

TokenManagerImpl

public TokenManagerImpl(TokenDAO daoMemory,
                        TokenDAO daoHibernate,
                        PropertyManager propertyManager,
                        com.atlassian.event.api.EventPublisher eventPublisher)
Method Detail

findByRandomHash

public Token findByRandomHash(String randomHash)
                       throws org.springframework.dao.DataAccessException,
                              ObjectNotFoundException
Specified by:
findByRandomHash in interface TokenManager
Throws:
org.springframework.dao.DataAccessException
ObjectNotFoundException

findByIdentifierHash

public Token findByIdentifierHash(String identifierHash)
                           throws ObjectNotFoundException
Specified by:
findByIdentifierHash in interface TokenManager
Throws:
ObjectNotFoundException

add

public Token add(Token token)
          throws org.springframework.dao.DataAccessException
Specified by:
add in interface TokenManager
Throws:
org.springframework.dao.DataAccessException

update

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

remove

public void remove(Token token)
            throws org.springframework.dao.DataAccessException
Specified by:
remove in interface TokenManager
Throws:
org.springframework.dao.DataAccessException

search

public List<Token> search(EntityQuery<? extends Token> query)
Specified by:
search in interface TokenManager

findByID

public Token findByID(long ID)
               throws org.springframework.dao.DataAccessException,
                      ObjectNotFoundException
Specified by:
findByID in interface TokenManager
Throws:
org.springframework.dao.DataAccessException
ObjectNotFoundException

remove

public void remove(long directoryID,
                   String name)
            throws org.springframework.dao.DataAccessException
Specified by:
remove in interface TokenManager
Throws:
org.springframework.dao.DataAccessException

removeAll

public void removeAll(long directoryId)
Specified by:
removeAll in interface TokenManager

removeAccessedBefore

public void removeAccessedBefore(Date expiryTime)
Specified by:
removeAccessedBefore in interface TokenManager

removeAll

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

Specified by:
removeAll in interface TokenManager

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 TokenManager
Returns:

setUsingDatabaseStorage

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

Specified by:
setUsingDatabaseStorage in interface TokenManager
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!


onApplicationStartedEvent

@EventListener
public void onApplicationStartedEvent(com.atlassian.config.lifecycle.events.ApplicationStartedEvent event)
On the application stated event, change to the correct token storage that has been stored in the database

Parameters:
event - the application started event

onXMLRestoreFinishedEvent

@EventListener
public void onXMLRestoreFinishedEvent(XMLRestoreFinishedEvent event)


Copyright © 2012 Atlassian. All Rights Reserved.