Class SessionCsrfTokenRepository
java.lang.Object
io.micronaut.security.csrf.session.SessionCsrfTokenRepository
- All Implemented Interfaces:
io.micronaut.core.order.Ordered, CsrfTokenRepository<io.micronaut.http.HttpRequest<?>>
@Requires(classes={io.micronaut.http.HttpRequest.class,io.micronaut.session.http.SessionForRequest.class}) @Requires(beans=CsrfConfiguration.class) @Requires(property="micronaut.security.csrf.repositories.session.enabled",value="true",defaultValue="true")
@Singleton
public class SessionCsrfTokenRepository
extends Object
implements CsrfTokenRepository<io.micronaut.http.HttpRequest<?>>
Implementation of
CsrfTokenRepository that retrieves the CSRF token from an HTTP session using the key defined in CsrfConfiguration.getHttpSessionName().
This repository takes precedence over CookieCsrfTokenRepository: when the request carries an HTTP session holding a CSRF token,
the session token is the one validated against the token supplied in the request.- Since:
- 4.11.0
- Author:
- Sergio del Amo
-
Field Summary
FieldsFields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindCsrfToken(@NonNull io.micronaut.http.HttpRequest<?> request) intgetOrder()
-
Field Details
-
ORDER
public static final int ORDERThe order of this repository. It runs beforeCookieCsrfTokenRepository.- Since:
- 5.5.2
- See Also:
-
-
Constructor Details
-
SessionCsrfTokenRepository
- Parameters:
csrfConfiguration- CSRF Configuration
-
-
Method Details
-
findCsrfToken
- Specified by:
findCsrfTokenin interfaceCsrfTokenRepository<io.micronaut.http.HttpRequest<?>>- Parameters:
request- Request- Returns:
- A CSRF token or an empty optional.
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceio.micronaut.core.order.Ordered
-