Java 无法使用spring security进行身份验证。输入凭据后

Java 无法使用spring security进行身份验证。输入凭据后,java,spring-mvc,spring-security,Java,Spring Mvc,Spring Security,我使用Spring security 4进行身份验证, 虽然我可以重定向到登录页面,但在此之后我无法进一步移动,无法找到此本地主机页面的错误 这是我的web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schem

我使用Spring security 4进行身份验证, 虽然我可以重定向到登录页面,但在此之后我无法进一步移动,无法找到此本地主机页面的错误

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
 id="WebApp_ID" version="3.1">
      <display-name>self-thin-client</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>

        <listener>
            <listener-class>
                org.springframework.web.context.ContextLoaderListener
            </listener-class>
        </listener>
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/security.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>/rs/self/*</url-pattern>
        </filter-mapping>

        <servlet>
            <servlet-name>dspature</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>dspature</servlet-name>
            <url-pattern>/rs/*</url-pattern>
        </servlet-mapping>

        <servlet>
            <servlet-name>Initializer</servlet-name>
            <servlet-class>com.store.Initializer</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    </web-app>

自精简客户端
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
org.springframework.web.context.ContextLoaderListener
上下文配置位置
/WEB-INF/security.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/rs/赛尔夫/*
版画
org.springframework.web.servlet.DispatcherServlet
1.
版画
/rs/*
初始值设定项
com.store.Initializer
1.
这是我的security.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-4.0.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-4.0.xsd">


        <!-- Spring MVC based authentication, login page etc.  -->
        <http>
            <intercept-url pattern="/**" access="hasRole('ROLE_ADMIN')"/>
            <form-login login-page="/rs/login" login-processing-url="/j_spring_security_check"
                        authentication-failure-url="/login" />
            <logout logout-success-url="/login"/>
        </http>

        <!-- Declared authentication manager -->
        <authentication-manager alias="authenticationManager">
            <authentication-provider ref="AuthenticationManager" />
        </authentication-manager>

        <!-- Bean implementing AuthenticationProvider of Spring Security -->
        <beans:bean id="AuthenticationManager" class="com.radix.server.login.AuthenticationManager">
        </beans:bean>

    </beans:beans>

这是我的html表单

 <form method="post" action="/j_spring_security_check" >
    <p>
      <span>Username:</span>
      <input type="text"  name= "j_username" >
    </p>
    <p>
      <span>Password:</span>
      <input type="password"  name= "j_password" >
    </p>
    <p>
      <input type="submit" value="submit">
    </p>
  </form>


用户名:

密码:


我认为问题可能在于url映射,但我无法找出它的错误所在,请帮助我解决它

web.xml
中更改此映射,方法如下:

<filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>
<form method="post" action="/your_app_context/j_spring_security_check" >
Security.xml:

<http pattern="/rs/login" security="none"/>
<http>
    <intercept-url pattern="/**" access="hasRole('ROLE_ADMIN')"/>
    <form-login login-page="/rs/login" login-processing-url="/j_spring_security_check"
                authentication-failure-url="/login" />
    <logout logout-success-url="/login"/>
    <csrf disabled="true"/>
</http>

注销成功url与登录表单url不匹配,但您似乎希望相同。如果需要这种方式,请将其更改为

编辑2: 在您最后的评论中,我认为剩下的最后一个问题是jsp表单操作。尝试以下方式更改操作:

<filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>
<form method="post" action="/your_app_context/j_spring_security_check" >


这对我来说毫无意义。如果您发布问题的第一个问题就是登录不起作用,那么登录如何停止工作?实际上,在阅读配置文件时,没有任何内容表明
/rs/self
/rs
实际上是您的上下文名称。。。如果它真的是应用程序上下文名称,我真的找不到您配置
安全性:http
元素及其内部
拦截url
的方式的意义。最后,如果
rs
rs/self
是您的应用程序上下文/战争名称,则它不应包含在
web.xml
security.xml
或任何控制器中使用的任何映射url中。我已将其硬编码为jsp表单login/rs/self/j_spring\u security\u check,如果我必须使用而不是,这将无法重定向到security.xml,因为筛选器应该是matchLet us。请从浏览器复制登录页面的url,该浏览器可以正常工作。您认为url如何与筛选器映射不匹配
/*
是应用程序上下文下所有url的通用匹配器