プライマリ・コンテンツに移動
Oracle® Fusion Middleware Oracle Entitlements Server開発者ガイド
11gリリース2 (11.1.2.3)
E67355-01
  ドキュメント・ライブラリへ移動
ライブラリ
製品リストへ移動
製品
目次へ移動
目次

前
 
 

8 標準タグ・ライブラリの使用方法

JavaServer Pages Standard Tag Library (JSTL)は、繰り返し発生するタスクをカプセル化したJavaServer Pages (JSP)要素で構成されます。カスタム・タグはタスクを実装するオブジェクトを含んだ再使用可能なJSPコンポーネントです。これらは、タグ・ライブラリで配布されます。Oracle Entitlements Serverは、認可APIをコールするカスタム・タグを含んでいます。開発者は、JSPでこれらのタグを使用して、セキュリティベースのWebアプリケーションを作成できます。

この章の次の各項では、カスタムOracle Entitlements Server JSPタグについて説明します。

8.1 タグ・ライブラリの使用方法

JSTLの使用時、JSP内で次のようにディレクティブを定義する必要があります。

<%@ taglib uri="http://www.oracle.com/oes/utils/tags" prefix="oes" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

さらに、oestags.jarをクラスパスに追加します。oestags.jarは、セキュリティ・モジュールのインストール・フォルダ内のOES_CLIENT_HOME/oessm/oestags/ディレクトリ、またはOracle Entitlements Server管理サーバーのインストール・フォルダ内のOES_ADMIN_HOME/oes/oestags/ディレクトリにあります。

8.2 機能タグの定義

これらのJSPタグは、Oracle Entitlements Serverの認可機能を取得します。次の各項ではこれらの機能タグについて説明します。

8.2.1 isAccessAllowedタグ

isAccessAllowedは、ユーザーに特定のリソースへのアクセスが認可されたかどうかを確認します。アクセスが許可された場合は、タグの本体が表示されます。許可されなかった場合は、本体がスキップされます。これはコオペラティブおよび条件タグです。trueまたはfalseと、義務の処理に使用可能な変数がJSPの本体へ返されます。


注意:

タグの本体によってJSPの内容を表示する場合は、then/elseタグを使用する必要があります。JSPの内容は、then/elseを使用しないかぎり、タグの本体で直接記述できません。

表8-1isAccessAllowedタグの定義を示しています。

表8-1 isAcessAllowedタグの定義

名前 詳細

リソース

説明: isAccessAllowedをコールするときに使用するリソースです。

必須

戻り型: 該当なし

resourceType

説明: isAccessAllowedをコールするときに使用するリソースのタイプです。設定しない場合、setSecurityContextによって設定されるグローバル・リソース・タイプが使用されます。

オプション

戻り型: 該当なし

action

説明: isAccessAllowedをコールするときに使用するアクションです。デフォルトのアクションは表示です。

オプション

戻り型: 該当なし

resultVar

説明: アクセスが許可されたかどうかを通知するために使用するスクリプト変数の名前です。

オプション

戻り型: ブール

resultVarScope

説明: resultVarの範囲です(page、request、sessionまたはapplication)。デフォルトの範囲はpageです。

オプション

戻り型: 該当なし

obligationVar

説明: isAccessAllowedコールから義務を返すために使用する変数の名前です。

オプション

戻り型: 義務のマップ。キーは義務の名前で、値は、属性名と値による属性のマップです。

obligationVarScope

説明: isAccessAllowedからの義務を含む変数の範囲です(page、request、sessionまたはapplication)。デフォルトの範囲はpageです。

オプション

戻り型: 該当なし


例8-1では、isAccessAllowedの使用方法を示します。

例8-1 isAccessAllowedタグの例

<%-- Set global attributes --%>
  <oes:setSecurityContext appId="TagLibraryApp" resourceType="image" 
     resourcePrefix="images/">
    <oes:attribute name="test_attr" value="good_job"/>
  </oes:setSecurityContext>
 
  <%!
      String resourceStr="private.jpg";
      String actionStr="read";
      String returnVar = "isAllowed";
  %>
 
