Spring boot Can';t通过自定义注销处理程序注销
在我的spring boot应用程序中,我想添加注销链接 在模板welcome.html中:Spring boot Can';t通过自定义注销处理程序注销,spring-boot,spring-security,Spring Boot,Spring Security,在我的spring boot应用程序中,我想添加注销链接 在模板welcome.html中: <!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"/> <title th:text="${appName}">Template title</title> <body> <h
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title th:text="${appName}">Template title</title>
<body>
<h1>Welcome to <span th:text="${appName}">Our App</span></h1>
<h2>Dictionaries:</h2>
<p><a href="/categories">Categories</a></p>
<p><a href="/users">Users</a></p>
<p><a href="/logout">Logout</a></p>
</body>
</html>
我的经纪人:
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:");
// some custom logic here
response.sendRedirect(request.getContextPath() + "/login.html");
}
}
正如您所看到的,它只是转发到登录页面
但是,当我在注销链接上单击welcome.html时,方法onLogoutSuccess
不会被调用,我会得到错误页面:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Jan 26 18:21:53 EET 2020
There was an unexpected error (type=Not Found, status=404).
No message available
将重定向到执行获取请求的“/logout”
。
除非您在“/logout”
处呈现页面,否则您将收到404
默认情况下,只有当POST
请求“/logout”
时才会触发注销
因为您使用的是Thymeleaf,所以您可以使用类似这样的东西来注销
<form action="#" th:action="@{/logout}" method="post">
<input type="submit" value="Logout" />
</form>
<form action="#" th:action="@{/logout}" method="post">
<input type="submit" value="Logout" />
</form>