Oracle® Fusion Middleware Oracle Entitlements Server開発者ガイド 11gリリース2 (11.1.2.3) E67355-01 |
|
前 |
JavaServer Pages Standard Tag Library (JSTL)は、繰り返し発生するタスクをカプセル化したJavaServer Pages (JSP)要素で構成されます。カスタム・タグはタスクを実装するオブジェクトを含んだ再使用可能なJSPコンポーネントです。これらは、タグ・ライブラリで配布されます。Oracle Entitlements Serverは、認可APIをコールするカスタム・タグを含んでいます。開発者は、JSPでこれらのタグを使用して、セキュリティベースのWebアプリケーションを作成できます。
この章の次の各項では、カスタムOracle Entitlements Server JSPタグについて説明します。
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/
ディレクトリにあります。
これらのJSPタグは、Oracle Entitlements Serverの認可機能を取得します。次の各項ではこれらの機能タグについて説明します。
isAccessAllowed
は、ユーザーに特定のリソースへのアクセスが認可されたかどうかを確認します。アクセスが許可された場合は、タグの本体が表示されます。許可されなかった場合は、本体がスキップされます。これはコオペラティブおよび条件タグです。trueまたはfalseと、義務の処理に使用可能な変数がJSPの本体へ返されます。
注意: タグの本体によってJSPの内容を表示する場合は、then/else タグを使用する必要があります。JSPの内容は、then/else を使用しないかぎり、タグの本体で直接記述できません。 |
表8-1はisAccessAllowed
タグの定義を示しています。
表8-1 isAcessAllowedタグの定義
名前 | 詳細 |
---|---|
リソース |
説明: 必須 戻り型: 該当なし |
resourceType |
説明: オプション 戻り型: 該当なし |
action |
説明: オプション 戻り型: 該当なし |
resultVar |
説明: アクセスが許可されたかどうかを通知するために使用するスクリプト変数の名前です。 オプション 戻り型: ブール |
resultVarScope |
説明: オプション 戻り型: 該当なし |
obligationVar |
説明: オプション 戻り型: 義務のマップ。キーは義務の名前で、値は、属性名と値による属性のマップです。 |
obligationVarScope |
説明: オプション 戻り型: 該当なし |
例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}" /> = <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}" /> = <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>
isAccessNotAllowed
は、ユーザーに特定のリソースへのアクセスが認可されなかったかどうかを確認します。アクセスが許可されなかった場合は、タグの本体が表示されます。許可された場合は、本体がスキップされます。これはコオペラティブおよび条件タグです。trueまたはfalseと、後から義務の処理に使用可能な変数がJSPの本体へ返されます。
注意: タグの本体によってJSPの内容を表示する場合は、then/else タグを使用する必要があります。JSPの内容は、then/else を使用しないかぎり、タグの本体で直接記述することはできません。 |
表8-2はisAccessNotAllowed
タグの定義を示しています。
表8-2 isAccessNotAllowedタグの定義
名前 | 詳細 |
---|---|
リソース |
説明: 必須 戻り型: 該当なし |
resourceType |
説明: オプション 戻り型: 該当なし |
action |
説明: オプション 戻り型: 該当なし |
resultVar |
説明: アクセスが許可されたかどうかを通知するために使用するスクリプト変数の名前です。 オプション 戻り型: ブール |
resultVarScope |
説明: オプション 戻り型: 該当なし |
obligationVar |
説明: オプション 戻り型: 義務のマップ。キーは義務の名前で、値は、属性名と値による属性のマップです。 |
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}" /> = <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}" /> = <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}" /> = <c:out value="${entry.value}" /> <br/> </c:forEach> </c:otherwise> </c:choose>
getUserRoles
は、特定のリソースとアクションに割り当てられたロールを取得します。これは、後からの処理に使用可能な変数をJSPに返すコオペラティブタグです。表8-3はgetUserRoles
タグの定義を示しています。
表8-3 getUserRolesタグの定義
名前 | 詳細 |
---|---|
リソース |
説明: 必須 戻り型: 該当なし |
resourceType |
説明: オプション 戻り型: 該当なし |
action |
説明: オプション 戻り型: 該当なし |
resultVar |
説明: ユーザーのロールのリストを含めるように設定する変数の名前。 必須 戻り型: ロール名の文字列のリスト。 |
resultVarScope |
説明: オプション 戻り型: 該当なし |
例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>
isUserInRole
は、ユーザーが、特定のリソースとアクションの指定されたロールに割り当てられているかどうかをチェックします。これはコオペラティブおよび条件タグです。true(現在のユーザーに特定のロールがある場合)またはfalseと、後からの処理のために結果変数がJSPの本体に返されます。
注意: タグの本体によってJSPの内容を表示する場合は、then/else タグを使用する必要があります。JSPの内容は、then/else を使用しないかぎり、タグの本体で直接記述することはできません。 |
表8-4はisUserInRole
タグの定義を示しています。
表8-4 isUserInRoleタグの定義
名前 | 詳細 |
---|---|
ロール |
説明: ユーザーに対してチェックするロールの名前。 必須 戻り型: 該当なし |
リソース |
説明: ユーザーのロールをチェックするリソースの名前。 必須 戻り型: 該当なし |
resourceType |
説明: ユーザーのロールをチェックするリソースのタイプ。設定しない場合、 オプション 戻り型: 該当なし |
action |
説明: ユーザーのロールをチェックするリソースのアクション。デフォルト値はviewになります。 オプション 戻り型: 該当なし |
resultVar |
説明: オプション 戻り型: ブール |
resultVarScope |
説明: オプション 戻り型: 該当なし |
例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
アシスタント(非機能とも呼びます)タグは、ヘルパー・タグです。次の各項ではこれらのアシスタント・タグについて説明します。
setSecurityContext
は、指定されたページ範囲でデータ(アプリケーションID、リソース・タイプ、他のタグのリソース名の接頭辞など)を設定するコオペレーティブ・タグです。アプリケーションのコンテキストでグローバルに設定する必要がある属性は、このタグの本体でattribute
タグ(8.3.2項「attributeタグ」を参照)を使用して設定できます。setSecurityContext
に設定された属性は、認可コール要素に従って、アプリケーション・コンテキスト内に配置されます。表8-5はsetSecurityContext
タグの定義を示しています。
表8-5 setSecurityContextタグの定義
名前 | 詳細 |
---|---|
appId |
説明: セキュリティ・コンテキストの 必須 戻り型: 該当なし |
resourceType |
説明: 他のすべての認可タグによって使用可能なグローバル・リソース・タイプ。 オプション 戻り型: 該当なし |
resourcePrefix |
説明: リソース名の接頭辞。1つのJSPにある大半のリソースの接頭辞が同じ場合、この属性を使用して各認可タグのリソース名を短縮できます。たとえば、 オプション 戻り型: 該当なし |
例8-5では、setSecurityContext
の使用方法を示します。
attribute
は、他のOracle Entitlements Server JSPタグによってOracle Entitlements Serverアプリケーション・コンテキストに追加の変数を渡すために使用できるタグです。それらの変数は、認可ポリシーに対して制約を書き込むために使用されます。表8-6はattribute
タグの定義を示しています。
表8-6 attributeタグの定義
名前 | 詳細 |
---|---|
name |
説明: アプリケーション・コンテキストで設定する属性の名前。 必須 戻り型: 該当なし |
value |
説明: アプリケーション・コンテキストで設定する値の名前。 必須 戻り型: 該当なし |
例8-6では、attribute
の使用方法を示します。
then
/else
は、条件タグ(isAccessAllowed
、isAccessNotAllowed
、isUserInRole
など)の内容を表示するために使用します。条件タグの結果がtrueの場合、then
タグの内容が表示されます。falseの場合、elseタグの内容が表示されます。これらのタグは追加の定義がない単純なタグです。