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

Session Control with Redis

Open dreamstar-enterprises opened this issue 1 year ago • 0 comments

How do I implement Session Control, when I use @EnableRedisWebSession on my security chain? Spring Session automatically creates beans that implement @WebSession and @WebsessionStore But the function below, in order to autowire WebSessionStore, needs to see a manual implementation of WebsessionStore, so what do I do?

@Component
internal class SessionControl(
    private val reactiveSessionRegistry: SpringSessionBackedReactiveSessionRegistry<ReactiveRedisIndexedSessionRepository.RedisSession>,
    private val webSessionStore: WebSessionStore
) {

    fun invalidateSessions(username: String): Mono<Void> {
        return reactiveSessionRegistry.getAllSessions(username)
            .flatMap { session ->
                session.invalidate() // invalidate the session
                    .then(webSessionStore.removeSession(session.sessionId)) // remove from WebSessionStore
                    .then(Mono.just(session)) // ensure the session object is returned for logging or further processing if needed
            }
            .then() // complete the Mono after processing all sessions
    }
}

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior.

Expected behavior A clear and concise description of what you expected to happen.

Sample

A link to a GitHub repository with a minimal, reproducible sample.

Reports that include a sample will take priority over reports that do not. At times, we may require a sample, so it is good to try and include a sample up front.

dreamstar-enterprises avatar Jul 26 '24 23:07 dreamstar-enterprises