Class SessionHandler
- All Implemented Interfaces:
MutinyDelegate,io.vertx.core.Handler<RoutingContext>,PlatformHandler,Consumer<RoutingContext>
Session for each browser
session.
It looks up the session for each request based on a session cookie which contains a session ID. It stores the session when the response is ended in the session store.
The session is available on the routing context with
RoutingContext.session().
NOTE: This class has been automatically generated from the original non Mutiny-ified interface.
- Author:
- Tim Fox
- See Also:
-
SessionHandler
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.vertx.mutiny.ext.web.handler.PlatformHandler
PlatformHandler.PlatformHandlerImpl -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TypeArg<SessionHandler>static final booleanDefault of whether the cookie has the HttpOnly flag set More info: https://www.owasp.org/index.php/HttpOnlystatic final booleanDefault of whether the cookie has the 'secure' flag set to allow transmission over https only.static final booleanDefault of whether the session should be created lazily.static final booleanDefault of whether a nagging log warning should be written if the session handler is accessed over HTTP, not HTTPSstatic final StringDefault name of session cookiestatic final StringDefault path of session cookiestatic final longstatic final intDefault min length for a session id. -
Constructor Summary
ConstructorsConstructorDescriptionSessionHandler(io.vertx.ext.web.handler.SessionHandler delegate) Create a new instance ofSessionHandlerdelegating to the given (non-null) instance ofSessionHandler.SessionHandler(Object delegate) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(RoutingContext item) Handle an item.static SessionHandlercreate(SessionStore sessionStore) Create a session handlerbooleanio.smallrye.mutiny.Uni<Void>flush(RoutingContext ctx) Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level.io.smallrye.mutiny.Uni<Void>flush(RoutingContext ctx, boolean ignoreStatus) Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level.voidFlush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level.voidflushAndAwait(RoutingContext ctx, boolean ignoreStatus) Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level.Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level.flushAndForget(RoutingContext ctx, boolean ignoreStatus) Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level.io.vertx.ext.web.handler.SessionHandlerGet the delegate instance.voidhandle(RoutingContext item) Handle an item.inthashCode()static SessionHandlernewInstance(io.vertx.ext.web.handler.SessionHandler delegate) Creates a new instance of theSessionHandler.newSession(RoutingContext context) Create a new sessionsetCookieHttpOnlyFlag(boolean httpOnly) Sets whether the 'HttpOnly' flag should be set for the session cookie.setCookieless(boolean cookieless) Use sessions based on url paths instead of cookies.setCookieMaxAge(long cookieMaxAge) Set a Cookie max-age to the session cookie.setCookieSameSite(io.vertx.core.http.CookieSameSite policy) Set the session cookie SameSite policy to use.setCookieSecureFlag(boolean secure) Sets whether the 'secure' flag should be set for the session cookie.setLazySession(boolean lazySession) Use a lazy session creation mechanism.setMinLength(int minLength) Set expected session id minimum length.setNagHttps(boolean nag) Set whether a nagging log warning should be written if the session handler is accessed over HTTP, not HTTPSsetSessionCookieName(String sessionCookieName) Set the session cookie namesetSessionCookiePath(String sessionCookiePath) Set the session cookie pathsetSessionTimeout(long timeout) Set the session timeoutsetSigningSecret(String secret) Set signing secret for the session cookie.io.smallrye.mutiny.Uni<Void>setUser(RoutingContext context, User user) Set the user for the sessionvoidsetUserAndAwait(RoutingContext context, User user) Set the user for the sessionsetUserAndForget(RoutingContext context, User user) Set the user for the sessiontoString()
-
Field Details
-
DEFAULT_SESSION_COOKIE_NAME
Default name of session cookie- See Also:
-
DEFAULT_SESSION_COOKIE_PATH
Default path of session cookie- See Also:
-
DEFAULT_SESSION_TIMEOUT
public static final long DEFAULT_SESSION_TIMEOUT- See Also:
-
DEFAULT_NAG_HTTPS
public static final boolean DEFAULT_NAG_HTTPSDefault of whether a nagging log warning should be written if the session handler is accessed over HTTP, not HTTPS- See Also:
-
DEFAULT_COOKIE_HTTP_ONLY_FLAG
public static final boolean DEFAULT_COOKIE_HTTP_ONLY_FLAGDefault of whether the cookie has the HttpOnly flag set More info: https://www.owasp.org/index.php/HttpOnly- See Also:
-
DEFAULT_COOKIE_SECURE_FLAG
public static final boolean DEFAULT_COOKIE_SECURE_FLAGDefault of whether the cookie has the 'secure' flag set to allow transmission over https only. More info: https://www.owasp.org/index.php/SecureFlag- See Also:
-
DEFAULT_SESSIONID_MIN_LENGTH
public static final int DEFAULT_SESSIONID_MIN_LENGTHDefault min length for a session id. More info: https://www.owasp.org/index.php/Session_Management_Cheat_Sheet- See Also:
-
DEFAULT_LAZY_SESSION
public static final boolean DEFAULT_LAZY_SESSIONDefault of whether the session should be created lazily.- See Also:
-
__TYPE_ARG
-
-
Constructor Details
-
SessionHandler
public SessionHandler(io.vertx.ext.web.handler.SessionHandler delegate) Create a new instance ofSessionHandlerdelegating to the given (non-null) instance ofSessionHandler. -
SessionHandler
-
-
Method Details
-
accept
Handle an item. This method is generated from theoriginalmethod."- Specified by:
acceptin interfaceConsumer<RoutingContext>- Specified by:
acceptin interfacePlatformHandler
-
handle
Handle an item. This method is generated from theoriginalmethod."- Specified by:
handlein interfaceio.vertx.core.Handler<RoutingContext>- Specified by:
handlein interfacePlatformHandler
-
getDelegate
public io.vertx.ext.web.handler.SessionHandler 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 interfaceMutinyDelegate- Specified by:
getDelegatein interfacePlatformHandler- Returns:
- the delegate instance
-
flush
Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.Unlike the bare Vert.x variant, this method returns a
Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.Don't forget to subscribe on it to trigger the operation.
- Parameters:
ctx- the current context- Returns:
- A
Unirepresenting the asynchronous result of this operation. - See Also:
-
io.vertx.ext.web.handler.SessionHandler#flush(RoutingContext)
-
flushAndAwait
Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.Unlike the bare Vert.x variant, this method returns a
Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in aRuntimeException).- Parameters:
ctx- the current context- See Also:
-
io.vertx.ext.web.handler.SessionHandler#flush(RoutingContext)
-
flushAndForget
Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.Unlike the bare Vert.x variant, this method ignores the
Voidresult or any failure.- Parameters:
ctx- the current context- Returns:
- The current instance to chain operations if needed.
- See Also:
-
io.vertx.ext.web.handler.SessionHandler#flush(RoutingContext)
-
flush
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> flush(RoutingContext ctx, boolean ignoreStatus) Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.Unlike the bare Vert.x variant, this method returns a
Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.Don't forget to subscribe on it to trigger the operation.
- Parameters:
ctx- the current contextignoreStatus- flush regardless of response status code- Returns:
- A
Unirepresenting the asynchronous result of this operation. - See Also:
-
io.vertx.ext.web.handler.SessionHandler#flush(RoutingContext, boolean)
-
flushAndAwait
Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.Unlike the bare Vert.x variant, this method returns a
Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in aRuntimeException).- Parameters:
ctx- the current contextignoreStatus- flush regardless of response status code- See Also:
-
io.vertx.ext.web.handler.SessionHandler#flush(RoutingContext, boolean)
-
flushAndForget
Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.Unlike the bare Vert.x variant, this method ignores the
Voidresult or any failure.- Parameters:
ctx- the current contextignoreStatus- flush regardless of response status code- Returns:
- The current instance to chain operations if needed.
- See Also:
-
io.vertx.ext.web.handler.SessionHandler#flush(RoutingContext, boolean)
-
setUser
Set the user for the sessionUnlike the bare Vert.x variant, this method returns a
Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.Don't forget to subscribe on it to trigger the operation.
- Parameters:
context- the routing contextuser- the user- Returns:
- A
Unirepresenting the asynchronous result of this operation. - See Also:
-
io.vertx.ext.web.handler.SessionHandler#setUser(RoutingContext, User)
-
setUserAndAwait
Set the user for the sessionUnlike the bare Vert.x variant, this method returns a
Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in aRuntimeException).- Parameters:
context- the routing contextuser- the user- See Also:
-
io.vertx.ext.web.handler.SessionHandler#setUser(RoutingContext, User)
-
setUserAndForget
Set the user for the sessionUnlike the bare Vert.x variant, this method ignores the
Voidresult or any failure.- Parameters:
context- the routing contextuser- the user- Returns:
- The current instance to chain operations if needed.
- See Also:
-
io.vertx.ext.web.handler.SessionHandler#setUser(RoutingContext, User)
-
create
Create a session handler- Parameters:
sessionStore- the session store- Returns:
- the handler
-
setSessionTimeout
Set the session timeout- Parameters:
timeout- the timeout, in ms.- Returns:
- a reference to this, so the API can be used fluently
-
setNagHttps
Set whether a nagging log warning should be written if the session handler is accessed over HTTP, not HTTPS- Parameters:
nag- true to nag- Returns:
- a reference to this, so the API can be used fluently
-
setCookieSecureFlag
Sets whether the 'secure' flag should be set for the session cookie. When set this flag instructs browsers to only send the cookie over HTTPS. Note that this will probably stop your sessions working if used without HTTPS (e.g. in development).- Parameters:
secure- true to set the secure flag on the cookie- Returns:
- a reference to this, so the API can be used fluently
-
setCookieHttpOnlyFlag
Sets whether the 'HttpOnly' flag should be set for the session cookie. When set this flag instructs browsers to prevent Javascript access to the the cookie. Used as a line of defence against the most common XSS attacks.- Parameters:
httpOnly- true to set the HttpOnly flag on the cookie- Returns:
- a reference to this, so the API can be used fluently
-
setSessionCookieName
Set the session cookie name- Parameters:
sessionCookieName- the session cookie name- Returns:
- a reference to this, so the API can be used fluently
-
setSessionCookiePath
Set the session cookie path- Parameters:
sessionCookiePath- the session cookie path- Returns:
- a reference to this, so the API can be used fluently
-
setMinLength
Set expected session id minimum length.- Parameters:
minLength- the session id minimal length- Returns:
- a reference to this, so the API can be used fluently
-
setCookieSameSite
Set the session cookie SameSite policy to use.- Parameters:
policy- to use,nullfor no policy.- Returns:
- a reference to this, so the API can be used fluently
-
setLazySession
Use a lazy session creation mechanism. The session will only be created when accessed from the context. Thus the session cookie is set only if the session was accessed.- Parameters:
lazySession- true to have a lazy session creation.- Returns:
- a reference to this, so the API can be used fluently
-
setCookieMaxAge
Set a Cookie max-age to the session cookie. When doing this the Cookie will be persistent across browser restarts. This can be dangerous as closing a browser windows does not invalidate the session. For more information refer to https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#Expire_and_Max-Age_Attributes- Parameters:
cookieMaxAge- a non negative max-age, note that 0 means expire now.- Returns:
- a reference to this, so the API can be used fluently
-
setCookieless
Use sessions based on url paths instead of cookies. This is an potential less safe alternative to cookies but offers an alternative when Cookies are not desired, for example, to avoid showing banners on a website due to cookie laws, or doing machine to machine operations where state is required to maintain.- Parameters:
cookieless- true if a cookieless session should be used- Returns:
- a reference to this, so the API can be used fluently
-
newSession
Create a new session- Parameters:
context- the routing context- Returns:
- the session
-
setSigningSecret
Set signing secret for the session cookie. The cookie will not be signed and verified by the SessionHandler if this is not set. But may be signed by the session implementation, for example, CookieSessionStore signs the cookie data.- Parameters:
secret- the secret used to sign the session cookie data- Returns:
- a reference to this, so the API can be used fluently
-
newInstance
Creates a new instance of theSessionHandler. -
hashCode
public int hashCode() -
equals
-
toString
-