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

前
 
次
 

6 認可コールと決定の処理

Oracle Entitlements Serverには、コール元が特定のサブジェクトについて認可をリクエストし、返された決定を処理可能な、様々なアプリケーション・プログラミング・インタフェース(API)があります。

この章の内容は次のとおりです。

6.1 PEP APIの使用方法

AzAPIは、OpenAZプロジェクトで開発されたJava APIであり、認可の決定のリクエストと通信し、同じ相手にレスポンスするように設計されています。通信は、XACML使用に定義された認可決定のリクエストおよびレスポンスの標準に基づきます。さらに、通信では、認証エンジンがこれらの定義を使用してリクエストとレスポンスを作成する必要があります。AzAPIインタフェースは、ポリシー決定ポイント(PDP)でのすべてのXACML情報の提供と消費を可能にします。この情報は、認可リクエストを送信するとき、および認可レスポンスを受信するときに必要になります。


注意:

OpenAZプロジェクトの詳細は、http://openliberty.org/で説明されています。

Oracle Entitlements Server PEP APIは、Javaおよび.NETアプリケーションのいずれかを保護するために、AzAPIの最上位に作成します。PEP APIには、ポリシー決定ポイント(PEP)を作成するユーティリティ・クラスがあり、XACMLデータ・オブジェクトではなくネイティブのJavaまたは.NETデータ・オブジェクトを使用してAzAPIよりも簡単で拡張性のあるインタフェースを提供するように設計されています。図6-1は、AzAPI、PEP APIおよびOracle Entitlements Server間の関係を示しています。

図6-1 はオープンAZ APIおよびPEP API間の関係

図6-1の説明が続きます
「図6-1 オープンAZ APIおよびPEP API間の関係」の説明

次の項では、Oracle Entitlements ServerによってAzAPIを実装する方法を説明します。

6.1.1 PEP APIの理解

Oracle Entitlements Serverでは、org.openliberty.openaz.azapi.pepパッケージのJavaおよび.NETプロバイダ実装を提供しています。Java PEP APIプロバイダは、oracle.security.jps.openaz.pepにパッケージ化されています。すべての.NETプロバイダ・インタフェースは、Oes.Pep.Apiネームスペースで実装されています。


注意:

PEP APIは、プロキシ実装を通じてWebサービス・セキュリティ・モジュールをコールします。このプロキシ・レイヤーはフェイルオーバーとキャッシュを処理します。Oracle Entitlements Server Web Serviceセキュリティ・モジュールのインストールの詳細は、Oracle Fusion Middleware Oracle Identity and Access Managementインストレーション・ガイドを参照してください。

次の各項では、詳細を説明します。

6.1.1.1 PEP APIの使用

PEP API認可リクエストごとに、プロバイダ実装はOracle Entitlements Server認可エンジンを呼び出し、決定を返します。この実装は、ネイティブJavaまたは.NETオブジェクト(サブジェクト、リソース、アクションなど)の変換と、基礎となるセキュリティ・プラットフォームへのマッピングを処理する必要があります。プロバイダ実装は、決定時に認可を取得する次のアクションを実行します。このシーケンスは、指定されたターゲットにポリシーが定義済であると仮定しています。リクエストとレスポンスには、PDPと相互作用するための標準の書式があります。

  1. アクセスのリクエストはPEPで受信されます。

    リクエストには、サブジェクト、リソース、アクションおよび(オプションの)環境属性が含まれています。サブジェクトが保護されたリソースへアクセスするのを認可するためにコールできます。また、アクションや認可の決定について何が許可されるかを問い合せることができます。

  2. PEPはPEP APIをコールし、PEP APIは、認可のリクエストを(アクセスしているリソースのタイプに基づいて)ポリシー決定ポイント(PDP)に渡します。

    PEP APIは、認可リクエストのタイプをリソース・タイプに基づいて決定します。

  3. PDPは、該当する場合に、追加のサブジェクト、アクション、環境などの属性をリクエストします。

    属性は、ポリシー情報ポイント(PIP)からリクエストされます。PIPはリクエストされた属性を返し、情報がPDPに戻されます。

  4. PDPは、関連するポリシーに対してリクエストを評価します。

  5. PDPは(認可の決定を含む)レスポンスをPEPに返します。

    レスポンスは、1つ以上の結果で構成されます。(結果が複数になるのは、階層型リソースを評価した場合のみです。)結果にはそれぞれ、決定(許可、拒否)、ステータス情報(評価に失敗した理由など)および(オプションで)1つ以上の義務が含まれています(PEPには、アクセスを付与または拒否する前に、これらを処理する義務があります)。

  6. PEPは義務がある場合には遂行します。

  7. PEPは、リクエストが付与された場合に、リソースへのアクセスを許可し、そうでない場合にはアクセスを拒否します。

6.1.1.2 様々なPEP APIリクエストの使用方法

PEP APIを使用することで、様々な方法でアクセスの認可をリクエストできます。1つのサブジェクトまたは複数のサブジェクトをそれぞれ単一の認可コールまたは一括認可コールで認可できます。Oracle Entitlements Serverでは、認可の決定とアクションに関する問合せもサポートされています。表6-1「PEP API認可リクエスト・タイプの理解」で、これらのリクエスト・タイプの詳細を説明します。

表6-1 PEP API認可リクエスト・タイプについて

認可リクエスト・タイプ 入力パラメータ 戻り値

単一の認可リクエスト

(権限を使用する場合にのみサポートされます)

  • サブジェクトを表すオブジェクトまたは文字列

  • リソース/アクションのペアまたは単独のリソースおよびアクションを表すオブジェクト

  • 環境のコンテキストを表すオブジェクト(オプション)

  • 単一のリクエストに対して、レスポンス・オブジェクトと認可の決定および義務(オプション)を返します。

  • 例外をスローします。

一括認可リクエスト

  • 1つのサブジェクトを表すオブジェクトまたは文字列

  • 複数のリソース/アクションのペア、または1つのリソースを表すリスト1つと1つのアクションを表すリスト1つ

  • 環境のコンテキストを表すオブジェクト

  • 単一コールでの複数のリクエストに対して、複数の認可の決定を持つレスポンス・オブジェクトと義務(オプション)を返します。

  • 例外をスローします。

問合せは、指定されたリソース/アクション/サブジェクト/環境の関係に対する認可の決定のリストを返します。

  • 特定のタイプのすべてのリソースまたは、特定のリソースのすべての子の付与および拒否された決定を取得できます。

  • 許可の問合せによって、許可されたリソース・アクションの関係のリストが返されます。

  • 拒否の問合せによって、拒否されたリソース・アクションの関係のリストが返されます。

  • 詳細の問合せによって、各リソース・アクションの関係に対する認可の決定の全結果が返されます。

  • サブジェクトを表すオブジェクトまたは文字列

  • リソース/アクションのペアまたは単独のリソースおよびアクションを表すオブジェクト

  • 環境のコンテキストを表すオブジェクト

  • 認可情報が特定のリソースまたは特定のリソースと子に必要かどうかを指定する検索範囲(問合せリクエストAPIが1つの場合)

  • 宣言されたリソース/アクションのペアと同じ順序の認可の決定を含んだ結果のリストを返します。

  • 定義された検索範囲に応じて、特定のリソース、特定のタイプのすべてのリソースまたは特定のリソースのすべての子の認可の決定を返します。

  • 例外をスローします。


6.1.1.3 PEP APIサブジェクトの指定

保護されたリソースへのアクセスの認可をリクエストするサブジェクトは、文字列か、現在認証されているユーザーを表すオブジェクトを渡すことで定義できます。

  • アイデンティティ・ストアに定義されているサブジェクトの名前の値を表す文字列を渡すことができます(例、Josh Smith)

  • Javaまたは.NETオブジェクト(認可されたユーザーを表します)を渡すことができます。

詳細は、6.1.2.1項「Java PEP APIサブジェクトの取得」または6.1.3.1項「.NET PEP APIサブジェクトの取得」を参照してください。

6.1.1.4 認可リクエスト文字列の書式

