public class TokenService extends Object
| Constructor and Description |
|---|
TokenService(CsrfGuard csrfGuard) |
| Modifier and Type | Method and Description |
|---|---|
void |
createMasterTokenIfAbsent(String logicalSessionKey)
Creates master token if it does not exist already.
|
void |
generateProtectedPageTokens(String logicalSessionKey)
Generates new random tokens for configured protected pages.
|
String |
generateTokensIfAbsent(String logicalSessionKey,
String httpMethod,
String requestURI)
Generates master token and page token for the current resource if the token-per-page configuration is enabled
|
String |
getMasterToken(String logicalSessionKey)
Returns the master token assigned to the unique identifier extracted from the current request.
|
Map<String,String> |
getPageTokens(String logicalSessionKey)
Return the page tokens if the functionality is enabled and the client has already accessed a protected resource,
or if the token pre-creation is enabled.
|
String |
getTokenValue(String logicalSessionKey,
String resourceUri)
Returns the master or the page token for the associated resource depending on whether the token-per-page
configuration is enabled or not.
|
void |
invalidate(LogicalSession logicalSession)
Invalidates the logical session and removes all tokens from the storage
|
void |
rotateAllTokens(String logicalSessionKey)
Rotates (re-generates) the master token and all page tokens if the token-per-page functionality is enabled.
|
TokenTO |
rotateUsedToken(String logicalSessionKey,
String requestURI,
TokenBO usedValidToken)
Rotates the used master or the currently requested page token if the token-per-page functionality is enabled.
|
TokenBO |
verifyToken(javax.servlet.http.HttpServletRequest request,
String resourceIdentifier,
String logicalSessionKey,
String masterToken)
Verifies the validity of the current request.
|
public TokenService(CsrfGuard csrfGuard)
public void invalidate(LogicalSession logicalSession)
logicalSession - a not null logical session implementationpublic String getMasterToken(String logicalSessionKey)
logicalSessionKey - identifies the current logical session uniquelypublic Map<String,String> getPageTokens(String logicalSessionKey)
Note: this method returns a copy of the page tokens in order to prevent outside modification.
logicalSessionKey - identifies the current logical session uniquelypublic String generateTokensIfAbsent(String logicalSessionKey, String httpMethod, String requestURI)
logicalSessionKey - identifies the current logical session uniquelyhttpMethod - the current HTTP method used to request the resourcerequestURI - the URI of the desired HTTP resourcepublic void createMasterTokenIfAbsent(String logicalSessionKey)
logicalSessionKey - identifies the current logical session uniquelypublic void generateProtectedPageTokens(String logicalSessionKey)
logicalSessionKey - identifies the current logical session uniquelypublic TokenTO rotateUsedToken(String logicalSessionKey, String requestURI, TokenBO usedValidToken)
logicalSessionKey - identifies the current logical session uniquelyrequestURI - the URI of the desired HTTP resourceusedValidToken - a verified token that has validated the current requestpublic void rotateAllTokens(String logicalSessionKey)
logicalSessionKey - identifies the current logical session uniquelypublic String getTokenValue(String logicalSessionKey, String resourceUri)
If the token does not currently exists, it creates a new one.
logicalSessionKey - identifies the current logical session uniquelyresourceUri - the URI of the desired HTTP resourcepublic TokenBO verifyToken(javax.servlet.http.HttpServletRequest request, String resourceIdentifier, String logicalSessionKey, String masterToken) throws CsrfGuardException
request - current HTTP Servlet RequestresourceIdentifier - the requested resource identifierlogicalSessionKey - identifies the current logical session uniquelymasterToken - the master tokenCsrfGuardException - if the request does not have a valid token associatedCopyright © 2025 OWASP. All rights reserved.