Package com.vaadin.hilla.auth
Class CsrfChecker
java.lang.Object
com.vaadin.hilla.auth.CsrfChecker
Handles checking of a CSRF token in endpoint requests.
-
Constructor Summary
ConstructorsConstructorDescriptionCsrfChecker(jakarta.servlet.ServletContext servletContext) Creates a new csrf checker for the given context. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if CSRF token checking in endpoints is enabled.voidsetCsrfProtection(boolean csrfProtectionEnabled) Enable or disable CSRF token checking in endpoints.booleanvalidateCsrfTokenInRequest(jakarta.servlet.http.HttpServletRequest request) Validates the CSRF token that is included in the request.
-
Constructor Details
-
CsrfChecker
public CsrfChecker(jakarta.servlet.ServletContext servletContext) Creates a new csrf checker for the given context.- Parameters:
servletContext- the servlet context
-
-
Method Details
-
validateCsrfTokenInRequest
public boolean validateCsrfTokenInRequest(jakarta.servlet.http.HttpServletRequest request) Validates the CSRF token that is included in the request.Checks that the CSRF token in the request matches the expected one that is stored in the HTTP cookie.
Note! If CSRF protection is disabled, this method will always return
true.- Parameters:
request- the request to validate- Returns:
trueif the CSRF token is ok or checking is disabled,falseotherwise
-
setCsrfProtection
public void setCsrfProtection(boolean csrfProtectionEnabled) Enable or disable CSRF token checking in endpoints.- Parameters:
csrfProtectionEnabled- enable or disable protection
-
isCsrfProtectionEnabled
public boolean isCsrfProtectionEnabled()Checks if CSRF token checking in endpoints is enabled.- Returns:
trueif protection is enabled,falseotherwise
-