java - 未在 SimpleUrlLogoutSuccessHandle 上调用 onLogoutSuccess
问题描述
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource; // get by Spring
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
// Here, you are making the public directory on the classpath root available without authentication (e..g. for css files)
.antMatchers("/public/**", "/registration.html").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login.html")
.successHandler((request, response, authentication) -> new DefaultRedirectStrategy().sendRedirect(request, response, "/welcome"))
.failureUrl("/login-error.html")
.permitAll()
.and()
.logout()
.logoutSuccessHandler(new CustomLogoutSuccessHandler())
.permitAll();
}
}
这是我的自定义处理程序:CustomLogoutSuccessHandler.java
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler implements LogoutSuccessHandler {
private static Logger logger = LogManager.getLogger(CustomLogoutSuccessHandler.class);
@Override
public void onLogoutSuccess(
HttpServletRequest request,
HttpServletResponse response,
Authentication authentication)
throws IOException, ServletException {
logger.info("onLogoutSuccess:");
response.sendRedirect(request.getContextPath() + "/login.html");
}
}
在我的模板 ( users.html
) 中,我添加了一个这样的链接:
<p align="center"><a th:href="@{/logout.html}">Logout</a></p>
但是,当单击注销链接时,onLogoutSuccess
不会在我的自定义处理程序类上调用该方法。
为什么?
解决方案
推荐阅读
- python - ImportError:无法导入名称“while_v2”
- python - 计算列表列表中的元素
- concourse - 如何在大厅的 ui 中明确排序任务?
- java - 如何拥有多个spring boot批处理配置类
- jquery - jquery .offset().top 没有预期的行为
- centos - 无法在 CentOS 8 上安装 Icinga Web 2
- python - 在 Python 中创建具有序号的矩阵
- facebook - 如何在网站上显示 Facebook 页面约会
- java - cucumber.runtime.junit.UndefinedThrowable:步骤未定义
- java - 发现在tomcat生成端口(动态端口)之前向端口0注册服务