Java 基于Redis的Spring安全并发控制
我们有一个关于Spring框架的项目。它包含具有以下配置的Spring安全性:Java 基于Redis的Spring安全并发控制,java,spring,spring-security,redis,spring-session,Java,Spring,Spring Security,Redis,Spring Session,我们有一个关于Spring框架的项目。它包含具有以下配置的Spring安全性: @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers(LOGIN_URL + "/**").permitAll() .antMatchers("/resources/**").permitAll()
@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)
;
}
@覆盖
受保护的无效配置(HttpSecurity http)引发异常{
http.authorizeRequests()
.antMatchers(登录名为“/**”).permitAll()
.antMatchers(“/resources/**”).permitAll()
.antMatchers(“/**”).access()
.及()
.formLogin()
.loginPage(登录地址)
.defaultSuccessUrl(登录URL+“/success”,true)
.failureUrl(登录\ URL+“/错误”)
.usernameParameter(“用户名”).passwordParameter(“密码”)
.及()
.logout().logout成功URL(logout\u URL)
.及()
.csrf()
.及()
.securityContext().securityContextRepository(重新加载用户权限服务)
.及()
.会议管理()
.最多会议(1)
.sessionRegistry(sessionRegistry)
.expiredUrl(登录地址)
;
}
它在一台ApacheTomcat服务器上工作。如果我尝试从其他浏览器登录,我以前的http会话将过期
现在我们需要添加Redis服务器(V4.0.9)作为http会话的存储,因为我们需要在多个实例之间共享会话。
但是我可以通过同一个用户和不同的会话登录两个ApacheTomcat。这很糟糕。
我尝试了几种方法来配置它:
有人能帮我吗?谢谢大家。我忘了创建SpringSessionBackedSessionRegistry bean。
问题现在已经解决。您需要使redis缓存中的用户会话无效。这可能会有所帮助:您可以显示
sessionRegistry
bean的声明吗?