Skip to content

Commit

Permalink
refactor: compatible with session timeout configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Apr 22, 2024
1 parent d380c6b commit 434a581
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.concurrent.ConcurrentHashMap;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.session.SessionProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
Expand Down Expand Up @@ -138,8 +140,14 @@ ServerSecurityContextRepository securityContextRepository() {
}

@Bean
public ReactiveIndexedSessionRepository<MapSession> reactiveSessionRepository() {
return new InMemoryReactiveIndexedSessionRepository(new ConcurrentHashMap<>());
public ReactiveIndexedSessionRepository<MapSession> reactiveSessionRepository(
SessionProperties sessionProperties,
ServerProperties serverProperties) {
var repository = new InMemoryReactiveIndexedSessionRepository(new ConcurrentHashMap<>());
var timeout = sessionProperties.determineTimeout(
() -> serverProperties.getServlet().getSession().getTimeout());
repository.setDefaultMaxInactiveInterval(timeout);
return repository;
}

@Bean
Expand Down

0 comments on commit 434a581

Please sign in to comment.