【发布时间】: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