PEP APIメソッドは、リクエストの範囲を定義する文字列を含みます。この範囲の文字列にリソース文字列を定義します。次の各項では、これらの範囲およびリソース文字列の書式設定方法を説明します。

6.1.1.4.1 PEP APIの範囲文字列の書式

範囲の入力文字列は、リソース、アクションおよび検索の範囲情報がカプセル化された、PDPポリシー専用のリソース表現です。これは次のように表現されます。

String scope = "resource = resourceString,actions = actionString1, 
actionString2, actionString3, searchscope = immediate/children";

この表現には次の規則があります。

  • resourceは必須で、resource文字列を範囲文字列内の最初に記述する必要があります。6.1.1.4.2項「PEP APIのリソース文字列の書式」を参照してください。

  • actionsはオプションです。存在する場合は、リクエストされたアクションのカンマ区切りリストを含み、必ず範囲の前に記述します。

  • searchscopeはオプションで、問合せリクエスト・タイプのみで使用します。値に、children(デフォルト値)またはimmediateを取ります。

    • 6.1.1.4.2項「PEP APIのリソース文字列の書式」の説明のとおり、値がchildrenの場合、resourceStringに渡せるのはアプリケーション識別子のみです。この場合PEP APIプロバイダは、指定されたリソース・オブジェクトとその子(存在する場合)を問い合せます。次の例では、範囲文字列がリソース文字列(とアプリケーション識別子)を含み、アクションと定義済検索範囲がないリソースを定義しています。したがって、この検索範囲はデフォルトのchildrenになります。

      String scope = "resource = PepQueryTest/resource_type_1/resource_1";
      
    • 6.1.1.4.2項「PEP APIのリソース文字列の書式」の説明のとおり、値がimmediateの場合、resourceStringには完全修飾識別子を渡す必要があります。この場合PEP APIプロバイダは、指定されたリソース・オブジェクトを問い合せます。次に例を示します。

      String scope = "resource = PepQueryTest/resource_type_1/resource_1, 
      actions = action1,action2, searchscope=immediate";

次の範囲文字列は、階層型リソースを定義しています。

String scope= "resource = PepQueryTest/hierarchical_type//res1/res2/res3, 
searchscope= children";
6.1.1.4.2 PEP APIのリソース文字列の書式

文字列は、区切り文字のフォワード・スラッシュ(/)を使用して、appId/resourceType/resourceNameの書式で記述する必要があります。appIdresourceTypeを空またはNULLにすることはできません。resourceNameは、問合せリクエストに対して空にすることはできますが、それ以外のすべてのリクエストに対しては値を指定する必要があります。

文字列の書式設定時、resourceNameで文字列を使用する場合には区切り文字をエスケープする必要はありません。たとえば、名前が/res1/res2/res3の階層型リソースがある場合、PEP APIに渡されるリソース文字列はappId/ResType//res1/res2/res3となります。ただし、appIdまたはresourceTypeで使用する場合は、区切り文字をエスケープする必要があります。これらの場合、文字列に3つ以上の区切り文字があると、無効と見なされます。


注意:

myapp/computer\laptop/res1のリソース文字列は、\記号が/\のいずれも表さないため無効です。

次の例のリストは、これらのルールを示しています。

  • myapp/computer\/laptop/res1は、myappアプリケーション内のres1という名前のリソースで、リソース・タイプがcomputer/laptopであることを意味します。

  • myapp/computer\\laptop/res1は、myappアプリケーション内のres1という名前のリソースで、リソース・タイプがcomputer\laptopであることを意味します。

  • myapp/computer/laptop/res1は、myappアプリケーション内のlaptop/res1という名前のリソースで、リソース・タイプがcomputerであることを意味します。

  • myapp/computer/laptop\/res1は、myappアプリケーション内のlaptop\/res1という名前のリソースで、リソース・タイプがcomputerであることを意味します。

  • myapp/hierarchialResource\\res1\res2\res3は、myappアプリケーション内の\res1\res2\res3という名前のリソースで、リソース・タイプがhierarchicalResourceであることを意味します。


注意:

Java内の文字列では、\記号自体はエスケープする必要があります。前述の3つの文字列は、Javaでは次のようになります。
  • myapp/computer\\/laptop/mybox

  • myapp/computer\\\\laptop/mybox

  • myapp/computer\\laptop/mybox


6.1.1.5 問合せを使用した認証情報の取得

問合せの操作は、PEP APIを使用して開始できます。問合せでは、次のオブジェクトを入力パラメータとして取り、対応する結果を返します。

  • アプリケーションとリソース・タイプ - 結果が、特定のアプリケーションのリソース・タイプの全リソース・インスタンスに返されます。このコールは階層型と非階層型の両方のリソース・タイプに対して有効です。

  • アプリケーション、リソース・タイプおよびリソース - 結果が、特定のアプリケーションのリソース・タイプの特定のリソース・インスタンスに返されます。リソース・タイプが階層の場合は、結果が該当するリソースの子にも同様に返されます。

表6-2は、2種類の問合せについて説明しています。問合せのそれぞれのタイプは、階層型と非階層型の両方のリソース・インスタンスで実行できます。

表6-2 PEP API問合せのタイプ

問合せのタイプ 戻り値 メソッド

(定義された範囲に応じて)リソース、子または両方に許可/拒否のアクションを返します。

指定されたサブジェクトの権限を含んだPepRequestを返します。

  • searchscope = "immediate"の場合、PepApiプロバイダは指定されたリソース・オブジェクトを問い合せます。

  • searchscope = "children"の場合、PepApiプロバイダは指定されたリソース・オブジェクトとその子(存在する場合)を問い合せます。

public PepRequest newQueryPepRequest(Object subjectObj, Object environmentObj, String scope, PepRequestQueryType queryType) throws PepException

リソースとその子についてのすべての認可結果を返します。

リソースとその子についてのすべての認可結果を返します。特定の環境パラメータを持つ現在のサブジェクトへのアクセスを許可または拒否されたリソース-アクションを取得するために使用できるPepRequestを返します。

public PepRequest newQueryPepRequest(Object subjectObj, Object resourceObj, Object actionObj, Object environmentObj, PepResponseType responseType, boolean resourceActionOnly) throws PepException


6.1.2 Java用PEP APIの使用方法

次の項では、Java用PEP APIの使用方法について説明します。

6.1.2.1 Java PEP APIサブジェクトの取得

この項では、Java用PEP APIで認可リクエストの認可サブジェクトを取得する方法を示したサンプル・コードを説明します。Java Authentication and Authorization Service (JAAS)のサブジェクトには、newPepRequest()メソッドをコールすることをお薦めします。


注意:

文字列のサブジェクトは、JAASサブジェクトに変換されます。

次の例の範囲とリソース文字列の指定方法は、6.1.1.4項「認可リクエスト文字列の書式」を参照してください。

例6-1は、ログイン・サービスで認可済ユーザーを取得し、1つのPEP API認可リクエストに対する認可済サブジェクトの使用方法を示しています。このコードは、指定されたリソースとアクションに基づいて認可の決定を返します。(一括および問合せリクエストは、同様の方法で作成および使用します。)

例6-1 Java PEP APIリクエストでの認可済サブジェクトの使用方法

ServiceLocator locator = JpsServiceLocator.getServiceLocator();
LoginService loginService = locator.lookup(LoginService.class);
CallbackHandler cbh = new MyCallbackHandler("name", "password".toCharArray());
 
LoginContext ctx = loginService.getLoginContext(new Subject(), cbh);
ctx.login();
Subject s = ctx.getSubject();
 
String action = "read";
String resourceString = "MyApplication/MyResourceType/MyResource";
Map<String, String> env = new HashMap<String, String>();
env.put("myAttr", "Hello");
 
//Alternately, a String subject like "tom" can be used.
String action = "read";
String resourceString = "MyApplication/MyResourceType/MyResource";
Map<String, String> env = new HashMap<String, String>();
env.put("myAttr", "Hello");
 
PepRequest pepRequest =       
PepRequestFactoryImpl.getPepRequestFactory().newPepRequest
  (s, action, resourceString, env);
 
