Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 基于Redis的Spring安全并发控制_Java_Spring_Spring Security_Redis_Spring Session - Fatal编程技术网

Java 基于Redis的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()

我们有一个关于Spring框架的项目。它包含具有以下配置的Spring安全性:

@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。这很糟糕。 我尝试了几种方法来配置它:

  • (注释配置)
  • 只有tomcat配置没有项目更改(redis-session-manager-with-dependencies-2.2.jar)
  • 所有这些方法都不起作用。 我还发现了这个问题: 两年前实施的。
    有人能帮我吗?

    谢谢大家。我忘了创建SpringSessionBackedSessionRegistry bean。
    问题现在已经解决。

    您需要使redis缓存中的用户会话无效。这可能会有所帮助:您可以显示
    sessionRegistry
    bean的声明吗?