认证系统往往都带有注销登录功能,Spring Security也提供了这方面的支持。事实上,从我们编写配置类继承WebSecurityConfigurerAdapter的那一刻起,Spring Security就已经为我们的系统埋入了注销的逻辑。
protected final HttpSecurity getHttp() throws Exception {
if (http != null) {
return http;
}
AuthenticationEventPublisher eventPublisher = getAuthenticationEventPublisher();
localConfigureAuthenticationBldr.authenticationEventPublisher(eventPublisher);
AuthenticationManager authenticationManager = authenticationManager();
authenticationBuilder.parentAuthenticationManager(authenticationManager);
Map<Class<?>, Object> sharedObjects = createSharedObjects();
http = new HttpSecurity(objectPostProcessor, authenticationBuilder,
sharedObjects);
if (!disableDefaults) {
// @formatter:off
http
.csrf().and()
.addFilter(new WebAsyncManagerIntegrationFilter())
.exceptionHandling().and()
.headers().and()
.sessionManagement().and()
.securityContext().and()
.requestCache().and()
.anonymous().and()
.servletApi().and()
.apply(new DefaultLoginPageConfigurer<>()).and()
.logout();
// @formatter:on
ClassLoader classLoader = this.context.getClassLoader();
List<AbstractHttpConfigurer> defaultHttpConfigurers =
SpringFactoriesLoad

本文探讨了Spring Security的注销登录功能,指出当配置类继承WebSecurityConfigurerAdapter时,系统已内置注销逻辑。通过HttpSecurity的logout()方法,可以设置注销过滤器,默认注销路由为'/logout',执行包括HttpSession失效、Remember-me验证清除、SecurityContextHolder清空等一系列操作,并在成功后重定向到'/login?logout'。注销流程由多个LogoutHandler协同完成。
最低0.47元/天 解锁文章
6088

被折叠的 条评论
为什么被折叠?



