public class SignedToken
extends java.lang.Object
SignedTokenEmailTokenVerifier
uses this class to verify tokens appearing in the custom
xsrfKey
JSON request property. The tokens protect against cross-site request forgery by depending
upon the browser's security model. The classic browser security model prohibits a script from
site A from reading any data received from site B. By sending unforgeable tokens from the server
and asking the client to return them to us, the client script must have had read access to the
token at some point and is therefore also from our server.
Constructor and Description |
---|
SignedToken(int age,
java.lang.String keyBase64)
Create a new utility, using the specific key.
|
Modifier and Type | Method and Description |
---|---|
com.google.gerrit.server.mail.ValidToken |
checkToken(java.lang.String tokenString,
java.lang.String text)
Validate a returned token.
|
static java.lang.String |
generateRandomKey()
Generate a random key for use with the XSRF library.
|
public SignedToken(int age, java.lang.String keyBase64) throws XsrfException
age
- the number of seconds a token may remain valid.keyBase64
- base 64 encoded representation of the key.XsrfException
- the JVM doesn't support the necessary algorithms.public static java.lang.String generateRandomKey()
public com.google.gerrit.server.mail.ValidToken checkToken(java.lang.String tokenString, java.lang.String text) throws XsrfException, CheckTokenException
ValidToken
, else will
throw XsrfException
when it's an unexpected token overflow or CheckTokenException
when it's an illegal token string format.tokenString
- a token string previously created by this class.text
- text that must have been used during newToken(String)
in order for the
token to be valid. If null the text will be taken from the token string itself.XsrfException
- the JVM doesn't support the necessary algorithms to generate a token.
XSRF services are simply not available.CheckTokenException
- throws when token is null, the empty string, has expired, does not
match the text supplied, or is a forged token.