java - 注销请求返回 http 404
问题描述
我正在尝试在 3.0.7 版本中为 spring-security 进行基本配置。当我转到/logout
URL 时,我得到 HTTP 404 并且用户仍处于登录状态。更重要的是,尽管它可以permitAll
访问,但我看到 spring 扫描登录的用户是否有 ROLE_USER (可能有问题, <intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
因为它需要每个请求而不是查看其他规则)。这里有什么问题?
我不想使用任何 JSP 文件!!!!只是后端在这里。它可以在注销后返回一个空白页面。
应用程序-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/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/logout" access="permitAll"/>
<intercept-url pattern="/asd" access="permitAll"/>
<intercept-url pattern="/accessdenied" access="permitAll"/>
<intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
<intercept-url pattern="/users" access="hasRole('ROLE_ADMIN')"/>
<logout logout-url="/logout" />
<http-basic/>
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider>
<user-service>
<user name="admin1" password="pass" authorities="ROLE_USER"/>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
web.xml
<web-app version="3.0" 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_3_0.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring/webcontext/myServlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<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>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/application-security.xml
</param-value>
</context-param>
解决方案
推荐阅读
- webdriver - WebdriverIO - 为什么 waitUntil() 不起作用?
- c - 如何在不更改标准输入缓冲区的内容的情况下以可移植方式、非阻塞方式检测用户是否按下了某个键?
- cluster-analysis - 如何对 3 维数据进行聚类?
- javascript - 仅当错误代码为 403 时才尝试登录
- flutter - 在颤动中单击 DataRow-Selected 后没有更新
- python - 如何轻松运行类方法
- apache-storm - 在 Storm 2.2.0 中使用 Flux.main() 以本地模式运行拓扑
- html - 如何在包含在 CDATA 中的 HTML 格式的 XML 字符串中使用主题颜色属性
- php - 无法从本地网络访问 wamp
- sql - 将数据透视到新的列名 - Oracle SQL