Spring Boot安全性注销不会使会话无效

阿纳尔达普

我增强的宠物诊所应用程序需要安全性。

当前,注销功能似乎无法正常工作。我有一个GET版本(简单链接)和一个POST版本(链接提交的隐藏表单)。

登录后,无论我使用哪种方法注销,一旦尝试再次登录,都将不允许进行新的登录。

我相信这与本节相关:

.sessionManagement()
    .maximumSessions(1)
    .maxSessionsPreventsLogin(true)
    .expiredUrl("/login?expired")

但我认为这一节:

.logout()
    .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
    .logoutSuccessUrl("/")
    .permitAll()

将使我无效,HttpSession以便允许下次登录,但这没有发生。

当我查看日志时,这些是第二次登录时不同的行:

s.CompositeSessionAuthenticationStrategy : Delegating to org.springframework.security.web.authentication.session.ConcurrentSessionControlAuthenticationStrategy@2cc9f3de
w.a.UsernamePasswordAuthenticationFilter : Authentication request failed: org.springframework.security.web.authentication.session.SessionAuthenticationException: Maximum sessions of 1 for this principal exceeded
w.a.UsernamePasswordAuthenticationFilter : Updated SecurityContextHolder to contain null Authentication
w.a.UsernamePasswordAuthenticationFilter : Delegating to authentication failure handler org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler@16c670c3

.a.SimpleUrlAuthenticationFailureHandler:重定向到/ login?错误

任何的建议都受欢迎。

我的应用程序可以在https://github.com/arnaldop/enhanced-pet-clinic找到

这是我的WebSecurityConfigurerAdapter子类中的代码

private static final String[] UNSECURED_RESOURCE_LIST =
    new String[] {"/", "/resources/**", "/assets/**", "/css/**", "/webjars/**",
        "/images/**", "/dandelion-assets/**", "/unauthorized", "/error*"};

@Override
public void configure(WebSecurity web) throws Exception {
    web
        .ignoring()
            .antMatchers(UNSECURED_RESOURCE_LIST);
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    //@formatter:off
    http
        .authorizeRequests()
            .antMatchers(UNSECURED_RESOURCE_LIST)
                .permitAll()
            .antMatchers("/owners/**", "/vets/**", "/vets*").hasRole("USER")
            .antMatchers("/manage/**").hasRole("ADMIN")
            .anyRequest()
                .permitAll()
        .and()
            .formLogin()
                .loginPage("/login")
                    .failureUrl("/login?error")
                    .permitAll()
        .and()
            .logout()
                .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                .logoutSuccessUrl("/")
                .permitAll()
        .and()
            .requiresChannel()
                .antMatchers("/login", "/owners/**", "/vets/**", "/vets*", "/manage/**")
                    .requiresSecure()
        .and()
            .exceptionHandling()
                .accessDeniedPage("/router?q=unauthorized")
        .and()
            .sessionManagement()
                .maximumSessions(1)
                .maxSessionsPreventsLogin(true)
                .expiredUrl("/login?expired")
        ;
    //@formatter:on
}
德伦·哈马尔(Dhiren Hamal)

我在春季启动时也遇到了相同的问题,该问题是通过实现HttpSessionEventPublisher来解决的

// Register HttpSessionEventPublisher
    @Bean
    public static ServletListenerRegistrationBean httpSessionEventPublisher() {
        return new ServletListenerRegistrationBean(new HttpSessionEventPublisher());
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在Spring-Session(Redis)和Spring-security中注销用户而不会使会话无效?

来自分类Dev

Spring Boot中的ACL安全性

来自分类Dev

Spring Boot安全性登录

来自分类Dev

Spring Boot Shell安全性

来自分类Dev

Spring Boot Shell安全性

来自分类Dev

Spring Boot 安全性的基本 URI

来自分类Dev

Spring安全性/ Spring会话/ Web套接字

来自分类Dev

安全性:090398无效的主题-Spring和Weblogic

来自分类Dev

Spring安全性注销转到j_spring_security_logout

来自分类Dev

Spring Boot无法提供基本的安全性

来自分类Dev

Spring Boot中的全局方法安全性

来自分类Dev

AngularJS + Spring Boot安全性以编程方式更改主体

来自分类Dev

具有容器安全性的Spring Boot

来自分类Dev

Spring Boot +安全性+多HTTP Web配置

来自分类Dev

通过Vaadin登录的Spring Boot安全性

来自分类Dev

在Spring Boot 1.4中测试安全性

来自分类Dev

Spring Boot安全性未正确配置

来自分类Dev

外部化Spring Boot /安全性配置

来自分类Dev

Spring Boot中的全局方法安全性

来自分类Dev

Spring Boot MVC基于非角色的安全性

来自分类Dev

Spring Boot安全性登录(v4)

来自分类Dev

Spring Boot 安全性 - Ant Matcher 不起作用

来自分类Dev

Okta Spring安全性

来自分类Dev

Maven:Spring 4 + Spring安全性

来自分类Dev

Maven:Spring 4 + Spring安全性

来自分类Dev

Spring安全性:Spring Security如何在SessionRegistry中注册新会话?

来自分类Dev

Spring安全性登录/注销-运行自定义代码

来自分类Dev

注销功能不会使会话无效

来自分类Dev

Spring Security:无法注销/使会话无效