【问题标题】:Spring Web Security logout not working with httpBasic authenticationSpring Web Security 注销不适用于 httpBasic 身份验证
【发布时间】:2014-10-01 05:59:50
【问题描述】:

我正在使用基本身份验证来保护我正在处理的初始 REST Web 服务。 似乎一切正常,除了注销路径似乎不起作用。如文档所述,它重定向到“/login?logout”,但我的用户似乎并没有真正被注销。 (即,我仍然可以按预期访问页面 X 而不是页面 Y)。

应用配置:

@Configuration
@ComponentScan
@EnableAutoConfiguration(exclude = ManagementSecurityAutoConfiguration.class)
@EnableWebSecurity
@EnableSwagger
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
    @Configuration
    protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.httpBasic()
            .and().authorizeRequests().antMatchers("/manage/**").hasRole("ADMIN")
            .anyRequest().fullyAuthenticated()
            .and().logout().permitAll().logoutRequestMatcher(new AntPathRequestMatcher("/logout", HttpMethod.GET.toString())).invalidateHttpSession(true);
        }

        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN", "USER").and().withUser("user").password("user").roles("USER");
        }
    }
}

请注意,总体而言,安全性看起来是有效的。我可以打开一个新的隐身标签,并且身份验证/安全性按预期工作。

【问题讨论】:

  • 你用浏览器测试吗?您确定它没有缓存凭据并在“背后”重复使用它们吗?您应该检查请求/响应往返以确保。
  • 我认为不会发生这种情况。我目前已禁用缓存,在日志中,当我访问“USER”安全路径时,似乎会话甚至被清除:2014-08-07 16:58:36.931 INFO 2132 --- [nio-8080-exec-2] o.s.b.a.audit.listener.AuditListener : AuditEvent [timestamp=Thu Aug 07 16:58:36 EDT 2014, principal=user, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null}]
  • 如果重要,注销确实在与 formLogin() 一起使用时起作用...我误解了注销路径应该如何工作吗?
  • 正如 GPI 所说,您应该检查您的浏览器没有自动重新发送凭据,这在基本身份验证中很常见,并且独立于任何服务器端注销的概念。还要在服务器上启用调试日志记录。
  • 正如@LukeTaylor 在一般注销中提到的不适用于基本/摘要身份验证。 Afaik 一旦通过身份验证,浏览器就会不断将标头发送到应用程序,一旦您注销,它将有效地进行新的登录。

标签: java spring spring-security spring-boot


【解决方案1】:

您无法使用注销链接从基本 http 身份验证中注销。

请查看类似的帖子here

【讨论】:

    猜你喜欢
    • 2015-12-11
    • 2019-10-14
    • 2021-01-20
    • 2018-02-10
    • 1970-01-01
    • 2011-11-14
    • 2014-08-24
    • 2020-09-08
    • 2017-07-08
    相关资源
    最近更新 更多