【发布时间】:2015-08-09 20:10:45
【问题描述】:
我正在尝试使用 spring security v.4 向我的应用程序添加登录功能。登录工作正常,但是当我尝试注销时出现错误 404。 Spring Security 参考说默认注销 URL 是 /logout。我的应用程序部署在 /app URL 下,我尝试遵循 URL localhost:8080/app/logout 和 localhost:8080/app/json/logout。我在堆栈上发现了一些类似的问题,但它们与使用 CSRF 保护而我没有使用它的情况有关。这是我的 web.xml 文件的一部分
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/json-servlet.xml,
/WEB-INF/applicationContext.xml</param-value>
</context-param>
<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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>json</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>json</servlet-name>
<url-pattern>/json/*</url-pattern>
</servlet-mapping>
还有我的 json-servlet.xml 哪里是 spring 安全配置:
<context:component-scan base-package="test" />
<mvc:annotation-driven />
<security:http>
<security:intercept-url pattern="/**" access="hasRole('USER')" />
<security:form-login />
<security:logout />
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="test" password="1" authorities="ROLE_USER, ROLE_ADMIN" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
提前致谢。
【问题讨论】:
-
在使用 Spring 4 时不要使用 XML。只是不要。使用遍布其示例或 Spring Boot 的基于 java 的配置。
标签: spring spring-security http-status-code-404 logout