Class InMemoryToken
- java.lang.Object
-
- org.owasp.csrfguard.token.storage.impl.InMemoryToken
-
-
Constructor Summary
Constructors Constructor Description InMemoryToken(String masterToken)InMemoryToken(String masterToken, org.apache.commons.lang3.tuple.Pair<String,String> pageToken)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetMasterToken()Returns the master tokenStringgetPageToken(String uri)Map<String,String>getPageTokens()PageTokenValuegetTimedPageToken(String uri)voidregenerateUsedPageToken(String tokenFromRequest, Supplier<String> tokenValueSupplier)TODO is it worth the added performance penalty in case of a large application with a lot of pages? What would be the risk if this would be contextual to the assigned resource? Disposes the current token from all the stored valid page tokens, disregarding to which resource it was assigned and replaces with a newly generated one.voidrotateAllPageTokens(Supplier<String> tokenValueSupplier)Rotates all the existing page token valuesvoidsetMasterToken(String masterToken)Sets the new master tokenvoidsetPageToken(String uri, String pageToken)StringsetPageTokenIfAbsent(String uri, Supplier<String> valueSupplier)voidsetPageTokens(Map<String,String> pageTokens)Initialize or overwrite the entire page-token map
-
-
-
Method Detail
-
getMasterToken
public String getMasterToken()
Description copied from interface:TokenReturns the master token- Specified by:
getMasterTokenin interfaceToken- Returns:
- the current master token
-
setMasterToken
public void setMasterToken(String masterToken)
Description copied from interface:TokenSets the new master token- Specified by:
setMasterTokenin interfaceToken- Parameters:
masterToken- the new master token
-
getPageToken
public String getPageToken(String uri)
- Specified by:
getPageTokenin interfaceToken- Parameters:
uri- the URI to which the page token should be returned- Returns:
- the page token for the requested uri
-
getTimedPageToken
public PageTokenValue getTimedPageToken(String uri)
- Specified by:
getTimedPageTokenin interfaceToken- Parameters:
uri- the URI to which the timed page token should be returned- Returns:
- a timed page token containing a page token and its creation date
-
setPageToken
public void setPageToken(String uri, String pageToken)
- Specified by:
setPageTokenin interfaceToken- Parameters:
uri- the URI to which the page token should be associatedpageToken- the new page token
-
setPageTokenIfAbsent
public String setPageTokenIfAbsent(String uri, Supplier<String> valueSupplier)
- Specified by:
setPageTokenIfAbsentin interfaceToken- Parameters:
uri- the URI to which the page token should be associatedvalueSupplier- a supplier that generates new, unique tokens at each invocation- Returns:
- the newly generated token
-
getPageTokens
public Map<String,String> getPageTokens()
- Specified by:
getPageTokensin interfaceToken- Returns:
- a map of URIs and their associated page tokens
-
setPageTokens
public void setPageTokens(Map<String,String> pageTokens)
Description copied from interface:TokenInitialize or overwrite the entire page-token map- Specified by:
setPageTokensin interfaceToken- Parameters:
pageTokens- a map of URIs and their associated page tokens
-
rotateAllPageTokens
public void rotateAllPageTokens(Supplier<String> tokenValueSupplier)
Description copied from interface:TokenRotates all the existing page token values- Specified by:
rotateAllPageTokensin interfaceToken- Parameters:
tokenValueSupplier- a supplier that generates new, unique tokens at each invocation
-
regenerateUsedPageToken
public void regenerateUsedPageToken(String tokenFromRequest, Supplier<String> tokenValueSupplier)
Description copied from interface:TokenTODO is it worth the added performance penalty in case of a large application with a lot of pages? What would be the risk if this would be contextual to the assigned resource? Disposes the current token from all the stored valid page tokens, disregarding to which resource it was assigned and replaces with a newly generated one.- Specified by:
regenerateUsedPageTokenin interfaceToken- Parameters:
tokenFromRequest- the current token which needs to be rotatedtokenValueSupplier- a supplier that generates new, unique tokens at each invocation
-
-