PepResponse response = pepRequest.decide();
System.out.println("result: " + response.allowed());
Map<String, Obligation> obligations = response.getObligations();
for (String name : obligations.keySet()) 
  {
   System.out.print("obligation: name = " + name + ", values = " + 
   obligations.get(name).getStringValues());
  }

例6-2は、Java Enterprise Edition (JEE)の認証後に、PEP APIで使用するWebLogic Serverサブジェクトの取得方法を示しています。

例6-2 Java PEP APIリクエストでのWebLogic Serverサブジェクトの使用方法

import weblogic.security.Security;
 
...
 
Subject s = Security.getCurrentSubject();
 
String action = "read";
String resourceString = "MyApplication/MyResourceType/MyResource";
Map<String, String> env = new HashMap<String, String>();
env.put("myAttr", "Hello");
 
PepResponse response = 
PepRequestFactoryImpl.getPepRequestFactory().newPepRequest
(s, action, resourceString, env).decide(); System.out.println("result: " + response.allowed()); Map<String, Obligation> obligations = response.getObligations(); for (String name : obligations.keySet()) { System.out.print("obligation: name = " + name + ", values = "
+ obligations.get(name).getStringValues()); }

例6-3は、Java Enterprise Edition (JEE)の認証後に、PEP APIで使用するWebsphere Application Serverサブジェクトの取得方法を示しています。

例6-3 Java PEP APIリクエストでのWebsphere Application Serverサブジェクトの使用方法

import com.ibm.websphere.security.auth.WSSubject;
 
...
Subject s = WSSubject.getCallerSubject();
 
String action = "read";
String resourceString = "MyApplication/MyResourceType/MyResource";
Map<String, String> env = new HashMap<String, String>();
env.put("myAttr", "Hello");
 
PepResponse response = PepRequestFactoryImpl.getPepRequestFactory().
  newPepRequest(s, action, resourceString, env).decide();
