org.apache.struts.util

Class TokenProcessor

public class TokenProcessor extends Object

TokenProcessor is responsible for handling all token related functionality. The methods in this class are synchronized to protect token processing from multiple threads. Servlet containers are allowed to return a different HttpSession object for two threads accessing the same session so it is not possible to synchronize on the session.

Since: Struts 1.1

Field Summary
static TokenProcessorinstance
The singleton instance of this class.
longprevious
The timestamp used most recently to generate a token value.
Constructor Summary
protected TokenProcessor()
Protected constructor for TokenProcessor.
Method Summary
StringgenerateToken(HttpServletRequest request)
Generate a new transaction token, to be used for enforcing a single request for a particular transaction.
static TokenProcessorgetInstance()
Retrieves the singleton instance of this class.
booleanisTokenValid(HttpServletRequest request)
Return true if there is a transaction token stored in the user's current session, and the value submitted as a request parameter with this action matches it.
booleanisTokenValid(HttpServletRequest request, boolean reset)
Return true if there is a transaction token stored in the user's current session, and the value submitted as a request parameter with this action matches it.
voidresetToken(HttpServletRequest request)
Reset the saved transaction token in the user's session.
voidsaveToken(HttpServletRequest request)
Save a new transaction token in the user's current session, creating a new session if necessary.
StringtoHex(byte[] buffer)
Convert a byte array to a String of hexadecimal digits and return it.

Field Detail

instance

private static TokenProcessor instance
The singleton instance of this class.

private long previous
The timestamp used most recently to generate a token value.

Constructor Detail

TokenProcessor

protected TokenProcessor()
Protected constructor for TokenProcessor. Use TokenProcessor.getInstance() to obtain a reference to the processor.

Method Detail

generateToken

public String generateToken(HttpServletRequest request)
Generate a new transaction token, to be used for enforcing a single request for a particular transaction.

Parameters: request The request we are processing

getInstance

public static TokenProcessor getInstance()
Retrieves the singleton instance of this class.

isTokenValid

public boolean isTokenValid(HttpServletRequest request)
Return true if there is a transaction token stored in the user's current session, and the value submitted as a request parameter with this action matches it. Returns false under any of the following circumstances:

Parameters: request The servlet request we are processing

isTokenValid

public boolean isTokenValid(HttpServletRequest request, boolean reset)
Return true if there is a transaction token stored in the user's current session, and the value submitted as a request parameter with this action matches it. Returns false

Parameters: request The servlet request we are processing reset Should we reset the token after checking it?

resetToken

public void resetToken(HttpServletRequest request)
Reset the saved transaction token in the user's session. This indicates that transactional token checking will not be needed on the next request that is submitted.

Parameters: request The servlet request we are processing

saveToken

public void saveToken(HttpServletRequest request)
Save a new transaction token in the user's current session, creating a new session if necessary.

Parameters: request The servlet request we are processing

toHex

private String toHex(byte[] buffer)
Convert a byte array to a String of hexadecimal digits and return it.

Parameters: buffer The byte array to be converted

Copyright B) 2000-2008 - The Apache Software Foundation