ページの先頭行へ戻る
Interstage Application Server V13.0.0 GlassFish 設計・構築・運用ガイド
FUJITSU Software

5.4.1 ロールとロールベースのアクセス制限の設定

アプリケーション開発者はdeployment descriptorを編集し、ロールの設定およびロールによるアクセス制限の設定を行います。
詳細は、Jakarta EE、Servlet、EJBの仕様を参照してください。

ServletでFORM認証を使用する場合に、fileレルム「realm1」を使用し、認可に使用するロールが「role1」「role2」の場合のweb.xmlの記述例

<?xml version="1.0" encoding="UTF-8" ?>
<web-app 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"
           version="3.0">
    <security-constraint>
      <web-resource-collection>
        <web-resource-name>resource1</web-resource-name>
        <url-pattern>/index1.html</url-pattern>
      </web-resource-collection>
      <auth-constraint>
        <role-name>role1</role-name>                (1)
      </auth-constraint>
    </security-constraint>
    <security-constraint>
      <web-resource-collection>
        <web-resource-name>resource2</web-resource-name>
        <url-pattern>/index2.html</url-pattern>
      </web-resource-collection>
      <auth-constraint>
        <role-name>role2</role-name>                (2)
      </auth-constraint>
    </security-constraint>
    <login-config>
      <auth-method>FORM</auth-method>
      <realm-name>realm1</realm-name>
      <form-login-config>
        <form-login-page>/form.html</form-login-page>
        <form-error-page>/error.html</form-error-page>
      </form-login-config>
    </login-config>
    <security-role>
      <role-name>role1</role-name>                  (3)
    </security-role>
    <security-role>
      <role-name>role2</role-name>                  (4)
    </security-role>
</web-app>

(1)の値は(3)で、(2)の値は(4)で定義します。

ServletでFORM認証を使用する場合に、fileレルム「realm1」を使用し、ServletのAPIでユーザー「servletUser1」「servletUser2」に対して認可する場合のweb.xmlの記述例

<?xml version="1.0" encoding="UTF-8" ?>
<web-app 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"
           version="3.0">
    <servlet>
      <servlet-name>test</servlet-name>
      <servlet-class>sample.TestServlet</servlet-class>
      <security-role-ref>
        <role-name>servletUser1</role-name>
        <role-link>role1</role-link>                   (1)
      </security-role-ref>
      <security-role-ref>
        <role-name>servletUser2</role-name>
        <role-link>role2</role-link>                   (2)
      </security-role-ref>
    </servlet>
    <servlet-mapping>
       <servlet-name>test</servlet-name>
       <url-pattern>/test</url-pattern>
    </servlet-mapping>
    <security-constraint>
      <web-resource-collection>
        <web-resource-name>resource2</web-resource-name>
        <url-pattern>/test</url-pattern>
      </web-resource-collection>
      <auth-constraint>
        <role-name>role1</role-name>
        <role-name>role2</role-name>
      </auth-constraint>
    </security-constraint>
    <login-config>
      <auth-method>FORM</auth-method>
      <realm-name>realm1</realm-name>
      <form-login-config>
        <form-login-page>/form.html</form-login-page>
        <form-error-page>/error.html</form-error-page>
      </form-login-config>
    </login-config>
    <security-role>
      <role-name>role1</role-name>                    (3)
    </security-role>
    <security-role>
      <role-name>role2</role-name>                    (4)
    </security-role>
</web-app>

(1)の値は(3)で、(2)の値は(4)で定義します。

注意

realm-nameを指定しない場合、認証にデフォルトレルムが使用されます。