安全检查问题

Issue With JSecurity Check

我的 jboss-web.xml 如下所示。

<jboss-web>
    <security-domain>java:/jaas/test</security-domain>
    <valve>
        <class-name>com.test.WebFormAuthenticator</class-name>
        <param>
            <param-name>landingPage</param-name>
            <param-value>/index.html</param-value>
        </param>
    </valve>
    <context-root>mycontext</context-root>
</jboss-web>

我的 web.xml 有以下几行。

<login-config>
        <auth-method>FORM</auth-method>
        <realm-name>test</realm-name>
        <form-login-config>
            <form-login-page>/login.html</form-login-page>
            <form-error-page>/loginError.html</form-error-page>
        </form-login-config>
    </login-config>
<security-constraint>
        <web-resource-collection>
            <web-resource-name>My Application</web-resource-name>
            <url-pattern>/rest/*</url-pattern>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>*</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>My Application</web-resource-name>
            <url-pattern>/bower_components/*</url-pattern>
            <url-pattern>/scripts/*</url-pattern>
        </web-resource-collection>
    </security-constraint>

登录成功后index.html将url改为/src/assets/images/favicon.ico

我使用的 html 代码类似于

<form id="loginForm" method="POST" action="j_security_check">

知道为什么会这样吗?

您已保护应用程序服务器上的所有资源。在这种情况下,这意味着浏览器请求 "index.jsp" 并被重定向到登录页面。然后浏览器也尝试请求 favicon(您是否在表单登录页面中指定了它?),但由于它也受到保护,它再次被重定向到登录页面(检查您的浏览器调试工具)。

你要知道表单登录模块保存了最后一次请求的资源,这个资源是登录后被保护的重定向目标。在这种情况下,网站图标请求会覆盖对 "index.jsp" 的请求,因此您在登录后将被重定向到网站图标。

您需要从安全约束中排除您的静态资源。 Here is how to do it.

根据要求提供样品:

<security-constraint>
  <web-resource-collection>
    <web-resource-name>app</web-resource-name>
    <url-pattern>/src/assets/*</url-pattern>
  </web-resource-collection>
  <!-- OMIT auth-constraint -->
</security-constraint>