Add Max Session to WebFlux
When i am using webflux , how can i achieve a similar effect ,get all login user session , like as : http.sessionManagement() .maximumSessions(1).sessionRegistry(getSessionRegistry()).maxSessionsPreventsLogin(false)
We do not currently support max sessions in WebFlux. I converted this issue into a ticket for that support
Can I give it a try??
@ankurpathak Sure! The ticket is yours
@rwinch I would like to dicusss this ticket progressively: Here is a top lable flow I am thinking to use:
class AuthenticationWebFilter {
private ServerSessionAuthenticationStrategy sessionAuthenticationStrategy = NullAuthenticatedServerSessionStrategy.getInstance();
private Mono<Void> authenticate(ServerWebExchange exchange,
WebFilterChain chain, Authentication token) {
WebFilterExchange webFilterExchange = new WebFilterExchange(exchange, chain);
return this.authenticationManager.authenticate(token)
.switchIfEmpty(Mono.defer(() -> Mono.error(new IllegalStateException("No provider found for " + token.getClass()))))
.flatMap(authentication -> sessionAuthenticationStrategy.onAuthentication(authentication, webFilterExchange.getExchange()).then(Mono.just(authentication)))
.flatMap(authentication -> onAuthenticationSuccess(authentication, webFilterExchange))
.onErrorResume(AuthenticationException.class, e -> this.authenticationFailureHandler
.onAuthenticationFailure(webFilterExchange, e));
}
}
public interface ServerSessionAuthenticationStrategy {
Mono<Void> onAuthentication(Authentication authentication, ServerWebExchange exchange);
}
public class NoOpServerSessionAuthenticationStrategy implements ServerSessionAuthenticationStrategy {
Mono<Void> onAuthentication(Authentication authentication, ServerWebExchange exchange){
return Mono.empty();
}
}
public interface ConcurrentServerSessionAuthenticationStrategy implements ServerSessionAuthenticationStrategy{
Mono<Void> onAuthentication(Authentication authentication, ServerWebExchange exchange){
return Mono.error(new SessionAuthenticationException("Error"));
}
}
- AuthenticationWebFilter will have instanace of ServerSessionAuthenticationStrategy
- After authentication check session counts delegating it to ServerSessionAuthenticationStrategy
- Two implementation of ServerSessionAuthenticationStrategy NoOp and Concurrent 4 Support for adding ServerSessionAuthenticationStrategy in all AuthenticationWebFilter in ServerHttpSecurity
@rwinch What is equivalent of SessionRegistry in reactive world? I think we would need ReactiveSessionRegistry for this issue as using SessionRegistry may be non blocking for InMemoryImplementatio but may be blocking for SessionRegistry implemenation for Redis, Mongo, JDBC in Spring Session. What do you think?
We don't currently have an equivalent. Note: I'd try and reimagine the API a bit rather than copy it directly. See exactly what is needed by Spring Security and limit it to that.
@rwinch Is this ticket alive? Can I try to solve this?
@rwinch Do we have any solution?
@mukeshkamboj @rwinch I am not working on this.
@rwinch Still relevant? May I suggest a solution?
Is this ticket still considered relevant? The ability to control the number of parallel sessions is often requested in reviews as a security function.
Is there any workaround for it in webflux using ReactiveRedisSessionRepository
Any progress of this issue?
Hi, any progress or suggestions on this?
Hi, any progress or suggestions on this issue ?
Hi, any progress or suggestions on this?
Hi, any progress or suggestions on this?
this seems to be a long way, since authorization server is focused in Oauth2 patterns with spring security team i don't see coming this feature soon
Any Progress on this?
Hi everyone, that has been no progress yet on this. Please give a thumbs up to the root comment if you would like to see this feature in Spring Security, this helps us prioritize issues.
If anyone is interested in working on this feature, you are welcome.