<%-- Test for isAccessAllowed tag --%>
  <oes:isAccessAllowed  resource="<%=resourceStr %>" action="<%=actionStr %>" 
  resultVar="<%=returnVar %>" obligationVar="obligations">
    <oes:attribute name="test_attr_local" value="hard_work" />
    <oes:then>
         You have the permission to <%=actionStr %> the image <%=resourceStr %>. 
         <br/>
         <img src="images/private.jpg"  width="250" height="150" /> <br/>
          The obligations are: <br/>
            <c:forEach items="${obligations}" var="entry">
            <c:out value="${entry.key}" /> &nbsp;=&nbsp; <c:out 
               value="${entry.value}" /> <br/>
            </c:forEach>
    </oes:then>
    <oes:else>
         You have not the permission to <%=actionStr %> the image 
          <%=resourceStr %>. <br/>
    </oes:else>
  </oes:isAccessAllowed>
 
<%-- another way to use tag isAccessAllowed --%>
  <oes:isAccessAllowed  resource="<%=resourceStr %>" action="<%=actionStr %>" 
  resultVar="<%=returnVar %>" obligationVar="obligations">
    <oes:attribute name="test_attr_local" value="hard_work" />
  </oes:isAccessAllowed>
  <c:choose>
  <c:when test="${isAllowed}">You have the permission to <%=actionStr %> 
      the image <%=resourceStr %>. <br/>
      <img src="images/private.jpg"  width="250" height="150" />
      The obligations are: <br/>
       <c:forEach items="${obligations}" var="entry">
       <c:out value="${entry.key}" /> &nbsp;=&nbsp; 
       <c:out value="${entry.value}" /> <br/>
  </c:forEach>
  </c:when>
 <c:otherwise>
      You have not the permission to <%=actionStr %> the image 
         <%=resourceStr %>. <br/>
 </c:otherwise>
 </c:choose>

8.2.2 isAccessNotAllowedタグ

isAccessNotAllowedは、ユーザーに特定のリソースへのアクセスが認可されなかったかどうかを確認します。アクセスが許可されなかった場合は、タグの本体が表示されます。許可された場合は、本体がスキップされます。これはコオペラティブおよび条件タグです。trueまたはfalseと、後から義務の処理に使用可能な変数がJSPの本体へ返されます。


注意:

タグの本体によってJSPの内容を表示する場合は、then/elseタグを使用する必要があります。JSPの内容は、then/elseを使用しないかぎり、タグの本体で直接記述することはできません。

表8-2isAccessNotAllowedタグの定義を示しています。

表8-2 isAccessNotAllowedタグの定義

名前 詳細

リソース

説明: isAccessAllowedをコールするときに使用するリソースです。

必須

戻り型: 該当なし

resourceType

説明: isAccessAllowedをコールするときに使用するリソースのタイプです。設定しない場合、setSecurityContextによって設定されるグローバル・リソース・タイプが使用されます。

オプション

戻り型: 該当なし

action

説明: isAccessAllowedをコールするときに使用するアクションです。デフォルトのアクションは表示です。

オプション

戻り型: 該当なし

resultVar

説明: アクセスが許可されたかどうかを通知するために使用するスクリプト変数の名前です。

オプション

戻り型: ブール

resultVarScope

説明: resultVarの範囲です(page、request、sessionまたはapplication)。デフォルトの範囲はpageです。

オプション

戻り型: 該当なし

obligationVar

説明: isAccessAllowedコールから義務を返すために使用する変数の名前です。

オプション

戻り型: 義務のマップ。キーは義務の名前で、値は、属性名と値による属性のマップです。

obligationVarScope

説明: isAccessAllowedからの義務を含む変数の範囲です(page、request、sessionまたはapplication)。デフォルトの範囲はpageです。

オプション

戻り型: 該当なし


例8-2では、isAccessNotAllowedの使用方法を示します。

例8-2 isAccessNotAllowedタグの例

<%-- Test for isAccessNotAllowed tag --%>
     <oes:isAccessNotAllowed  resource="<%=resourceStr %>" 
      action="<%=actionStr %>" resultVar="isNotAllowed" 
      obligationVar="obligations_not">
     <oes:then>
       You have not the permission to <%=actionStr %> the image <%=resourceStr %>. 
       <br/>
       The obligations are: <br/>
       <c:forEach items="${obligations_not}" var="entry">
       <c:out value="${entry.key}" /> &nbsp;=&nbsp; 
       <c:out value="${entry.value}" /> <br/>
       </c:forEach>
      </oes:then>
      <oes:else>
        You have the permission to <%=actionStr %> the image <%=resourceStr %>. 
         <br/>
         <img src="images/private.jpg" width="250" height="150"/>
        The obligations are: <br/>
       <c:forEach items="${obligations_not}" var="entry">
       <c:out value="${entry.key}" /> &nbsp;=&nbsp; 
       <c:out value="${entry.value}" /> <br/>
      </c:forEach>
      </oes:else>
