spring-security icon indicating copy to clipboard operation
spring-security copied to clipboard

Add Max Session to WebFlux

Open bentenzheng opened this issue 8 years ago • 24 comments

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)

bentenzheng avatar Nov 30 '18 04:11 bentenzheng

We do not currently support max sessions in WebFlux. I converted this issue into a ticket for that support

rwinch avatar Nov 30 '18 14:11 rwinch

Can I give it a try??

ankurpathak avatar Dec 03 '18 08:12 ankurpathak

@ankurpathak Sure! The ticket is yours

rwinch avatar Dec 03 '18 21:12 rwinch

@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"));
        }

}
  1. AuthenticationWebFilter will have instanace of ServerSessionAuthenticationStrategy
  2. After authentication check session counts delegating it to ServerSessionAuthenticationStrategy
  3. Two implementation of ServerSessionAuthenticationStrategy NoOp and Concurrent 4 Support for adding ServerSessionAuthenticationStrategy in all AuthenticationWebFilter in ServerHttpSecurity

ankurpathak avatar Dec 06 '18 07:12 ankurpathak

@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?

ankurpathak avatar Dec 13 '18 05:12 ankurpathak

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 avatar Dec 18 '18 20:12 rwinch

@rwinch Is this ticket alive? Can I try to solve this?

yakunin-kirill avatar Sep 12 '19 12:09 yakunin-kirill

@rwinch Do we have any solution?

mukeshkamboj avatar Mar 11 '20 06:03 mukeshkamboj

@mukeshkamboj @rwinch I am not working on this.

ankurpathak avatar Mar 12 '20 10:03 ankurpathak

@rwinch Still relevant? May I suggest a solution?

yakunin-kirill avatar Mar 14 '20 21:03 yakunin-kirill

Is this ticket still considered relevant? The ability to control the number of parallel sessions is often requested in reviews as a security function.

Johannes-Rost avatar Aug 14 '20 13:08 Johannes-Rost

Is there any workaround for it in webflux using ReactiveRedisSessionRepository

rishisc avatar Jul 02 '21 11:07 rishisc

Any progress of this issue?

Danushka96 avatar Aug 14 '21 10:08 Danushka96

Hi, any progress or suggestions on this?

SuveenVundavalli avatar Sep 03 '21 12:09 SuveenVundavalli

Hi, any progress or suggestions on this issue ?

yangdq1 avatar Nov 22 '21 02:11 yangdq1

Hi, any progress or suggestions on this?

maradanasai avatar Mar 25 '22 06:03 maradanasai

Hi, any progress or suggestions on this?

RajeevKumarMarrapu avatar Mar 25 '22 06:03 RajeevKumarMarrapu

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

dgallego58 avatar May 08 '22 01:05 dgallego58

Any Progress on this?

JonnyDeates avatar Apr 13 '23 20:04 JonnyDeates

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.

marcusdacoregio avatar Apr 13 '23 23:04 marcusdacoregio