认证请求/ j_spring_security_check 404错误(Authentication

2019-10-22 16:31发布

与下面的安全配置,使得POST请求/ j_spring_security_check抛出404错误。 可能有人帮我指出我做错了什么?

security.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
              http://www.springframework.org/schema/security
              http://www.springframework.org/schema/security/spring-security-4.0.xsd">

    <!-- Areas of the application which require no secuirty to visit -->

    <security:http security="none" pattern="/login/**" />
    <security:http security="none" pattern="/css/**" />
    <security:http security="none" pattern="/images/**" />
    <security:http security="none" pattern="/handler/**" />

    <security:http>
        <security:intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
        <security:form-login login-page="/login/"
            default-target-url="/login/successful_login.html"
            always-use-default-target="true" />
            <security:csrf disabled="true"/>
        <security:http-basic />
        <security:logout />
    </security:http>

    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider
            ref="protrackAuthenticationProvider" />
    </security:authentication-manager>


    <bean id="protrackAuthenticationProvider"
        class="com.example.security.ProtrackAuthenticationProvider">
    </bean>

    <bean id="authenticationFilter"
        class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
        <property name="authenticationManager" ref="authenticationManager" />
        <property name="filterProcessesUrl" value="/j_spring_security_check" />
    </bean>
</beans>

在web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
    version="3.0" xmlns="http://java.sun.com/xml/ns/javaee">

    <description>ProtrackEntities</description>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        /WEB-INF/ptentities-spring.xml
        /WEB-INF/ptentities-security.xml
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <!-- Servlets -->
    <servlet>
        <servlet-name>exportHandler</servlet-name>
        <servlet-class>com.myersinfosys.protrack.server.handlers.FileExportHandler</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>exportHandler</servlet-name>
        <url-pattern>/exportHandler</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>


    <servlet>
        <servlet-name>gwt-rpc</servlet-name>
        <servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>gwt-rpc</servlet-name>
        <url-pattern>/rpc/*</url-pattern>
    </servlet-mapping>

    <!-- Default page to serve -->
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

这里是请求错误:

远程地址:127.0.0.1:59322请求URL: http://127.0.0.1:59322/j_spring_security_check请求方法:POST状态代码:404未找到

Answer 1:

它看起来像你正在使用的Spring Security 4.0版

我刚刚从春季安全3.2.3升级到4.0.1,它看起来像的登录和注销处理程序的默认网址已分别从改变/ j_spring_security_check/登录/ j_spring_security_logout/注销

它也像你正在使用缺少的路径,通常是你的web应用程序的名称的应用程序上下文组成部分的URL。 它看起来更像是:

http://127.0.0.1:59322/YourWebapp/j_spring_security_check 

或日后Spring Security的版本:

http://127.0.0.1:59322/YourWebapp/login


文章来源: Authentication request to /j_spring_security_check 404 Error