</oes:isAccessNotAllowed>
 
<%-- another way to use tag isAccessNotAllowed --%>
<oes:isAccessNotAllowed  resource="<%=resourceStr %>" 
    action="<%=actionStr %>" resultVar="isNotAllowed" 
    obligationVar="obligations_not" />
   <c:choose>
   <c:when test="${isNotAllowed}">You have not the permission to 
      <%=actionStr %> the image <%=resourceStr %>. <br/>
   </c:when>
   <c:otherwise>
    You have the permission to <%=actionStr %> the image <%=resourceStr %>. <br/>
    <img src="images/private.jpg"  width="250" height="150" />
    The obligations are: <br/>
   <c:forEach items="${obligations}" var="entry">
   <c:out value="${entry.key}" /> &nbsp;=&nbsp; 
   <c:out value="${entry.value}" /> <br/>
   </c:forEach>
   </c:otherwise>
   </c:choose>

8.2.3 getUserRolesタグ

getUserRolesは、特定のリソースとアクションに割り当てられたロールを取得します。これは、後からの処理に使用可能な変数をJSPに返すコオペラティブタグです。表8-3getUserRolesタグの定義を示しています。

表8-3 getUserRolesタグの定義

名前 詳細

リソース

説明: getUserRolesをコールするときに使用するリソース。

必須

戻り型: 該当なし

resourceType

説明: getUserRolesをコールするときに使用するリソースのタイプ。設定しない場合、setSecurityContextによって設定されるグローバル・リソース・タイプが使用されます。

オプション

戻り型: 該当なし

action

説明: getUserRolesをコールするときに使用するアクション。デフォルトのアクションは表示です。

オプション

戻り型: 該当なし

resultVar

説明: ユーザーのロールのリストを含めるように設定する変数の名前。

必須

戻り型: ロール名の文字列のリスト。

resultVarScope

説明: resultVarの範囲です(page、request、sessionまたはapplication)。デフォルトの範囲はpageです。

オプション

戻り型: 該当なし


例8-3では、getUserRolesの使用方法を示します。

例8-3 getUserRolesタグの例

<%-- Test for tag getUserRoles --%>
     <oes:setSecurityContext appId="TagLibraryApp" resourceType="jspfile" 
        resourcePrefix="">
     <oes:attribute name="myroleattr" value="its_my_role"/>
     </oes:setSecurityContext>
     <oes:getUserRoles  resource="protected/rolepolicy.jsp" action="write" 
        resultVar="rolenames" />
     <c:out value="Role names are : " />
     <c:forEach items="${rolenames}" var="rolename">
     <c:out value="${rolename}" /> <br>
     </c:forEach>

8.2.4 isUserInRoleタグ

isUserInRoleは、ユーザーが、特定のリソースとアクションの指定されたロールに割り当てられているかどうかをチェックします。これはコオペラティブおよび条件タグです。true(現在のユーザーに特定のロールがある場合)またはfalseと、後からの処理のために結果変数がJSPの本体に返されます。


注意:

タグの本体によってJSPの内容を表示する場合は、then/elseタグを使用する必要があります。JSPの内容は、then/elseを使用しないかぎり、タグの本体で直接記述することはできません。

表8-4isUserInRoleタグの定義を示しています。

表8-4 isUserInRoleタグの定義

名前 詳細

ロール

説明: ユーザーに対してチェックするロールの名前。

必須

戻り型: 該当なし

リソース

説明: ユーザーのロールをチェックするリソースの名前。

必須

戻り型: 該当なし

resourceType

説明: ユーザーのロールをチェックするリソースのタイプ。設定しない場合、setSecurityContextによって設定されるグローバル・リソース・タイプが使用されます。

オプション

戻り型: 該当なし

action

説明: ユーザーのロールをチェックするリソースのアクション。デフォルト値はviewになります。

