[英]Spring logout gives 404 error
I've gone through all of the solutions listed at SO but can't seem to make it work. 我已经查看了SO中列出的所有解决方案,但似乎无法使其正常工作。 I've a simple spring-security xml file-
我有一个简单的spring-security xml文件 -
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
<http auto-config='true' use-expressions="true">
<intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user" password="user" authorities="ROLE_USER"/>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
My logout page looks like this- 我的注销页面看起来像这样 -
<form action="j_spring_security_logout" method="post" id="logoutForm">
<input type="hidden"
name="${_csrf.parameterName}"
value="${_csrf.token}" />
</form>
<script>
function formSubmit() {
document.getElementById("logoutForm").submit();
}
</script>
<c:if test="${pageContext.request.userPrincipal.name != null}">
<h2>
Welcome : ${pageContext.request.userPrincipal.name} |
<a href="javascript:formSubmit()"> Logout</a>
</h2>
</c:if>
But I get 404 error when I make HTTP POST; 但是当我进行HTTP POST时,我收到404错误; Spring gives following error message-
Spring提供以下错误消息 -
WARNING: No mapping found for HTTP request with URI [/j_spring_security_logout] in DispatcherServlet with name 'spring-dispatcher'
What am I doing wrong? 我究竟做错了什么?
Spring versions (from pom.xml)- Spring版本(来自pom.xml) -
<spring-core-version>4.1.6.RELEASE</spring-core-version>
<spring-security-version>4.0.1.RELEASE</spring-security-version>
According to the docs , the logout URL ins Spring Security 4 is just /logout
, so it should work if you change your form action. 根据文档 ,Spring Security 4中的注销URL只是
/logout
,因此如果您更改表单操作它应该可以工作。
I would also drop the auto-config
attribute and just set what you want to use explicitly, following the examples in the manual. 我还会删除
auto-config
属性,并按照手册中的示例设置您要明确使用的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.