Package net.shibboleth.idp.ui.csrf
Class CSRFTokenManager
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.idp.ui.csrf.CSRFTokenManager
- All Implemented Interfaces:
Component,DestructableComponent,InitializableComponent
A thread-safe helper class for dealing with cross-site request forgery tokens.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA simple default CSRF token validation predicate. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe name of the HTTP parameter that contains the anti-csrf token.private BiPredicate<CSRFToken,String> Predicate to validate the CSRF token.private IdentifierGenerationStrategyThe strategy used to generate a CSRF token value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidGenerate aCSRFTokenusing the token generation strategy derived token value.booleanisValidCSRFToken(CSRFToken csrfToken, String requestCsrfToken) Check the CSRF token matches the CSRF token in the request using thecsrfTokenValidationPredicate.voidsetCsrfParameterName(String parameterName) Set the CSRF HTTP parameter name.voidsetCsrfTokenValidationPredicate(BiPredicate<CSRFToken, String> tokenValidationPredicate) Set the CSRF token validation predicate.voidsetTokenGenerationStrategy(IdentifierGenerationStrategy tokenStrategy) Set the CSRF token generation strategy.Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized
-
Field Details
-
csrfParameterName
The name of the HTTP parameter that contains the anti-csrf token. -
tokenGenerationStrategy
The strategy used to generate a CSRF token value. -
csrfTokenValidationPredicate
Predicate to validate the CSRF token.
-
-
Constructor Details
-
CSRFTokenManager
public CSRFTokenManager()Constructor.
-
-
Method Details
-
setCsrfTokenValidationPredicate
public void setCsrfTokenValidationPredicate(@Nonnull BiPredicate<CSRFToken, String> tokenValidationPredicate) Set the CSRF token validation predicate.- Parameters:
tokenValidationPredicate- the CSRF token validation predicate.
-
setCsrfParameterName
Set the CSRF HTTP parameter name.- Parameters:
parameterName- CSRF parameter name
-
doInitialize
- Overrides:
doInitializein classAbstractInitializableComponent- Throws:
ComponentInitializationException
-
generateCSRFToken
Generate aCSRFTokenusing the token generation strategy derived token value. Set the HTTP parameter name from thecsrfParameterNamefield.- Returns:
- a CSRF token
-
isValidCSRFToken
Check the CSRF token matches the CSRF token in the request using thecsrfTokenValidationPredicate.- Parameters:
csrfToken- the server side CSRF token.requestCsrfToken- the CSRF token from the request.- Returns:
- true iff the CSRF token value matches the request CSRF token. False if they do not match.