オプション

戻り型: 該当なし

resultVar

説明: isUserInRoleからの結果を後から使用するために保持する変数。

オプション

戻り型: ブール

resultVarScope

説明: resultVarの範囲です(page、request、sessionまたはapplication)。デフォルトの範囲はpageです。

オプション

戻り型: 該当なし


例8-4では、isUserInRoleの使用方法を示します。

例8-4 isUserInRoleタグの例

<%-- Test for tag isUserInRole --%>
    <oes:isUserInRole role="tagrole1" resource="protected/rolepolicy.jsp" 
      action="write" resultVar="isUserInRole" resultVarScope="request">
      <oes:then>You are in the role "tagrole1".</oes:then>
      <oes:else>You are not in the role "tagrole1".</oes:else>
    </oes:isUserInRole>
 
 <%-- we can also use following scripts to test if the user is in the specific 
      role --%>
     <c:choose>
       <c:when test="${isUserInRole}">
           <iframe src="protected/rolepolicy.jsp?isUserInRole=<c:out 
            value='${isUserInRole}'/>" width="500" height="250" />
       </c:when>
       <c:otherwise>
          You are not in role "tagrole1", and can not see the content of 
          protected/rolepolicy.jsp
       </c:otherwise>
       </c:choose

8.3 アシスタント・タグの定義

アシスタント(非機能とも呼びます)タグは、ヘルパー・タグです。次の各項ではこれらのアシスタント・タグについて説明します。

8.3.1 setSecurityContextタグ

setSecurityContextは、指定されたページ範囲でデータ(アプリケーションID、リソース・タイプ、他のタグのリソース名の接頭辞など)を設定するコオペレーティブ・タグです。アプリケーションのコンテキストでグローバルに設定する必要がある属性は、このタグの本体でattributeタグ(8.3.2項「attributeタグ」を参照)を使用して設定できます。setSecurityContextに設定された属性は、認可コール要素に従って、アプリケーション・コンテキスト内に配置されます。表8-5setSecurityContextタグの定義を示しています。

表8-5 setSecurityContextタグの定義

名前 詳細

appId

説明: セキュリティ・コンテキストのappId。リソース属性を持つページ上の他のすべてのタグにランタイム・リソースを作成するために使用されます。

必須

戻り型: 該当なし

resourceType

説明: 他のすべての認可タグによって使用可能なグローバル・リソース・タイプ。

オプション

戻り型: 該当なし

resourcePrefix

説明: リソース名の接頭辞。1つのJSPにある大半のリソースの接頭辞が同じ場合、この属性を使用して各認可タグのリソース名を短縮できます。たとえば、/product/cat1/images/にある多数のイメージが認可ポリシーによって保護されている場合、接頭辞を/product/cat1/images/に設定して、リソース名をmobile.jpgのように単純.なイメージ名にできます。

オプション

戻り型: 該当なし


例8-5では、setSecurityContextの使用方法を示します。

例8-5 setSecurityContextタグの例

<%-- Set global attributes --%>
    <oes:setSecurityContext appId="TagLibraryApp" resourceType="image" 
      resourcePrefix="images/">
      <oes:attribute name="test_attr" value="good_job"/>
    </oes:setSecurityContext>

8.3.2 attributeタグ

attributeは、他のOracle Entitlements Server JSPタグによってOracle Entitlements Serverアプリケーション・コンテキストに追加の変数を渡すために使用できるタグです。それらの変数は、認可ポリシーに対して制約を書き込むために使用されます。表8-6attributeタグの定義を示しています。

表8-6 attributeタグの定義

名前 詳細

name

説明: アプリケーション・コンテキストで設定する属性の名前。

必須

戻り型: 該当なし

value

説明: アプリケーション・コンテキストで設定する値の名前。

必須

戻り型: 該当なし


例8-6では、attributeの使用方法を示します。

例8-6 attributeタグの例

<oes:attribute name="myroleattr" value="its_my_role"/>

8.3.3 then/elseタグ

then/elseは、条件タグ(isAccessAllowedisAccessNotAllowedisUserInRoleなど)の内容を表示するために使用します。条件タグの結果がtrueの場合、thenタグの内容が表示されます。falseの場合、elseタグの内容が表示されます。これらのタグは追加の定義がない単純なタグです。