public class HttpSessionTransactionTokenStore extends Object implements TransactionTokenStore
TransactionTokenStore
interface which uses HTTP session to store the token Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_RETRY_CREATE_TOKEN_NAME
default retry count to generate token
|
static int |
NO_OF_TOKENS_PER_TOKEN_NAME
default token size per token name
|
static String |
TOKEN_HOLDER_SESSION_ATTRIBUTE_PREFIX
attribute name of token holder in the session scope
|
Constructor and Description |
---|
HttpSessionTransactionTokenStore()
Default constructor
|
HttpSessionTransactionTokenStore(int transactionTokenSizePerTokenName)
Constructor.
|
HttpSessionTransactionTokenStore(int transactionTokenSizePerTokenName,
int retryCreateTokenName)
Constructor.
|
HttpSessionTransactionTokenStore(TokenStringGenerator generator,
int transactionTokenSizePerTokenName,
int retryCreateTokenName)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
String |
createAndReserveTokenKey(String tokenName)
Creates a new Token key and reserve it in the HttpSession
removes oldeset token if token size is greater than or equals transactionTokensPerTokenName in the same
namespace. |
String |
getAndClear(TransactionToken token)
Fetches the value stored in session corresponding to the
TransactionToken received as argument to this method. |
void |
remove(TransactionToken token)
Removes the session attribute corresponding to the transactionToken instance passed as argument to this method
|
void |
store(TransactionToken token)
Stores the token represented by
TransactionToken into HTTP session |
public static final String TOKEN_HOLDER_SESSION_ATTRIBUTE_PREFIX
public static final int NO_OF_TOKENS_PER_TOKEN_NAME
public static final int DEFAULT_RETRY_CREATE_TOKEN_NAME
public HttpSessionTransactionTokenStore()
By default, number of tokenKeys per tokenName is set to 10. And number of retries to create a tokenName is set to 10.
public HttpSessionTransactionTokenStore(int transactionTokenSizePerTokenName)
transactionTokensPerTokenName indicates the number of transactionTokens that can be stored in the session for each
tokenName at a time.
transactionTokenSizePerTokenName
- Allowed number of tokens for each tokenName(must be greater than 0)IllegalArgumentException
- sizePerTokenName is (less than or equals 0)public HttpSessionTransactionTokenStore(int transactionTokenSizePerTokenName, int retryCreateTokenName)
transactionTokensPerTokenName indicates the number of transactionTokens that can be stored in the session for each
tokenName at a time.
retryCreateTokenName indicates the number of times retrys are done to create a token name
transactionTokenSizePerTokenName
- Allowed number of tokens for each tokenName(must be greater than 0)retryCreateTokenName
- Number of retries for creating tokenName(must be greater than 0)IllegalArgumentException
- sizePerTokenName is (less than or equals 0) or retryCreateTokenName is (less than or
equals 0)public HttpSessionTransactionTokenStore(TokenStringGenerator generator, int transactionTokenSizePerTokenName, int retryCreateTokenName)
generator
- TokenStringGenerator
instance (must not be null)transactionTokenSizePerTokenName
- Allowed number of tokens for each tokenName(must be greater than 0)retryCreateTokenName
- Number of retries for creating tokenName(must be greater than 0)IllegalArgumentException
- generator is null or sizePerTokenName is (less than or equals 0) or retryCreateTokenName
is (less than or equals 0)public String getAndClear(TransactionToken token)
TransactionToken
received as argument to this method.
This value corresponding to the same transactionToken instance can be fetched only once. Once the value is fetched, its
value is cleared from the session. For all further invocations to this method for the same transactionToken instance,
null
will be returned.
getAndClear
in interface TransactionTokenStore
token
- TransactionToken
instance (must not be null)IllegalArgumentException
- generator is nullTransactionTokenStore.getAndClear(org.terasoluna.gfw.web.token.transaction.TransactionToken)
public void remove(TransactionToken token)
remove
in interface TransactionTokenStore
token
- TransactionToken
instance (must not be null)TransactionTokenStore.remove(org.terasoluna.gfw.web.token.transaction.TransactionToken)
public String createAndReserveTokenKey(String tokenName)
transactionTokensPerTokenName
in the same
namespace.createAndReserveTokenKey
in interface TransactionTokenStore
tokenName
- token name (namespace)TransactionTokenStore.createAndReserveTokenKey(java.lang.String)
public void store(TransactionToken token)
TransactionToken
into HTTP session
The session attribute name to store it is prefixed with HttpSessionTransactionTokenStore_TOKEN_
.
store
in interface TransactionTokenStore
token
- TransactionToken
instance (must not be null)TransactionTokenStore.store(org.terasoluna.gfw.web.token.transaction.TransactionToken)
Copyright © 2013–2018 terasoluna.org. All rights reserved.