2

私は最近 JBoss を使用して JSF アプリケーションで JAAS 認証を使用できるようにしました。異なるコンピューター/ブラウザーで同じユーザーでログインできることに気付いたとき、すべてが正常に機能しているように見えました。

ユーザーごとに複数のセッションを許可できないことを理解させるために不足している構成があるかどうか疑問に思っていました。

最初はとても簡単だと思っていましたが、後からそうではありませんでした。JBoss コミュニティ Web サイトとここで 2 日間読んでいます。

ここでは、standalone.xml の構成がどのように見えるかを示します。

<security-domain name="***Realm" cache-type="default">
                <authentication>
                    <login-module code="Database" flag="required">
                        <module-option name="dsJndiName" value="java:jboss/datasources/***DS"/>
                        <module-option name="principalsQuery" value="select password from users where email=?"/>
                        <module-option name="rolesQuery" value="select role_name, 'Roles' from users where email = ?"/>
                        <module-option name="hashAlgorithm" value="MD5"/>
                        <module-option name="hashEncoding" value="base64"/>
                    </login-module>
                </authentication>
            </security-domain>

関連する JAAS タグを web.xml に追加します。

<!-- Allowed Roles -->
<security-role>
    <role-name>SUPERADMIN</role-name>
</security-role>

<security-role>
    <role-name>ADMIN</role-name>
</security-role>

<security-role>
    <role-name>USER</role-name>
</security-role>
<!-- Protected Areas -->
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Only SUPER Admins</web-resource-name>
        <url-pattern>/protected/superadmin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>SUPERADMIN</role-name>
    </auth-constraint>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Only Admins and SuperAdmins</web-resource-name>
        <url-pattern>/protected/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>ADMIN</role-name>
        <role-name>SUPERADMIN</role-name>
    </auth-constraint>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Users and admins and SuperAdmins</web-resource-name>
        <url-pattern>/protected/user/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>SUPERADMIN</role-name>
        <role-name>ADMIN</role-name>
        <role-name>USER</role-name>
    </auth-constraint>
</security-constraint>

<!-- Validation By Form -->
<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.jsf</form-login-page>
        <form-error-page>/loginError.jsf</form-error-page>
    </form-login-config>
</login-config>
<!-- Filter to get the user name and work with it -->
<filter>
    <filter-name>LoginFilter</filter-name>
    <filter-class>br.com.icts.rybenapessoal.filters.LoginFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>LoginFilter</filter-name>
    <url-pattern>/protected/*</url-pattern>
</filter-mapping>

正しい方向を示してくれたり、この問題に関するドキュメントをもっと見つけてくれたりするのを助けてくれることに感謝します。

よろしく。アーサー

4

0 に答える 0