0

Glassfish 3.1.2 を使用してフォームベースの認証を実装したいと考えています。私の目標は、 /faces/user フォルダーのコンテンツをログイン後にのみ利用できるようにすることです。そのため、このフォルダーからページを取得すると、サインイン ページにリダイレクトされます。残念ながら、リダイレクトは機能しません。

web.xml で次の構成を使用します。

<?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0"
         xmlns="http://java.sun.com/xml/ns/javaee"
         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">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>

    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/faces/signin.xhtml</form-login-page>
            <form-error-page>/faces/error.xhtml</form-error-page>
        </form-login-config>
    </login-config>


    <security-role>
        <description/>
        <role-name>users</role-name>
    </security-role>


    <security-constraint>
        <display-name>Restricted to users</display-name>
        <web-resource-collection>
            <web-resource-name>Restricted Access</web-resource-name>
            <url-pattern>/faces/user/*</url-pattern>
            <http-method>DELETE</http-method>
            <http-method>PUT</http-method>
            <http-method>HEAD</http-method>
            <http-method>OPTIONS</http-method>
            <http-method>TRACE</http-method>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>users</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

</web-app>

問題は、直接http://domain.com/faces/user/dashboard.xhtml を開いてコンテンツを表示できることです。ログインフォームが表示されない!

私が変われば

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/faces/signin.xhtml</form-login-page>
        <form-error-page>/faces/error.xhtml</form-error-page>
    </form-login-config>
</login-config>

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>jdbc-realm</realm-name>
</login-config>

HTML 認証が表示され、正しい認証情報を提供しないとhttp://domain.com/faces/user/dashboard.xhtmlにアクセスできません。

セキュリティ制約の何が問題になっていますか?

どんな助けでも大歓迎です。前もって感謝します

4

2 に答える 2

1

私はそれを解決しました。問題は web.xml 構成自体にはありませんでした。

私は自分のプロジェクトでき​​れいな顔を使用しています。マッピングがフォームリダイレクトにブレーキをかけるようです。プロジェクトからかわいらしい顔を出すと、すべてが修正されます。

于 2013-06-27T11:26:09.403 に答える