首页 > 解决方案 > 注销请求返回 http 404

问题描述

我正在尝试在 3.0.7 版本中为 spring-security 进行基本配置。当我转到/logoutURL 时,我得到 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>

标签: javaspring-mvcspring-security

解决方案


推荐阅读