Spring Web安全性在使用httpBasic身份验证时无法注销登录

4

我正在使用基本认证来保护我正在开发的初始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");
        }
    }
}

请注意,总的来说安全措施似乎已经生效。我可以打开一个新的无痕标签,身份验证/安全措施按预期工作。

1
你是否使用浏览器进行测试?你确定它没有缓存凭据并在“背后”重复使用它们吗?你应该检查请求/响应往返以确保。 - GPI
我认为这不会发生。我目前已禁用缓存,在日志中,当我访问“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}] - bvulaj
如果有影响的话,当与formLogin()一起使用时,注销确实有效...我是否误解了注销路径的工作方式? - bvulaj
1
正如GPI所说,您应该检查浏览器是否自动重新发送凭据,这在基本身份验证中很常见,并且与任何服务器端注销的概念无关。同时在服务器上启用调试日志记录。 - Shaun the Sheep
1
正如@LukeTaylor所提到的,基本/摘要身份验证通常不适用于注销。据我所知,一旦经过身份验证,浏览器将继续向应用程序发送标头,这实际上意味着您在注销后需要重新登录。 - M. Deinum
1个回答

4

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

请查看类似的主题这里


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接