Package com.atlassian.jira.security.xsrf
Class SimpleXsrfTokenGenerator
java.lang.Object
com.atlassian.jira.security.xsrf.SimpleXsrfTokenGenerator
- All Implemented Interfaces:
XsrfTokenGenerator
Implementation of XsrfTokenGenerator that stores a unique token depending
on strategy resolved
- requests originated by jira (webwork) run with
XsrfTokenStrategy.Type.SESSION
strategy
- external requests (like REST calls) run with XsrfTokenStrategy.Type.COOKIE
strategy- Since:
- v4.0
-
Field Summary
Fields inherited from interface com.atlassian.jira.security.xsrf.XsrfTokenGenerator
TOKEN_HTTP_SESSION_KEY, TOKEN_WEB_PARAMETER_KEY
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleXsrfTokenGenerator
(JiraAuthenticationContext authenticationContext, JiraServerIdProvider jiraServerIdProvider, FeatureManager featureManager) -
Method Summary
Modifier and TypeMethodDescriptionboolean
This returns true of the token was generated by an authenticated userGets the token from the current request, generating a new one if none is foundgenerateToken
(boolean create) Gets the token from the current request, optionally generating a new one if none is foundgenerateToken
(javax.servlet.http.HttpServletRequest httpServletRequest) Gets the token from the current request, generating a new one if none is foundgenerateToken
(javax.servlet.http.HttpServletRequest httpServletRequest, boolean create) Gets the token from the current request, optionally generating a new one if none is foundgetToken
(javax.servlet.http.HttpServletRequest request) Gets the token from the current request, generating a new one if none is foundConvenience method which will return the name to be used for a supplied XsrfToken in a request.boolean
validateToken
(javax.servlet.http.HttpServletRequest request, String token) Validate a form token received as part of a web request
-
Constructor Details
-
SimpleXsrfTokenGenerator
public SimpleXsrfTokenGenerator(JiraAuthenticationContext authenticationContext, JiraServerIdProvider jiraServerIdProvider, FeatureManager featureManager)
-
-
Method Details
-
generateToken
Description copied from interface:XsrfTokenGenerator
Gets the token from the current request, generating a new one if none is found- Specified by:
generateToken
in interfaceXsrfTokenGenerator
- Parameters:
httpServletRequest
- the request the token is being generated for- Returns:
- a valid XSRF form token
-
generateToken
public String generateToken(javax.servlet.http.HttpServletRequest httpServletRequest, boolean create) Description copied from interface:XsrfTokenGenerator
Gets the token from the current request, optionally generating a new one if none is found- Specified by:
generateToken
in interfaceXsrfTokenGenerator
- Parameters:
httpServletRequest
- the request the token is being generated forcreate
- true to create token if none is found- Returns:
- a valid XSRF form token
-
generateToken
Description copied from interface:XsrfTokenGenerator
Gets the token from the current request, generating a new one if none is found- Specified by:
generateToken
in interfaceXsrfTokenGenerator
- Returns:
- a valid XSRF form token
-
generateToken
Description copied from interface:XsrfTokenGenerator
Gets the token from the current request, optionally generating a new one if none is found- Specified by:
generateToken
in interfaceXsrfTokenGenerator
- Parameters:
create
- true to create token if none is found- Returns:
- a valid XSRF form token
-
getXsrfTokenName
Description copied from interface:XsrfTokenGenerator
Convenience method which will return the name to be used for a supplied XsrfToken in a request.- Specified by:
getXsrfTokenName
in interfaceXsrfTokenGenerator
- Returns:
- the name in the request for the Xsrf token.
-
validateToken
Description copied from interface:XsrfTokenGenerator
Validate a form token received as part of a web request- Specified by:
validateToken
in interfaceXsrfTokenGenerator
- Parameters:
request
- the request the token was received intoken
- the token- Returns:
- true iff the token is valid
-
generatedByAuthenticatedUser
Description copied from interface:XsrfTokenGenerator
This returns true of the token was generated by an authenticated user- Specified by:
generatedByAuthenticatedUser
in interfaceXsrfTokenGenerator
- Parameters:
token
- the XSRF token in question- Returns:
- true if the token was generated by an authenticated user.
-
getToken
Description copied from interface:XsrfTokenGenerator
Gets the token from the current request, generating a new one if none is found- Specified by:
getToken
in interfaceXsrfTokenGenerator
- Parameters:
request
- request that contains the form token.- Returns:
- the token stored in the cookie of this request.
-