4

ログインページにリダイレクトされるように、ウェルカムページをセキュリティチェックに保持した次のweb.xmlファイルがありますが、ユーザーログインなしでウェルカムページが表示されます。これは正しい方法ですか? ここに画像の説明を入力

<welcome-file-list>
        <welcome-file>/GISPages/welcome.xhtml</welcome-file> 
    </welcome-file-list>

    <resource-ref>
        <res-ref-name>jdbc/Gis_WebApp</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>


    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Protected Pages</web-resource-name>
            <url-pattern>/GISPages/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>registereduser</role-name>
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint>

    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>Live</realm-name>
        <form-login-config>
            <form-login-page>/login.xhtml</form-login-page>
            <form-error-page>/noauth.xhtml</form-error-page>
        </form-login-config>
    </login-config>

    <security-role>
        <role-name>registereduser</role-name>
    </security-role>

    <security-role>
        <role-name>admin</role-name>
    </security-role> 
4

1 に答える 1

1

セキュリティ上の制約により URL パターンが保護されますが、この場合、welcome ファイルの設定により、デフォルトの URL が http://:port/webcontext/ のように変更され、welcome.xhtml が表示されます。一方、定義された URL パターンに従って、保護された URL は http://:port/webcontext/GISPages/welcome.xhtml のような URL を持つ必要があります。URL パターンがアプリケーション サーバーと一致しなかったため、ページ コンテンツがレンダリングされます。

私にとってうまくいった唯一の解決策は、 prerender イベントで UserPrincipal をチェックすることです

<f:event type="preRenderComponent"
listener="#{bean.forwardToLoginIfNotLoggedIn}" /> 

UserPrincipal が null を返す場合、login.xhtml にリダイレクトします。

古いスレッドを開いて申し訳ありません。私は最近同様の問題に直面したため、これが役立つかもしれないと考えました。

于 2012-07-19T18:53:22.300 に答える