Ответ 1
Если вы используете logout с CSRF, вы должны выполнить POST. См. http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#csrf-logout
Когда я пытаюсь получить доступ к URL выхода из моего приложения spring, я получаю ошибку 404 и No mapping found for HTTP Request with URI [/logout] in DispatcherServlet with name 'mvc-dispatcher'
в моем журнале сервера.
Я уже пробовал Звонок в j_spring_security_logout не работает, Проблема с выводом безопасности spring и довольно много всех связанных результатов на SO.
Я включаю в себя все файлы конфигурации, поскольку структура spring xml еще не совсем понятна мне.
Моя конфигурация безопасности:
<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/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<http pattern="/resources/**" security="none" />
<http auto-config="true">
<intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<intercept-url pattern="/**" access="ROLE_USER" />
<form-login login-page="/login" default-target-url="/"/>
<logout logout-url="/logout" />
<csrf />
</http>
<global-method-security secured-annotations="enabled" />
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService" />
</authentication-manager>
</beans:beans>
My web.xml
:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>XYZ</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/*-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Как сделать страницу выхода из системы?
Если вы используете logout с CSRF, вы должны выполнить POST. См. http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#csrf-logout
У меня была такая же проблема после перехода от Spring от 3.2 до 4, но я хотел выйти из системы, используя ссылку в представлении.
Spring doco (http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#csrf-include-csrf-token-form) объясняет, как это сделать в представлении.
Я использовал этот фрагмент в JSP для выхода из системы:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:form action="${pageContext.request.contextPath}/logout" method="POST">
<input type="submit" value="Logout" />
</form:form>