Package io.vertx.mutiny.ext.web.handler
Class CSRFHandler
java.lang.Object
io.vertx.mutiny.ext.web.handler.CSRFHandler
- All Implemented Interfaces:
MutinyDelegate,io.vertx.core.Handler<RoutingContext>,InputTrustHandler,Consumer<RoutingContext>
public class CSRFHandler
extends Object
implements io.vertx.core.Handler<RoutingContext>, InputTrustHandler, Consumer<RoutingContext>, MutinyDelegate
This handler adds a CSRF token to requests which mutate state. In order change the state a (XSRF-TOKEN) cookie is set
with a unique token, that is expected to be sent back in a (X-XSRF-TOKEN) header.
The behavior is to check the request body header and cookie for validity.
This Handler requires session support, thus should be added somewhere below Session and Body handlers.
NOTE: This class has been automatically generated from the original non Mutiny-ified interface.
- Author:
- Paulo Lopes
- See Also:
-
CSRFHandler
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.vertx.mutiny.ext.web.handler.InputTrustHandler
InputTrustHandler.InputTrustHandlerImpl -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TypeArg<CSRFHandler>static final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionCSRFHandler(io.vertx.ext.web.handler.CSRFHandler delegate) Create a new instance ofCSRFHandlerdelegating to the given (non-null) instance ofCSRFHandler.CSRFHandler(Object delegate) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(RoutingContext item) Handle an item.static CSRFHandlerInstantiate a new CSRFHandlerImpl with a secretbooleanio.vertx.ext.web.handler.CSRFHandlerGet the delegate instance.voidhandle(RoutingContext item) Handle an item.inthashCode()static CSRFHandlernewInstance(io.vertx.ext.web.handler.CSRFHandler delegate) Creates a new instance of theCSRFHandler.setCookieHttpOnly(boolean httpOnly) Set the cookiehttpOnlyattribute.setCookieName(String name) Set the cookie name.setCookiePath(String path) Set the cookie path.setCookieSecure(boolean secure) Sets the cookiesecureflag.setHeaderName(String name) Set the header name.setNagHttps(boolean nag) Should the handler give warning messages if this handler is used in other than https protocols?Set the origin for this server.setTimeout(long timeout) Set the timeout for tokens generated by the handler, by default it uses the default from the session handler.toString()
-
Field Details
-
DEFAULT_COOKIE_NAME
- See Also:
-
DEFAULT_COOKIE_PATH
- See Also:
-
DEFAULT_HEADER_NAME
- See Also:
-
__TYPE_ARG
-
-
Constructor Details
-
CSRFHandler
public CSRFHandler(io.vertx.ext.web.handler.CSRFHandler delegate) Create a new instance ofCSRFHandlerdelegating to the given (non-null) instance ofCSRFHandler. -
CSRFHandler
-
-
Method Details
-
accept
Handle an item. This method is generated from theoriginalmethod."- Specified by:
acceptin interfaceConsumer<RoutingContext>- Specified by:
acceptin interfaceInputTrustHandler
-
handle
Handle an item. This method is generated from theoriginalmethod."- Specified by:
handlein interfaceio.vertx.core.Handler<RoutingContext>- Specified by:
handlein interfaceInputTrustHandler
-
getDelegate
public io.vertx.ext.web.handler.CSRFHandler getDelegate()Get the delegate instance.This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.
- Specified by:
getDelegatein interfaceInputTrustHandler- Specified by:
getDelegatein interfaceMutinyDelegate- Returns:
- the delegate instance
-
create
Instantiate a new CSRFHandlerImpl with a secretCSRFHandler.create("s3cr37")- Parameters:
secret- server secret to sign the token.
-
setOrigin
Set the origin for this server. When this value is set, extra validation will occur. The request must match the origin server, port and protocol.- Parameters:
origin- the origin for this server e.g.:https://www.foo.com.- Returns:
- fluent
-
setCookieName
Set the cookie name. By default XSRF-TOKEN is used as it is the expected name by AngularJS however other frameworks might use other names.- Parameters:
name- a new name for the cookie.- Returns:
- fluent
-
setCookiePath
Set the cookie path. By default / is used.- Parameters:
path- a new path for the cookie.- Returns:
- fluent
-
setCookieHttpOnly
Set the cookiehttpOnlyattribute. When setting tofalsethe CSRF handler will behave in Double Submit Cookie mode. When set totruethen it will operate in Cookie-to-header mode. For more information https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#double-submit-cookie- Parameters:
httpOnly- a new name for the header.- Returns:
- fluent
-
setCookieSecure
Sets the cookiesecureflag. When set this flag instructs browsers to only send the cookie over HTTPS.- Parameters:
secure- true to set the secure flag on the cookie- Returns:
- a reference to this, so the API can be used fluently
-
setHeaderName
Set the header name. By default X-XSRF-TOKEN is used as it is the expected name by AngularJS however other frameworks might use other names.- Parameters:
name- a new name for the header.- Returns:
- fluent
-
setNagHttps
Should the handler give warning messages if this handler is used in other than https protocols?- Parameters:
nag- true to nag- Returns:
- fluent
-
setTimeout
Set the timeout for tokens generated by the handler, by default it uses the default from the session handler.- Parameters:
timeout- token timeout- Returns:
- fluent
-
newInstance
Creates a new instance of theCSRFHandler. -
hashCode
public int hashCode() -
equals
-
toString
-