Class ServerHttpSecurity.SessionManagementSpec.ConcurrentSessionsSpec
java.lang.Object
org.springframework.security.config.web.server.ServerHttpSecurity.SessionManagementSpec.ConcurrentSessionsSpec
- Enclosing class:
- ServerHttpSecurity.SessionManagementSpec
Configures how many sessions are allowed for a given user.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionmaximumSessions
(SessionLimit sessionLimit) Sets the maximum number of sessions allowed for any user.maximumSessionsExceededHandler
(ServerMaximumSessionsExceededHandler maximumSessionsExceededHandler) Sets theServerMaximumSessionsExceededHandler
to use when the maximum number of sessions is exceeded.sessionRegistry
(ReactiveSessionRegistry reactiveSessionRegistry) Sets theReactiveSessionRegistry
to use.
-
Constructor Details
-
ConcurrentSessionsSpec
public ConcurrentSessionsSpec()
-
-
Method Details
-
sessionRegistry
public ServerHttpSecurity.SessionManagementSpec.ConcurrentSessionsSpec sessionRegistry(ReactiveSessionRegistry reactiveSessionRegistry) Sets theReactiveSessionRegistry
to use.- Parameters:
reactiveSessionRegistry
- theReactiveSessionRegistry
to use- Returns:
- the
ServerHttpSecurity.SessionManagementSpec.ConcurrentSessionsSpec
to continue customizing
-
maximumSessions
public ServerHttpSecurity.SessionManagementSpec.ConcurrentSessionsSpec maximumSessions(SessionLimit sessionLimit) Sets the maximum number of sessions allowed for any user. You can useSessionLimit.of(int)
to specify a positive integer orSessionLimit.UNLIMITED
to allow unlimited sessions. To customize the maximum number of sessions on a per-user basis, you can provide a customSessionLimit
implementation, like so:http .sessionManagement((sessions) -> sessions .concurrentSessions((concurrency) -> concurrency .maximumSessions((authentication) -> { if (authentication.getName().equals("admin")) { return Mono.empty() // unlimited sessions for admin } return Mono.just(1); // one session for every other user }) ) )
- Parameters:
sessionLimit
- the maximum number of sessions allowed for any user- Returns:
- the
ServerHttpSecurity.SessionManagementSpec.ConcurrentSessionsSpec
to continue customizing
-
maximumSessionsExceededHandler
public ServerHttpSecurity.SessionManagementSpec.ConcurrentSessionsSpec maximumSessionsExceededHandler(ServerMaximumSessionsExceededHandler maximumSessionsExceededHandler) Sets theServerMaximumSessionsExceededHandler
to use when the maximum number of sessions is exceeded.- Parameters:
maximumSessionsExceededHandler
- theServerMaximumSessionsExceededHandler
to use- Returns:
- the
ServerHttpSecurity.SessionManagementSpec.ConcurrentSessionsSpec
to continue customizing
-