System.out.println("result: " + response.allowed());
Map<String, Obligation> obligations = response.getObligations();
for (String name : obligations.keySet()) 
  {
   System.out.print("obligation: name = " + name + ", values = 
     " + obligations.get(name).getStringValues());
  }

例6-4は、Java Enterprise Edition (JEE)の認証後に、PEP APIで使用するWebsphere Application Serverサブジェクトの取得方法を示しています。

例6-4 Java PEP APIリクエストでのOPSSサブジェクトの使用方法

import oracle.security.jps.util.SubjectUtil;
 
...
 
// Assuming the OPSS filter/interceptor were configured, 
// SubjectUtil.getCurrentSubject would return the subject 
//on JRF {WAS OR WLS}
Subject s = SubjectUtil.getCurrentSubject ();
 
String action = "read";
String resourceString = "MyApplication/MyResourceType/MyResource";
Map<String, String> env = new HashMap<String, String>();
env.put("myAttr", "Hello");
 
PepResponse response = PepRequestFactoryImpl.getPepRequestFactory().
  newPepRequest(s, action, resourceString, env).decide();
System.out.println("result: " + response.allowed());
Map<String, Obligation> obligations = response.getObligations();
for (String name : obligations.keySet()) 
  {
   System.out.print("obligation: name = " + name + ", values = 
     " + obligations.get(name).getStringValues());
  }

6.1.2.2 単純なJava PEP API認可リクエストの実行

Oracle Entitlements Serverでは2種類の問合せリクエストが提供されています。特定のリソース(とその子)のすべてのアクションのリストをリクエストするか、特定のリソース(とその子)のすべての認可の結果をリクエストできます。両方の種類の問合せでは、特定のリソース・タイプのすべてのインスタンス化されたリソースの結果を取得します。例6-5は、特定のリソースに対する問合せリクエストです。検索範囲がimmediateに定義されていることに注意してください。範囲とリソース文字列の指定方法は、6.1.1.4項「認可リクエスト文字列の書式」を参照してください。

例6-5 リソースに対するJava PEP API認可のリクエスト

...
String scope = "resource = PepQueryTest/resource_type_1/resource_1, 
  actions = action1, searchscope=immediate";
PepRequest req = PepRequestFactoryImpl.getPepRequestFactory().
  newQueryPepRequest(subject, env, scope, 
  PepRequestQueryType.RETURN_ONLY_ALLOWED_RESULTS);
 
PepResponse resp = req.decide();
 
//List of RuntimeAction objects
List actions = (List) resp.getAction();
RuntimeResource resource = (RuntimeResource) resp.getResource();

6.1.2.3 Java PEP API義務の処理

義務にはアクセスの決定と一緒にコール側アプリケーションに返される追加の情報を指定します。PEP APIレスポンスのそれぞれの義務には、Map<String, String>のタイプのマップがあります。(String値を囲む二重引用符はありません。)次の例の範囲とリソース文字列の指定方法は、6.1.1.4項「認可リクエスト文字列の書式」を参照してください。

例6-6は、義務もリクエストする認可リクエストです。

例6-6 PEP APIリクエストおよび解析レスポンスの実行

Subject s = ...; // a Jps subject (with app roles inside)
String action = "read";
String resourceString = "MyApplication/MyResourceType/MyResource";
Map<String, String> env = new HashMap<String, String>();
env.put("myAttr", "Hello");
 
PepResponse response = 
  PepRequestFactoryImpl.getPepRequestFactory().newPepRequest
  (s,action,resourceString,env).decide();
System.out.println("result: " + response.allowed());
Map<String, Obligation> obligations = response.getObligations();
for (String name : obligations.keySet())
{         System.out.print("obligation: name = " + name + ", values = " + obligations.get(name).getStringValues());         }

例6-7は、義務出力の例です。この場合も、文字列を囲む二重引用符はありません。

例6-7 例6-6から返された義務

result: true
obligation: name = MyObligation, values =
{attr1=18, attr2=World, time=08:59:59, attr_date=12/29/2010}

6.1.2.4 Java PEP API一括認可リクエストの実行

例6-8は、認可を一括でリクエストするように記述されたサンプル・コードです。2つのリクエストをカプセル化しています。

例6-8 Java PEP APIによる一括認可のリクエスト

public void testBulkRequest() throws Exception {
        Map<String, String> env = new HashMap<String, String>();
        env.put("dynamic_attr", "dynamic_attr_value");
        String resourceString = 
            MY_APPLICATION + "/" + MY_RESOURCE_TYPE + "/" + MY_RESOURCE;
        String wrongAction = "wrong_action";
        PepResponse resp = pepRequestFactory.newBulkPepRequest(
                subject,
                Arrays.asList(new Object[]{MY_ACTION, wrongAction}),
                Arrays.asList(new Object[]{resourceString, resourceString}),
                env).decide();
 
//
// response corresponding to first authorization decision
//
 
        assertTrue(resp.next());
 
        assertTrue("resp.allowed() is expected to be true!! ", resp.allowed());
        assertSame(MY_ACTION, resp.getAction());
        assertSame(RESOURCE_STRING, resp.getResource());
 
//
// response corresponding to second authorization decision
//
 
        assertTrue(resp.next());
 
        assertFalse("resp.allowed() is expected to be false!! ", resp.allowed());
        assertSame(wrongAction, resp.getAction());
        assertSame(RESOURCE_STRING, resp.getResource());
 
//
// call next() again..
//
        assertFalse(resp.next());
    }

これらの例の範囲とリソース文字列の指定方法は、6.1.1.4項「認可リクエスト文字列の書式」を参照してください。

6.1.2.5 Java PEP API問合せリクエストの実行

Java用PEP APIにはnewQueryPepRequest()メソッドが含まれており、認可リクエストによって適用されるリソースの範囲とアクションに関する情報を取得できます。範囲は、メソッドに渡されるサブジェクトと環境オブジェクトに基づきます。(範囲とリソース文字列の指定方法は、6.1.1.4項「認可リクエスト文字列の書式」を参照してください。)返される情報は、PepRequestQueryTypeがどのように定義されているかによります。次のいずれかの値を取得します。

  • RETURN_ONLY_ALLOWED_RESULTSによって、定義された範囲内で許可されるリソース・アクションのペアのリストが返されます。

  • RETURN_ONLY_DENIED_RESULTSによって、定義された範囲内で拒否されるリソース・アクションのペアのリストが返されます。

  • VERBOSEによって、定義済の範囲内からリクエストされたリソース・アクションのペアごとにすべての結果が返されます。

例6-9は、PepRequestQueryType列挙の値の1つとして問合せタイプを定義可能なシグネチャを示しています。

例6-9 Java PEP APIの問合せタイプの定義

public PepRequest newQueryPepRequest
    (object subjectObj,
    Object environmentObj
    String scope
    PepRequestQueryType queryType)

例6-10は、新しいPepResponseType列挙の値の1つとして、レスポンス・タイプを定義可能なシグネチャを示しています。resourceActionOnlyは、リソースとアクション(問合せの適用先)のアイデンティティのみを表す情報がレスポンスで返されるか、完全なレスポンス(義務を含む)が返されるかを示すブールです。

例6-10 新しいJava PEP APIのリソース・タイプの定義

public PepRequest newQueryPepRequest
   (java.lang.Object subjectObj,
    java.lang.Object resourceObj, 
    java.lang.Object actionObj, 
    java.lang.Object environmentObj, 
    org.openliberty.openaz.azapi.constants.PepResponseType responseType,
    boolean resourceActionOnly)

例6-11は、特定のリソースとその子に対して許可および拒否されたすべてのアクションをリクエストする問合せです。検索範囲はchildrenに定義されていることに注意してください。

例6-11 Java PEP APIによるリソースおよび子への詳細問合せ

...
String scope = "resource=PepQueryTest/Hierarchical/\\/res1";
 
PepRequest req = PepRequestFactoryImpl.getPepRequestFactory
   (subject, env, scope, PepRequestQueryType.VERBOSE);
PepResponse resp = req.decide();
 
ArrayList arrayList;
List grantedActions;
List deniedActions;
 
int i = 0;

//there can be more than 1 result when searchscope="children"
while (resp.next()) {
  RuntimeResource res = (RuntimeResource) resp.getResource();
 
//both granted actions and denied actions are returned for PepRequestQueryType.VERBOSE
//PepResponse.getAction() returns an ArrayList where ArrayList.get(0) returns list of granted actions;
//it returns an ArrayList where ArrayList.get(1) returns list of denied actions;
 
arrayList = (ArrayList) resp.getAction();
grantedActions = null;
deniedActions = null;
 
if (arrayList != null) {
  grantedActions = (List) arrayList.get(0);
  deniedActions = (List) arrayList.get(1);
  }
String resourceName = res.getResourceName();
}

例6-12は、immediate検索範囲で許可された結果のみを返す問合せコードです。

例6-12 Java PEP APIによるimmediateの検索範囲の問合せリクエスト

String scope = "resource=PepQueryTest/resource_type_1/resource_1, 
  actions=action1, searchscope=immediate";
PepRequest req = 
  PepRequestFactoryImpl.getPepRequestFactory().newQueryPepRequest
  (subject, env, scope, PepRequestQueryType.RETURN_ONLY_ALLOWED_RESULTS);
PepResponse resp = req.decide();
 
//Getting list of RuntimeAction objects
List actions = (List) resp.getAction();
RuntimeResource resource = (RuntimeResource) resp.getResource();

例6-13は、children検索範囲での許可および拒否の結果を返す問合せコードです。

例6-13 Java PEP APIによるchildrenの検索範囲の問合せリクエスト

String scope = "resource=PepQueryTest/Hierarchical/\\/res1";
PepRequest req = PepRequestFactoryImpl.getPepRequestFactory
  (subject, env, scope, PepRequestQueryType.VERBOSE);
PepResponse resp = req.decide();
 
ArrayList arrayList;
List grantedActions;
List deniedActions;
 
int i = 0;

//there can be more than 1 result when searchscope="children"
while (resp.next()) {
RuntimeResource res = (RuntimeResource) resp.getResource();
 
//both granted actions and denied actions are returned for //PepRequestQueryType.VERBOSE  
//PepResponse.getAction() returns an ArrayList where ArrayList.get(0) 
//returns list of granted actions;
//it returns an ArrayList where ArrayList.get(1) returns list of denied actions;
 
arrayList = (ArrayList) resp.getAction();
grantedActions = null;
deniedActions = null;
 
if (arrayList != null) {
   grantedActions = (List) arrayList.get(0);
   deniedActions = (List) arrayList.get(1);
}
 String resourceName = res.getResourceName();
}

例6-14は、義務とともに許可および拒否の結果のみを返す問合せコードです。

例6-14 Java PEP APIによる許可/拒否の結果と義務の問合せリクエスト

String resourceString = "MyApplication/MyResourceType/MyResource";
String action = "read";
PepRequest req = pepRequestFactory.newQueryPepRequest(subject, 
  resourceString, action, null, PepResponseType.ALL_RESULTS, true);
 
PepResponse resp = req.decide();
  while (resp.next()) {
//print authorization results for each resource and action.
System.out.println("For resource " + resp.getResource() + "  and action" +
  resp.getAction() + " authorization allowed = " + resp.allowed());

//check out obligations
Map<String, Obligation> obligations = resp.getObligations();
Set<String> obIds = obligations.keySet();
  for (String obId : obIds) {
Obligation obligation = obligations.get(obId);
Map<String, String> strValus = obligation.getStringValues();
}
}

6.1.2.6 Java PEP APIの構成

Java PEP APIを使用するには、アイデンティティ・ストア、ポリシー・ストア、ポリシー配布サービスおよびユーザー・アサーション・ログイン・モジュールをjps-config.xml構成ファイルで定義する必要があります。


注意:

jps-config.xml構成ファイルの詳細は、『Oracle Fusion Middlewareアプリケーション・セキュリティ・ガイド』を参照してください。Oracle Entitlements Server固有のパラメータは、『Oracle Fusion Middleware Oracle Entitlements Server管理者ガイド』を参照してください。

例6-15は、参考用に転載したjps-config.xmlの一部です。

例6-15 jps-config.xmlのサンプル・ファイル

...
<serviceInstance name="idstore.ldap" provider="idstore.ldap.provider">
 <description>LDAP Identity Store Service Instance</description>
 <property name="idstore.config.provider" 
  value="oracle.security.jps.wls.internal.idstore.WlsLdapIdStoreConfigProvider"/>
 <property name="CONNECTION_POOL_CLASS" 
  value="oracle.security.idm.providers.stdldap.JNDIPool"/>
</serviceInstance>
<serviceInstance name="idstore.loginmodule" provider="jaas.login.provider">
 <description>Identity Store Login Module</description>
 <property name="loginModuleClassName" 
  value="oracle.security.jps.internal.jaas.module.idstore.IdStoreLoginModule"/>
 <property name="jaas.login.controlFlag" value="REQUIRED"/>
</serviceInstance>
<serviceInstance name="pdp.service" provider="pdp.service.provider">
 <description>Runtime PDP service instance</description>
 <property name="oracle.security.jps.runtime.pd.client.sm_name" value="mixedsm"/>
 <property name="oracle.security.jps.runtime.pd.client.localpolicy.work_folder" 
  value="/ade/diazhao_entsec_
  2/oracle/work/utp/buildout/functional/platsec/tempdir/mixedpd-work"/>
 <property name="oracle.security.jps.pdp.AuthorizationDecisionCacheEnabled" 
  value="true"/>
 <property 
  name="oracle.security.jps.pdp.AuthorizationDecisionCacheEvictionCapacity" 
  value="500"/>
 <property 
  name="oracle.security.jps.pdp.AuthorizationDecisionCacheEvictionPercentage" 
  value="10"/>
 <property name="oracle.security.jps.pdp.AuthorizationDecisionCacheTTL" 
  value="60"/>
 <property name="oracle.security.jps.pd.client.PollingTimerEnabled" value="true"/>
 <property name="oracle.security.jps.pd.client.PollingTimerInterval" value="10"/>
 <property name="oracle.security.jps.ldap.cache.refresh.interval" value="10000"/>
 <property name="oracle.security.jps.runtime.pd.client.policyDistributionMode" 
  value="mixed"/>
</serviceInstance>
<serviceInstance name="policystore.db" provider="policystore.provider">
 <property name="policystore.type" value="DB_ORACLE"/>
 <property name="oracle.security.jps.farm.name" 
  value="cn=testfarm_diazhao_entsec_2"/>
 <property name="server.type" value="DB_ORACLE"/>
 <property name="oracle.security.jps.ldap.root.name" value="cn=jpsroot"/>
 <property name="datasource.jndi.name" value="platsec_test_ds"/>
</serviceInstance>
<serviceInstance name="user.assertion.loginmodule" provider="jaas.login.provider">
 <description>User Assertion Login Module</description>
 <property name="loginModuleClassName" value="oracle.
  security.jps.internal.jaas.module.assertion.JpsUserAssertionLoginModule"/>
 <property name="jaas.login.controlFlag" value="REQUIRED"/>
</serviceInstance>
...
<jpsContexts default="default">
 <jpsContext name="default">
  <serviceInstanceRef ref="credstore.db"/>
  <serviceInstanceRef ref="keystore.db"/>
  <serviceInstanceRef ref="policystore.db"/>
  <serviceInstanceRef ref="audit.db"/>
  <serviceInstanceRef ref="trust"/>
  <serviceInstanceRef ref="pdp.service"/>
  <serviceInstanceRef ref="attribute"/>
  <serviceInstanceRef ref="idstore.ldap"/>
 </jpsContext>
</jpsContexts>

6.1.3 .NET用PEP APIの使用方法

.NET用PEP APIは、Oracle Entitlements Serverの認可をMicrosoft .NETテクノロジを使用して構築されたアプリケーションに統合するために使用します。.NETアプリケーションによって.NET用PEP APIがコールされ、認可の決定が取得されます。(.NET用PEP APIは、プロキシ実装(フェイルオーバーとキャッシングを処理)経由で、Webサービス・セキュリティ・モジュールで提供されている認可Webサービスを呼び出します。)

認可に.NETセキュリティ・モジュールを呼び出すには、適用可能なリソースとアクションのペアを表す、アクションオブジェクトのリストと対応するリソース・オブジェクトのリストを提供するIPepRequestを作成します。リソースとアクションの各ペアに対する認可の決定がIPepRequest.decide()の呼び出し時に返されます。次の項では、.NET用PEP APIアプリケーションの使用方法について説明します。

6.1.3.1 .NET PEP APIサブジェクトの取得

IPepRequestコールのサブジェクトは次のいずれかの操作で定義できます。

  • ユーザー名を文字列で渡します。

  • System.Security.Principal.IIdentityユーザー・オブジェクトを渡します。このオブジェクトは.NET標準オブジェクトであり、Oracle Entitlements ServerがサポートするWindowsオペレーティング・システムによる認証を表します。次のようにIIdentityユーザー・オブジェクトを取得します。

    • スタンドアロン・アプリケーションの場合は次の記述を使用します。

      IIdentity iIdentity = WindowsIdentity.GetCurrent();
      
    • Webアプリケーションの場合は次の記述を使用します。

      IIdentity iIdentity = (IIdentity)(HttpContext.Current.User.Identity);
      
  • .NETアプリケーションにカスタム認証がある場合、UserPricipalクラスを使用して、ユーザー情報を設定しUserPrincipalオブジェクトを渡します。

6.1.3.2 単純なNET PEP API認可リクエストの実行

Oracle Entitlements Serverでは、認可(単一と一括)および問合せのリクエストを提供しています。特定のリソース(とその子)のすべてのアクションのリストをリクエストするか、特定のリソース(とその子)のすべての認可の結果を問い合せることができます。両方の種類の問合せは、特定のリソース・タイプのすべてのインスタンス化されたリソースの結果を取得するために使用することもできます。

渡される認可情報には、認証済サブジェクト(例、iIdentity)、アクションを表すオブジェクトのリスト[例、String (read)]、リソースを表すオブジェクトのリスト(例、applicationId/resourcetype/resource)および環境を表すオブジェクト(ハッシュテーブルの形式で渡される情報を含む)があります。例6-16「リソースに対する.NET PEP API認可のリクエスト」での範囲とリソース文字列の指定方法は、6.1.1.4項「認可リクエスト文字列の書式」を参照してください。このコードには、6.1.3.3項「.NET PEP API義務の処理」で説明されている義務も含まれています。

例6-16 リソースに対する.NET PEP API認可のリクエスト

String action = "read";
String resourceString = "MyApplication/MyResourceType/MyResource";
Hashtable env = new Hashtable();
env.Add("myAttr", "Hello");
IIdentity iIdentity = WindowsIdentity.GetCurrent();
IPepResponse response =
   PepRequestFactoryImpl.GetPepRequestFactory().NewPepRequest
  (iIdentity, action, resourceString, env).Decide();
Console.Write ("result: " + response.Allowed());
Dictionary<String, IObligation> obligations = response.GetObligations();
 
foreach (KeyValuePair<String, IObligation> entry in obligations) 
{Console.WriteLine
  ("Print the obligation" + entry.Value.GetStringValues());
}

例6-17は、サブジェクトが文字列として指定されているときに、.NET PEP APIを使用した認可をリクエストします。

例6-17 文字列サブジェクトによる.NET PEP API認可のリクエスト

String action = "read";
String resourceString = "MyApplication/MyResourceType/MyResource";
IPepResponse response = PepRequestFactoryImpl.GetPepRequestFactory().
  NewPepRequest("John", action, resourceString).Decide();
Console.WriteLine("result: " + response.Allowed());

例6-18は、サブジェクトがUserPrincipalとして指定されているときに、.NET PEP APIを使用した認可をリクエストします。

例6-18 UserPrincipalサブジェクトによる.NET PEP API認可のリクエスト

UserPrincipal userPrincipal = new UserPrincipal("user1");
Hashtable envTable = new Hashtable();
String action = "read";
String resourceString = "MyApplication/MyResourceType/MyResource";
IPepResponse response = PepRequestFactoryImpl.GetPepRequestFactory().
  NewPepRequest
  (userPrincipal, action, resourceString, envTable).Decide();
Console.WriteLine("result: " + response.Allowed()); 

6.1.3.3 .NET PEP API義務の処理

IObligationインタフェースのGetObligationId()メソッドは、認可リクエストに関連する義務を取得するために使用します。義務にはアクセスの決定と一緒にコール側アプリケーションに返される追加の情報を指定します。例6-16(前の項)は、義務を取得する認可リクエストです。例6-19に別の例を示します。

例6-19 .NET PEP APIによる単一の認可と義務のリクエスト

String appId = "test-app";
String userName = "weblogic";
String resourceType = "Electronics-MyRT";
String resource1 = ":Nelco1";
String action1 = "view";
String action2 = "off";IPepRequestFactory pepRequestFactoryImpl = 
  PepRequestFactoryImpl.GetPepRequestFactory();
Hashtable envTable = new Hashtable();
envTable.Add("electronicType", "entertainment");
IPepResponse pepresponse = pepRequestFactoryImpl.NewPepRequest
  (userName, action1, appId + "/" + resourceType + "/" + resource1,
   envTable).Decide();
Dictionary<String,IObligation> obligations=pepresponse.GetObligations();
foreach (KeyValuePair<String, IObligation> entry in obligations)
{
Console.WriteLine("Print the obligation" + entry.Value.GetStringValues());
}

6.1.3.4 .NET PEP API一括認可リクエストの実行

範囲とリソース文字列の指定方法は、6.1.1.4項「認可リクエスト文字列の書式」を参照してください。例6-20は一括認可のコールを示しています。

例6-20 一括認可のリクエスト

String appId = "test-app";
String userName = "weblogic";
String authenticatedUser = "weblogic";
//String resourceType = "LibraryResourceType";
String resourceType = "Electronics-MyRT";
String resource1 = ":Nelco1";
String resource2 = ":Nelco1:TV";
String resource3 = ":Nelco1:TV:small-screen";
String action1 = "view";
String action2 = "on";
String action3 = "off";

IPepRequestFactory pepRequestFactoryImpl = 
  PepRequestFactoryImpl.GetPepRequestFactory();
IPepResponse pepresponse=null;
bool isNext = false;
Collection<Object> resList = new Collection<Object>();
resList.Add(appId + "/" + resourceType + "/" + resource1);
resList.Add(appId + "/" + resourceType + "/" + resource2);
Collection<Object> actList = new Collection<Object>();
actList.Add(action1);
actList.Add(action3);
Hashtable envTable = new Hashtable();
envTable.Add("electronicType", "entertainment");
pepresponse = pepRequestFactoryImpl.NewBulkPepRequest
  (userName, actList, resList, envTable).Decide();
 
//First authorization decision
isNext = pepresponse.Next();
Debug.Assert(isNext == false, "Error in bulk operation");
Debug.Assert(pepresponse.Allowed() == false, "Error in bulk operation");
 
//Second authorization decision
isNext = pepresponse.Next();
Debug.Assert(isNext == false, "Error in bulk operation");
Debug.Assert(pepresponse.Allowed() == true, "Error in bulk operation");

6.1.3.5 .NET PEP API問合せリクエストの実行

.NET用PEP APIにはnewQueryPepRequest()メソッドが含まれており、認可リクエストによって適用されるリソースの範囲とアクションに関する情報を取得できます。範囲は、メソッドに渡されるサブジェクトと環境オブジェクトに基づきます。(範囲とリソース文字列の指定方法は、6.1.1.4項「認可リクエスト文字列の書式」を参照してください。)返される情報は、PepRequestQueryTypeがどのように定義されているかによります。次のいずれかの値を取得します。

  • RETURN_ONLY_ALLOWED_RESULTSによって、定義された範囲内で許可されるリソース・アクションのペアのリストが返されます。例6-21を参照してください。

  • RETURN_ONLY_DENIED_RESULTSによって、定義された範囲内で拒否されるリソース・アクションのペアのリストが返されます。例6-22を参照してください。

  • VERBOSEによって、定義済の範囲内からリクエストされたリソース・アクションのペアごとにすべての結果が返されます。例6-23を参照してください。

例6-21 許可されたリソース・アクション・ペアのリストに対する.NET問合せ

String appId = "MyApplication";
String resourceType = "resourceType";
String resource = "res";
IIdentity iIdentity = WindowsIdentity.GetCurrent();
IPepRequestFactory pepRequestFactoryImpl = 
  PepRequestFactoryImpl.GetPepRequestFactory();
IPepResponse pepresponse=null;
String actionStr="view,on,off";
bool isNext=false;
String scopeImmediate = "resource=" + "application" + "/" + "resource_type" + 
  "/" + "resource2" + ", actions=" + actionStr + ",searchscope=immediate";
Hashtable envTable = new Hashtable();
envTable.Add("electronicType", "entertainment");

pepresponse = pepRequestFactoryImpl.NewQueryPepRequest
  (iIdentity, envTable,scopeImmediate,PepRequestQueryType.
   RETURN_ONLY_ALLOWED_RESULTS).Decide();
 
isNext=pepresponse.Next();
Object act = pepresponse.GetAction();
List<String> actList = (List<String>)act;
if (actList.Contains("view") && actList.Contains("on"))
  { Debug.Assert(actList.Count == 2, "Invalid result");
}

例6-22 拒否されたリソース・アクション・ペアのリストに対する.NET問合せ

String appId = "MyApplication";
String resourceType = "resourceType";
String resource = "res";
IIdentity iIdentity = WindowsIdentity.GetCurrent();
IPepRequestFactory pepRequestFactoryImpl = 
  PepRequestFactoryImpl.GetPepRequestFactory();
IPepResponse pepresponse=null;
String actionStr = "view,on,off";
bool isNext = false;
String scopeImmediate = "resource=" + "application" + "/" + "resource_type" + 
  "/" + "resource2" + ", actions=" + actionStr + ",searchscope=immediate";
Hashtable envTable = new Hashtable();
envTable.Add("electronicType", "entertainment");
pepresponse = pepRequestFactoryImpl.NewQueryPepRequest
  (iIdentity, envTable, scopeImmediate, PepRequestQueryType.
   RETURN_ONLY_DENIED_RESULTS).Decide();
isNext = pepresponse.Next();
Object act = pepresponse.GetAction();
List<String> actList = (List<String>)act;
if (actList.Count == 1 || actList[0].Equals("off"))
  {
   Debug.Assert(actList.Count == 1, "Invalid result");
  }

例6-23 すべてのリソース・アクション・ペアのリストに対する.NET問合せ

String appId = "MyApplication";
String resourceType = "resourceType";
String resource = "res";
IIdentity iIdentity = WindowsIdentity.GetCurrent();
//for standalone
IPepRequestFactory pepRequestFactoryImpl =
  PepRequestFactoryImpl.GetPepRequestFactory();
IPepResponse pepresponse=null;
String actionStr = "view,on,off";
String scopeImmediate = "resource=" + "application" + "/" + "resource_type" + 
  "/" + "resource2" + ", actions=" + actionStr + ", searchscope=immediate";
Hashtable envTable = new Hashtable();
envTable.Add("electronicType", "entertainment");
 
pepresponse = pepRequestFactoryImpl.NewQueryPepRequest
  (iIdentity, envTable, scopeImmediate, PepRequestQueryType.VERBOSE).Decide();
 
//isNext = pepresponse.Next();
Object act = pepresponse.GetAction();
List<List<String>> actList = (List<List<String>>)act;
List<String> actListAllowed = actList[0];
List<String> actListDenied = actList[1];
if (actListAllowed.Count == 2)
  { Debug.Assert(actListAllowed.Count == 2, "Invalid result");
}
if (actListDenied.Count == 1)
  {
   Debug.Assert(actListDenied.Count == 1, "Invalid result");
}

例6-24は、指定されたリソースとその子に対する認可の問合せを示しています。searchscope=childrenであることに注意してください。

例6-24 リソースとその子に対する認可の結果のリクエスト

IPepRequestFactory pepRequestFactoryImpl = 
  PepRequestFactoryImpl.GetPepRequestFactory();
IPepResponse pepresponse=null;
String actionStr = "view,on,off";
String scopeImmediate = "resource=" + "application" + "/" + "resource_type" + 
  "/" + "resource2" + ", actions=" + actionStr + ",searchscope=children";
Hashtable envTable = new Hashtable();
envTable.Add("electronicType", "entertainment");
 
IIdentity iIdentity = WindowsIdentity.GetCurrent();pepresponse = pepRequestFactoryImpl.NewQueryPepRequest
  (iIdentity, envTable, scopeImmediate, PepRequestQueryType.VERBOSE).Decide();
 
//isNext = pepresponse.Next();
Object act = pepresponse.GetAction();
List<List<String>> actList = (List<List<String>>)act;
List<String> actListAllowed = actList[0];
List<String> actListDenied = actList[1];
if (actListAllowed.Count == 2)
  { Debug.Assert(actListAllowed.Count == 2, "Invalid result");
}
 if (actListDenied.Count == 1)
{
 Debug.Assert(actListDenied.Count == 1, "Invalid result");
}

6.1.3.6 .NET PEP APIの構成

.NET PEP APIは、ダイナミック・リンク・ライブラリ(DLL)によってMicrosoft .NETアプリケーションに提供されます。.NETアプリケーション開発者は、保護対象のアプリケーションの一部としてOES-PEP.dllを組み込む必要があります。さらに、次のように構成プロセスにも組み込みます。

  1. 保護対象のアプリケーションの一部としてOES-PEP.dllを組み込みます。これは.NETのアプリケーション開発者が行います。

  2. OES_CLIENT_HOME/oessm/dotnetsm/configtool/ディレクトリにあるdotnetsm_config.propertiesファイルの次のプロパティを更新します。

    • gac.utility: DLLが登録された.NET Frameworkのグローバル・アセンブリ・ユーティリティ・パスを定義します。

    • wssm.smurl: .NETアプリケーションがOracle Entitlements Serverと通信するために使用する、Web Serviceセキュリティ・モジュールのURLを定義します。

    • application.config.file: 保護対象のアプリケーションの構成ファイルを定義します。このパラメータの有効値は2つあります。Webアプリケーションの場合は、構成ファイルの名前がweb.configとなります。スタンドアロン・アプリケーションの場合は、構成ファイルの名前がapp.configとなります。

    • operation : 準備するアクションを定義します。このパラメータには2つの有効値があります。configは構成を表します。removeは.NETアプリケーションの構成ファイルに追加されたすべての構成を削除し、さらにGACユーティリティから登録済のOES-PEP.dlllog4net.dllを削除します。

    • application.log4NetXmlfil: .NETセキュリティ・モジュールのログ・ファイルを生成するlog4net.xmlのパスを定義します。.NETアプリケーションがすでにログ・ファイルを生成している場合は、既存のlog4net.xmlの場所を使用します。そうでない場合は、OES_CLIENT_HOME/dotnetsm/logging/にある、.NETセキュリティ・モジュールのlog4net.xmlファイルを使用します。

  3. Windowsマシンで次のコマンドを使用して構成ツールを実行します。smTypeはインスタンス化するセキュリティ・モジュールのタイプを表します(この場合はdotnet)。さらにsmConfigIdは、セキュリティ・モジュールがインスタンス化されたときに定義された識別子を表します(この場合はmyDotnet)。

    config.cmd -smType dotnet -smConfigId myDotnet
    

    このツールは、保護対象のアプリケーションをホストするWindowsマシンでOES-PEP.dllおよびlog4net.dllを登録し、アプリケーションの構成ファイル(web.configまたはapp.config)をWebサービス・セキュリティ・モジュールとロギング構成ファイルの場所で更新します。さらに、次のプロパティも定義します。

    • oracle.security.jps.pdp.proxy.RequestTimeoutMilliSecs - サーバーがレスポンスしない場合にリクエストがタイムアウトになるまでの時間間隔です。デフォルト値は10(秒)です。

    • oracle.security.jps.pdp.proxy.FailureRetryCount - 代替のフェイルオーバー・サーバーへ試行する前に、サーバーにアクセスを試行する回数です。デフォルト値は3(回の試行)です。

    • oracle.security.jps.pdp.proxy.FailbackTimeoutMilliSecs - プライマリ・サーバーと通信を再試行できるようになるまでの時間間隔です。デフォルト値は3(分)です。

    • oracle.security.jps.pdp.proxy.SynchronizationIntervalMilliSecs - 状態を同期するために、PDPプロキシがPDPサーバーをポーリングする頻度を定義します。たとえば、この間隔は、認可キャッシュをフラッシュする必要があるかどうかを定期的にチェックするために使用されます。デフォルト値は60(秒)です。

6.2 checkPermission()コールの実行

checkPermission()は、Java Permissionオブジェクトを使用して保護されたリソースへのアクセスを決定します。JavaのPermissionオブジェクトは、リソースへのアクセスを表し、適用可能な構成済ポリシーに基づいて作成され、(付与されたアクセスが)割り当てられます。Oracle Entitlements Serverでは、次の標準クラスでcheckPermission()メソッドを使用できます。

  • java.lang.SecurityManager

  • java.security.AccessController


    注意:

    静的なAccessController.checkPermissionメソッドは、デフォルトのアクセス制御コンテキスト(スレッド作成時に継承されるコンテキスト)を使用します。その他のコンテキストでパーミッションを確認するには、特定のAccessControlContextインスタンスでcheckPermission()メソッドのインスタンスをコールします。

さらに、Oracle Entitlements Serverは、oracle.security.jps.util.JpsAuthクラスでcheckPermission()メソッドの使用をサポートしています。


ヒント:

oracle.security.jps.util.JpsAuthクラスのcheckPermission()メソッドを使用することをお薦めします。これは、改善されたデバッグ・サポート、優れたパフォーマンスおよび監査サポートを提供しています。

(JavaSEアプリケーションで)checkPermission()メソッドを呼び出す場合は次の点を確認してください。

  1. java.security.policyシステム・プロパティがOracle Platform Security Services/Oracle WebLogic Serverポリシー・ファイルの場所に設定済である。

  2. アプリケーションが最初にsetPolicy()メソッドをコールし、明示的にポリシー・プロバイダを設定している。次のサンプル・コードはこの設定を示しています。

    java.security.Policy.setPolicy(new
     oracle.security.jps.internal.policystore.JavaPolicyProvider()); 
    

oracle.security.jps.util.JpsAuth.checkPermission()は、Permissionオブジェクトを受け入れることで標準メソッドとして厳密に機能します。リクエストされたアクセスが許可される場合は、checkPermission()が出力なしに返り、拒否される場合はAccessControlExceptionがスローされます。例6-25checkPermission()の使用方法を示しています。

例6-25 checkPermission()メソッドの使用方法

java.security.Policy.setPolicy(new
 oracle.security.jps.internal.policystore.JavaProvider()); // Java SE env only
PolicyContext.setContextID(TARGET_APP); // Java SE env only

// authorization runtime 
Subject s = new Subject(); s.getPrincipals().add(new WLSUserImpl("wcai")); s.setReadOnly();
JpsSubject.invokeAs(s, new PrivilegedAction<Object>() {
 
public Object run() {
FilePermission perm2 = new FilePermission("HARRY_PORTER", "read");     
psAuth.checkPermission(perm2);
    return null;
}

6.3 XACMLゲートウェイの使用

Oracle Entitlements Serverは、外部アプリケーションにXACML 2.0プロトコルを使用した認可の質問を許可します。Webサービス・セキュリティ・モジュールにはXACMLゲートウェイがあり、XACML認可リクエストの許可と、XACML認可レスポンスの返送を可能にしています。この機能は、マルチ・プロトコル・セキュリティ・モジュールを使用している場合にのみサポートされます。

Webサービス・セキュリティ・モジュールのXACMLゲートウェイは、リモートPDPとして機能します。PEPとPDP間では、標準のXACML 2.0コンテキストを使用して、認可リクエストとレスポンスが送受信されます。次に、XACML認証リクエストのプロセス・シーケンスを示します。

  1. PEP(アプリケーション)がセッションを確立し、ユーザーを認証して、そのプリンシパルの有効なトークンを取得します。

    例6-26は、セッションを確立し、XACML 2.0認可リクエストを送信する方法を示しています。例6-27は代替の方法を示しています。

    例6-26 XACMLゲートウェイのセッションを確立するサンプル・コード

    setupSession();
    request = createRequest();
    try {
        resp = xacmlSvc.authorize(request);
    } catch (AxisFault af) {
        if (isTokenExpired(af)) {
            resetupSession();
            try {
                resp = xacmlSvc.authorize(request);
            }
            catch (RemoteException e) {
                throw new XACMLException("Error calling the XACML service.", e);
            }
                     }
        else {
            throw new XACMLException("Error calling the XACML service.", af);
        }
    } catch (RemoteException e) {
             throw new XACMLException("Error calling the XACML service.", e);
                }
     
    private boolean isTokenExpired(AxisFault af) {
      String faultReason = af.getFaultReason();
      if((faultReason != null) && (faultReason.indexOf
        ("IdentityAssertionException") != -1)) {
         return true;
    }
    return false;
        }
     
    private void setupSession() throws XACMLException {
      if (identity == null) {
          establishSession();
    }
        }
     
    private void resetupSession() throws XACMLException {
     establishSession();
    }
    
    private void establishSession() throws XACMLException {
      try {
        EstablishSessionType sess = new EstablishSessionType();
        sess.setPrincipalsInfo(convertSubjectToPrincipalsInfo(subject));
        sess.setRequestedCredentialType(OES_CREDENTIAL_TYPE);
            AuthenticationResultType result = atzSvc.establishSession(sess);
            identity = result.getIdentityAssertion();
          }
          catch (Exception e) {
            throw new XACMLException("Unable to authenticate user.", e);
          }
          if (identity == null) {
              throw new XACMLException("Null identity received. 
                 Unable to establish session for " + subject);
          }
          System.out.println("Authentication Succeeded, Identity: ");
          MessageElement ele = identity.get_any()[0];
          System.out.println(ele.getFirstChild());
      }
    

    例6-27は、すべてのリクエストにサブジェクトを渡すことができ、establishSessionメソッドを必要としない新しいモードを示しています。例6-26の以前のモードは依然としてサポートされています。

    例6-27 プリンシパル情報によりセッションを確立するサンプル・コード

    /**
     * Test authorize for user role in new mode which send the principal info in 
       every request.
     * @throws Exception
     */
    public void testAtzForUserRoleNewMode() throws Exception {
      SubjectType sbjct1 = constructSubject(OTHER_USER, new String[]{OTHER_ROLE});
      SubjectType sbjct2 = constructSubject(ADMIN_USER, new String[]{ADMIN_ROLE});
     
    printTestHeader("Deny Test: user \"" + OTHER_USER + "\" is in role \"" + 
      OTHER_ROLE + "\"");
    sendRequest(new SubjectType[]{sbjct1}, new ResourceType[]{resTest1}, 
      actionWrite, emptyEnv);
     
    printTestHeader("Permit Test: user \"" + ADMIN_USER + "\" is in role \"" + 
      ADMIN_ROLE + "\"");
    sendRequest(new SubjectType[]{sbjct2}, new ResourceType[]{resTest1}, 
      actionWrite, emptyEnv);
    }
    
  2. PEPは、PDP(セキュリティ・モジュール)へのトークンを含んだXACMLリクエストを送信します。

    例6-28は、XACML認可リクエストの作成方法を示しています。

    例6-28 XACMLリクエストの作成

    private RequestType createRequest() throws XACMLException
    {
      // create resource
      String res = "Library/LibraryResourceType/Book";
      AttributeType attr = createAttribute(res, RESOURCE_ID, XML_STRING_TYPE);
      ResourceType resource = new ResourceType(null, new AttributeType[]{attr});
        // create action
      String actionStr = "borrow";
      attr = createAttribute(actionStr, ACTION_ID, XML_STRING_TYPE);
      ActionType action = new ActionType(new AttributeType[]{attr});
        // create environment
      String isRegistered = input.getString("Is the user registered in the library (yes|no): ");
      String numberOfBorrowedBooks = input.getString("How many books has the user borrowed already:: ");
      EnvironmentType env;
      List attrs = new ArrayList();
      attrs.add(createAttribute(isRegistered, XACML_NAMESPACE + "RegisteredAttribute", XML_STRING_TYPE));
      attrs.add(createAttribute(numberOfBorrowedBooks, XACML_NAMESPACE + "NumberOfBorrowedBooksAttribute", XML_STRING_TYPE));
        // obligations
      attrs.add(createAttribute(LIST_VAL1, XACML_NAMESPACE + ATTRIBUTE_NAME, XML_STRING_TYPE));
      attrs.add(createAttribute(LIST_VAL2, XACML_NAMESPACE + ATTRIBUTE_NAME, XML_STRING_TYPE));
        env = new EnvironmentType((AttributeType[])attrs.toArray(new AttributeType[attrs.size()]));
        // subject
      attr = createAttribute(identity.get_any(), SUBJECT_ID, XACML_NAMESPACE + OES_CREDENTIAL_TYPE);
      SubjectType subject = new SubjectType(new AttributeType[]{attr}, null);
        // now construct the request with subject, resource, action and environment.
      return new RequestType(new SubjectType[]{subject},
                 new ResourceType[]{resource}, action, env);
    }
    

    例6-29は、XACML 2.0認可リクエストのサンプルです。SSM-SOAPWS_xacml.wsdlファイルは、操作インタフェースの定義を提供しています。

    例6-29 XACML 2.0認可リクエスト

    <Request xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os">
      <Subject xsi:type="ns1:SubjectType" xmlns:ns1="urn:oasis:names:tc:xacml:2.0:context:schema:os" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" 
         DataType="http://security.bea.com/ssmws/ssm-ws-1.0.wsdl#OESIdentityAssertion" 
    xsi:type="ns1:AttributeType">
          <AttributeValue xsi:type="ns1:AttributeValueType">
            <OESIdentityAssertion 
               xmlns="http://security.bea.com/ssmws/ssm-soap-types-1.0.xsd">
             SU=John;TS=1288702235781;CT=1</OESIdentityAssertion> 
          </AttributeValue>
        </Attribute>
      </Subject>
      <ns2:Resource xsi:type="ns2:ResourceType"   
       xmlns:ns2="urn:oasis:names:tc:xacml:2.0:context:schema:os" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ns2:Attribute AttributeId="urn:oasis:names:tc:xacml:2.0:resource:resource-id" 
          DataType="http://www.w3.org/2001/XMLSchema#string" 
          xsi:type="ns2:AttributeType">
        <ns2:AttributeValue xsi:type="ns2:AttributeValueType">
            Library/LibraryResourceType/Book</ns2:AttributeValue> 
        </ns2:Attribute>
      </ns2:Resource>
      <ns3:Action xsi:type="ns3:ActionType"  
         xmlns:ns3="urn:oasis:names:tc:xacml:2.0:context:schema:os" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <ns3:Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" 
         DataType="http://www.w3.org/2001/XMLSchema#string" 
          xsi:type="ns3:AttributeType">
      <ns3:AttributeValue 
        xsi:type="ns3:AttributeValueType">borrow</ns3:AttributeValue> 
      </ns3:Attribute>
      </ns3:Action>
      <ns4:Environment xsi:type="ns4:EnvironmentType" 
         xmlns:ns4="urn:oasis:names:tc:xacml:2.0:context:schema:os" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <ns4:Attribute AttributeId=
        "http://security.bea.com/ssmws/ssm-ws-1.0.wsdl#RegisteredAttribute" 
         DataType="http://www.w3.org/2001/XMLSchema#string" 
         xsi:type="ns4:AttributeType">
      <ns4:AttributeValue xsi:type="ns4:AttributeValueType">yes</ns4:AttributeValue> 
        </ns4:Attribute>
        <ns4:Attribute AttributeId=
          "http://security.bea.com/ssmws/ssm-ws-1.0.wsdl
          #NumberOfBorrowedBooksAttribute" 
           DataType="http://www.w3.org/2001/XMLSchema#string" 
           xsi:type="ns4:AttributeType">
        <ns4:AttributeValue xsi:type="ns4:AttributeValueType">2</ns4:AttributeValue> 
        </ns4:Attribute>
      </ns4:Environment>
    </Request>
    
  3. XACMLゲートウェイはトークンをアサートし、該当するアイデンティティに変換します。

  4. Oracle Entitlements Serverは、該当するポリシーを使用してそのプリンシパルについての認可を決定し、XACMLレスポンスをPEPに返します。

    例6-30は、XACML 2.0認可レスポンスのサンプルです。SSM-SOAPWS_xacml.wsdlファイルは、操作インタフェースの定義を提供しています。

    例6-30 XACML 2.0認可レスポンス

    <Response xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os">
        <Result ResourceId="Library/LibraryResourceType/Book">
          <Decision>Permit</Decision>
          <Status>
            <StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:ok"/>
          </Status>
          <ns1:Obligations xmlns:ns1="urn:oasis:names:tc:xacml:2.0:policy:schema:os">
            <ns1:Obligation ObligationId=
             "http://security.bea.com/ssmws/ssm-ws-1.0.wsdl#Roles" FulfillOn="Permit">
            <ns1:AttributeAssignment 
              DataType="http://www.w3.org/2001/XMLSchema#string" 
              AttributeId="http://security.bea.com/ssmws/ssm-ws-1.0.wsdl#role">
              AuthenticatedUser</ns1:AttributeAssignment>
            </ns1:Obligation>
            <ns1:Obligation    
              ObligationId="http://security.bea.com/ssmws/ssm-ws-1.0.wsdl#
              ResponseAttributes" FulfillOn="Permit">
            <ns1:AttributeAssignment 
              DataType="http://www.w3.org/2001/XMLSchema#dateTime" 
             AttributeId="http://security.bea.com/ssmws/ssm-ws-1.0.wsdl#decisionTime">
              2010-11-02T12:50:43.685Z</ns1:AttributeAssignment>
            </ns1:Obligation>
          </ns1:Obligations>
        </Result>
      </Response>