Package com.google.refine.commands
Class CSRFTokenFactory
java.lang.Object
com.google.refine.commands.CSRFTokenFactory
Generates CSRF tokens and checks their validity.
- Author:
- Antonin Delpeuch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final SecureRandomRandom number generator used to create tokensprotected final longTime to live for tokens, in secondsMaps each token to the time it was generatedprotected final intLength of the tokens to generate -
Constructor Summary
ConstructorsConstructorDescriptionCSRFTokenFactory(long timeToLive, int tokenLength) Constructs a new CSRF token factory. -
Method Summary
Modifier and TypeMethodDescriptionGenerates a fresh CSRF token, which will remain valid for the configured amount of time.booleanvalidToken(String token) Checks that a given CSRF token is valid.
-
Field Details
-
tokenCache
Maps each token to the time it was generated -
timeToLive
protected final long timeToLiveTime to live for tokens, in seconds -
tokenLength
protected final int tokenLengthLength of the tokens to generate -
rng
Random number generator used to create tokens
-
-
Constructor Details
-
CSRFTokenFactory
public CSRFTokenFactory(long timeToLive, int tokenLength) Constructs a new CSRF token factory.- Parameters:
timeToLive- Time to live for tokens, in secondstokenLength- Length of the tokens generated
-
-
Method Details
-
getFreshToken
Generates a fresh CSRF token, which will remain valid for the configured amount of time. -
validToken
Checks that a given CSRF token is valid.- Parameters:
token- the token to verify- Returns:
- true if the token is valid
-