Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.forum.database
Class DbEmailTokenManager

java.lang.Object
  extended by com.jivesoftware.base.event.UserListenerAdapter
      extended by com.jivesoftware.forum.database.DbEmailTokenManager
All Implemented Interfaces:
UserListener, JiveManager, EmailTokenManager

public class DbEmailTokenManager
extends UserListenerAdapter
implements EmailTokenManager

Implementation of EmailTokenManager which associates random numbers with user ids and stores them in the database. Generates tokens of the form [randomValue-userID-messageID]. Tokens have a time to live in the system of 7 days. After that, a reaper task will delete them from the cache and database, and any emails sent with those token values will be rejected.


Method Summary
 void destroy()
          Called during application shutdown.
static DbEmailTokenManager getInstance()
          Returns the singleton instance.
 java.lang.String getMessageToken(long userID, long messageID)
          Returns a token of the form [randomValue-userID-messageID].
 java.util.regex.Pattern getTokenPattern()
          Returns the Pattern which matches tokens created by this token manager.
 long[] getUserAndMessageID(java.lang.String messageToken)
          Returns the userID and messageID encoded in the token as a two element array.
 long getUserID(java.lang.String messageToken)
          Returns just the user id as found in the supplied token string.
 void initialize()
          Called during application startup.
 void userDeleted(UserEvent event)
          Called when a user is deleted.
 
Methods inherited from class com.jivesoftware.base.event.UserListenerAdapter
userCreated, userModified
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initialize

public void initialize()
Called during application startup. Initializes the cache and a task which cleans out old tokens.

Specified by:
initialize in interface JiveManager

destroy

public void destroy()
Called during application shutdown. No op.

Specified by:
destroy in interface JiveManager

getInstance

public static DbEmailTokenManager getInstance()
Returns the singleton instance.

Returns:
the singleton instance.

getMessageToken

public java.lang.String getMessageToken(long userID,
                                        long messageID)
                                 throws EmailMonitorException
Returns a token of the form [randomValue-userID-messageID]. These tokens can be subsequently passed to getUserAndMessageID(java.lang.String) to retrieve the userID and messageID. Tokens expire after 7 days. The random part of the token is generated once per day per user.

Specified by:
getMessageToken in interface EmailTokenManager
Parameters:
userID - the userID to associate with and encode into the token.
messageID - the message id to encode into the token.
Returns:
a token of the form [randomValue-userID-messageID].
Throws:
EmailMonitorException - if an underlying exception is thrown during token creation.

getUserAndMessageID

public long[] getUserAndMessageID(java.lang.String messageToken)
                           throws EmailMonitorException
Returns the userID and messageID encoded in the token as a two element array. If the random part of the token is not found to be associated with the userID, or if the token is malformed, an EmailMonitorException is thrown.

Specified by:
getUserAndMessageID in interface EmailTokenManager
Parameters:
messageToken - the token to read.
Returns:
the userID and messageID encoded in the token as a two element array.
Throws:
EmailMonitorException - if an underlying exception is thrown during token lookup and authentication, or if the token has expired.

getUserID

public long getUserID(java.lang.String messageToken)
Returns just the user id as found in the supplied token string.

Specified by:
getUserID in interface EmailTokenManager
Parameters:
messageToken - the token string to search for a user id.
Returns:
the user id as found in the supplied token string.

getTokenPattern

public java.util.regex.Pattern getTokenPattern()
Returns the Pattern which matches tokens created by this token manager.

Specified by:
getTokenPattern in interface EmailTokenManager
Returns:
the Pattern which matches tokens created by this token manager.

userDeleted

public void userDeleted(UserEvent event)
Called when a user is deleted. All tokens associated with the user are deleted from the cache and the database.

Specified by:
userDeleted in interface UserListener
Overrides:
userDeleted in class UserListenerAdapter
Parameters:
event - the UserEvent containing the affected user.

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.