public class CsrfShield
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
CsrfShield.Token
CSRF Token.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CSRF_TOKEN_NAME |
static java.lang.String |
CSRF_TOKEN_SET |
protected static int |
maxTokensPerSession |
protected static int |
timeToLive |
Constructor and Description |
---|
CsrfShield() |
Modifier and Type | Method and Description |
---|---|
protected static void |
assureSize(java.util.Set<CsrfShield.Token> tokenSet)
Removes expired tokens if token set is full.
|
static boolean |
checkCsrfToken(javax.servlet.http.HttpServletRequest request) |
static boolean |
checkCsrfToken(javax.servlet.http.HttpServletRequest request,
java.lang.String tokenName)
Checks if
CSRF token is valid. |
static boolean |
checkCsrfToken(javax.servlet.http.HttpSession session,
java.lang.String tokenValue)
Checks token value.
|
static java.lang.String |
prepareCsrfToken(javax.servlet.http.HttpSession session) |
static java.lang.String |
prepareCsrfToken(javax.servlet.http.HttpSession session,
int timeToLive)
Generates new CSRF token and puts it in the session.
|
static java.lang.String |
prepareCsrfToken(javax.servlet.jsp.PageContext pageContext) |
static void |
setMaxTokensPerSession(int maxTokensPerSession)
Sets max number of tokens that will be stored for single session.
|
static void |
setTimeToLive(int periodInSeconds)
Sets time to live for tokens in seconds.
|
public static final java.lang.String CSRF_TOKEN_NAME
public static final java.lang.String CSRF_TOKEN_SET
protected static int timeToLive
protected static int maxTokensPerSession
public static void setTimeToLive(int periodInSeconds)
public static void setMaxTokensPerSession(int maxTokensPerSession)
public static java.lang.String prepareCsrfToken(javax.servlet.jsp.PageContext pageContext)
public static java.lang.String prepareCsrfToken(javax.servlet.http.HttpSession session)
public static java.lang.String prepareCsrfToken(javax.servlet.http.HttpSession session, int timeToLive)
protected static void assureSize(java.util.Set<CsrfShield.Token> tokenSet)
setMaxTokensPerSession(int)
public static boolean checkCsrfToken(javax.servlet.http.HttpServletRequest request)
public static boolean checkCsrfToken(javax.servlet.http.HttpServletRequest request, java.lang.String tokenName)
CSRF token
is valid.
Returns false
if token was requested, but not found.
Otherwise, it returns true
.public static boolean checkCsrfToken(javax.servlet.http.HttpSession session, java.lang.String tokenValue)
Copyright © 2003-present Jodd Team