1

我的 Web 应用程序中发生的最奇怪的事情。这是<security-constraint>web.xml 的部分:

   <security-constraint>
        <web-resource-collection>
            <web-resource-name>Non-secure resources</web-resource-name>
            <url-pattern>/js/*</url-pattern>
            <url-pattern>/theme/*</url-pattern>
            <url-pattern>/login.jsp</url-pattern>
            <url-pattern>/logout.faces</url-pattern>
            <http-method>GET</http-method>
        </web-resource-collection>
    </security-constraint>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Secure resources</web-resource-name>
            <url-pattern>/faces/*</url-pattern>
            <url-pattern>/fragments/*</url-pattern>
            <url-pattern>/pages/*</url-pattern>
            <url-pattern>*.faces</url-pattern>
            <url-pattern>*.jsp</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>AllAuthenticated</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>map</realm-name>
        <form-login-config>
            <form-login-page>/login.jsp</form-login-page>
            <form-error-page>/loginError.jsp</form-error-page>
        </form-login-config>
    </login-config>
    <security-role>
        <role-name>AllAuthenticated</role-name>
    </security-role>

当用户通过 访问应用程序时http://<host-name>/<context-path>/,用户将被转发到登录页面,成功登录后一切正常。但是如果用户通过 访问应用程序http://<host-name>/<context-path>/login.jsp,在成功登录后,用户会收到 404 错误消息,并且浏览器中的 URL 是http://<host-name>/<context-path>/j_security_check

任何人都知道为什么会发生这种情况以及我该如何预防?

4

2 回答 2

0

您必须将这些行添加到您的 web.xml :

<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>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>

于 2013-05-03T16:46:53.763 回答
0

您应该在 web.xml 中添加此元素。

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/j_security_check</url-pattern>
</servlet-mapping>
于 2016-05-28T00:18:26.813 回答