【发布时间】:2019-01-23 07:01:12
【问题描述】:
我们有一个关于 Spring Framework 的项目。它包含具有此配置的 Spring Security:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers(LOGIN_URL + "/**").permitAll()
.antMatchers("/resources/**").permitAll()
.antMatchers("/**").access(<...>)
.and()
.formLogin()
.loginPage(LOGIN_URL)
.defaultSuccessUrl(LOGIN_URL + "/success", true)
.failureUrl(LOGIN_URL + "/error")
.usernameParameter("username").passwordParameter("password")
.and()
.logout().logoutSuccessUrl(LOGOUT_URL)
.and()
.csrf()
.and()
.securityContext().securityContextRepository(reloadUserAuthoritiesService)
.and()
.sessionManagement()
.maximumSessions(1)
.sessionRegistry(sessionRegistry)
.expiredUrl(LOGIN_URL)
;
}
它可以在一台 Apache Tomcat 服务器上运行。如果我尝试从其他浏览器登录,我之前的 http 会话将过期。
现在我们需要添加 Redis 服务器 (v 4.0.9) 作为 http 会话的存储,因为我们需要在多个实例之间共享会话。 但是我可以通过同一用户和不同的会话登录两个 Apache Tomcat。这不好。 我尝试了几种配置方式:
- https://www.baeldung.com/spring-session(注解配置)
- 只有没有项目更改的 tomcat 配置 (redis-session-manager-with-dependencies-2.2.2.jar)
所有这些方法都行不通。 我也发现了这个问题:https://github.com/spring-projects/spring-session/issues/65 它是在两年前实施的。 有人可以帮帮我吗?
【问题讨论】:
-
你需要使redis缓存中的用户会话失效。可能这会有所帮助:stackoverflow.com/questions/43090679/…
-
你能显示你的
sessionRegistrybean 的声明吗?
标签: java spring spring-security redis spring-session