ヘッダーをスキップ
Oracle® Fusion Middlewareアプリケーション・セキュリティ・ガイド
11gリリース1(11.1.1)
B56235-07
  目次へ移動
目次
索引へ移動
索引

前
 
次
 

26 アイデンティティ・ディレクトリAPIを使用した開発

この章では、アイデンティティ・ディレクトリAPIを使用して、アイデンティティ・ストアにアクセスして操作する方法について説明します。

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

26.1 アイデンティティ・ディレクトリAPIについて

アイデンティティ・ディレクトリAPIを使用すると、アプリケーションは、基礎となるアイデンティティ・リポジトリの種類を問わず、統一的で移植可能な方法でアイデンティティ情報(ユーザーやその他のエンティティ)にアクセスすることができます。

アイデンティティ・ディレクトリAPIの特徴:

アイデンティティ・ディレクトリAPIはIdentity Governance Frameworkを使用し、このフレームワークのすべての利点を提供することにより、個人情報(PII)、アクセス権限、属性およびその他のエンティティなどのアイデンティティ関連の情報が使用および格納され、組織間で伝播される方法を制御することを可能にします。

26.1.1 機能の概要

この項では、アイデンティティ・ディレクトリAPIによってサポートされている機能について説明します。

ユーザー・エンティティに対する機能

ユーザーに対して次の機能がサポートされています。

  • ユーザーに対する作成、読取り、更新、削除(CRUD)の操作の実行

  • 次の手順を実行します。

    • ユーザー属性の取得と設定

    • アイデンティティ・ストアのネイティブ認証メカニズムでのユーザーの認証

    • ユーザーが属するグループの取得(オプションで、ネストされたグループも含む)

    • グループのメンバーとしてのユーザーの追加

  • ユーザー・パスワードの変更

  • ユーザー・パスワードの変更の強制

  • ユーザー状態(有効/無効、ロックアウト、パスワード変更が必要)の取得と設定

グループ・エンティティに対する機能

グループに対して次の機能がサポートされています。

  • グループに対するCRUD操作の実行

  • 次の手順を実行します。

    • 属性の取得と設定

    • グループのメンバーの取得と検索

    • グループが属するグループの取得(オプションで、ネストされたグループも含む)

    • グループが別のグループのメンバーであるかどうかの判別

  • 複数の値を持つ属性のサポート

  • 静的グループおよび動的グループのサポート

26.2 クラスの概要

表26-1に、アイデンティティ・ディレクトリAPIのクラスをリストします。

表26-1 アイデンティティ・ディレクトリAPIのクラス

クラス 説明

Capabilities

エンティティの機能を含みます。

CreateOptions

エンティティ作成操作に対するオプションを含みます。

DeleteOptions

エンティティ削除操作に対するオプションを含みます。

Entity

検索または読取りメソッドを使用してフェッチされたエンティティの属性リストを格納する汎用エンティティ・クラス。

EntityAlreadyExistsException

既存のエンティティの作成を試みると返されます。

EntityCapabilities


EntityManager

汎用エンティティの読取り、作成、検索などの操作を処理します。

EntityNotFoundException

リクエストされたエンティティが見つからない場合に返されます。

EntityNotUniqueException

エンティティが一意に定義されていない場合に返されます。

EntityRelationManager

関係の読取り、作成、削除、検索などのエンティティ関係操作を処理します。

Group

グループのメンバー・リストを格納する汎用エンティティ・クラス。グループ・メンバーシップを変更するメソッドも提供します。

GroupManager

グループの作成、削除、検索などの操作を処理します。

IDSException

例外を処理します。

IDSPrincipal

例外に関連するプリンシパルを含みます。

IdentityDirectory

IdentityDirectoryインスタンスを作成するためのIdentityDirectoryへのハンドルを表します。

対応するエンティティに対する操作を実行できるように、インスタンスはUser、Groupおよび汎用エンティティ・マネージャのハンドルを提供します。

IdentityDirectoryFactory

IdentityDirectoryServiceを作成するためのファクトリ・クラス。

IdentityDirectoryInfo


InvalidAttributesException

無効なエンティティ属性に関連する例外に使用されます。

InvalidFilterException

アイデンティティBean内で生成された例外に使用されます。

ModAttribute

ModifyOptions

エンティティ変更操作に対するオプションを含み、OperationOptionsを拡張します。

OperationNotSupportedException

アイデンティティBean内で生成された例外に使用されます。

ReadOptions

エンティティ読取り操作に対するオプションを含み、OperationOptionsを拡張します。読取りオプションにはLocaleおよびRequested Attributes設定が含まれます。

ResultSet

ページングの結果との検索相互作用により返されるオブジェクトに対するインタフェース。

SearchFilter

エンティティを検索するための簡易検索フィルタまたは複雑なネストされた検索フィルタを作成するために使用されます。

SearchOptions

エンティティ検索操作に対するオプションを含み、ReadOptionsを拡張します。

User

ユーザー・エンティティに対する汎用クラス。

UserCapabilities

ユーザー機能属性を含みます。

UserManager

様々な基準によりユーザーを作成、削除、検索するためのメソッドを含みます。


26.3 アイデンティティ・ディレクトリの構成

アイデンティティ・ディレクトリの構成は、論理的なエンティティ構成と物理的なアイデンティティ・ストア構成の組合せになります。

論理エンティティ構成を使用するアイデンティティ・ディレクトリは次の場所に格納されています。

DOMAIN_HOME/config/fmwconfig/ids-config.xml

デフォルトのアイデンティティ・ディレクトリに対する物理的なアイデンティティ・ストア構成は次の場所にあります。

DOMAIN_HOME/config/fmwconfig/ovd/default

デフォルトのアイデンティティ・ディレクトリでは、OPSS (WebLogic認証プロバイダまたはjps-config.xml)で構成されているものと同じアイデンティティ・ストア・プロパティ(つまり、ホスト、ポート、資格証明、検索ベース、作成ベース、名前属性など)が使用されます。詳細は、第F.2.3項「LDAPアイデンティティ・ストアのプロパティ」を参照してください。

26.4 アイデンティティ・ディレクトリAPIの操作

この項では、アプリケーションがアイデンティティ・ディレクトリAPIを使用して、アイデンティティ・ストア・データを表示および管理する方法について説明します。次のセクションが含まれます:

26.4.1 アイデンティティ・ディレクトリAPIインスタンスの取得

次のように、jps-contextからアイデンティティ・ディレクトリ・ハンドルを取得し、ディレクトリ・インスタンスを取得できます。

JpsContextFactory ctxFactory = JpsContextFactory.getContextFactory();
JpsContext ctx = ctxFactory.getContext();
       
//find the JPS IdentityStore service instance
IdentityStoreService idstoreService =   ctx.getServiceInstance(IdentityStoreService.class)
 
//get the Identity Directory instance
oracle.igf.ids.IdentityDirectory ids = idstoreService.getIdentityStore();

26.4.2 ユーザーとグループに対するCRUD操作の実行

ユーザーとグループに対して、作成、取得、更新および削除(CRUD)操作を実行できます。

26.4.2.1 ユーザー操作

ユーザーに対する基本的なCRUD操作は次のとおりです。

ユーザーの作成

Principal UserManager.createUser(List<Attribute> attrVals, CreateOptions opts)

ユーザーの取得

User UserManager.getUser(Principal principal, ReadOptions opts)

ユーザーの検索

User UserManager.searchUser(String id, ReadOptions opts)

ユーザーの削除

void UserManager.deleteUser(String id, DeleteOtions opts)

ユーザーの更新

void UserManager.modify(List<ModAttribute> attrVals, ModifyOptions opts)

ユーザー・リストの取得

ResultSet UserManager.searchUsers(SearchFilter filter, SearchOptions opts)

26.4.2.2 グループ操作

グループに対する基本的なCRUD操作は次のとおりです。

グループの作成

Principal GroupManager.createGroup(List<Attribute> attrVals, CreateOptions opts)

グループの取得

User GroupManager.getGroup(Principal principal, ReadOptions opts)

グループの検索

User GroupManager.searchGroup(String id, ReadOptions opts)

グループの削除

void GroupManager.deleteGroup(String id, DeleteOtions opts)

グループ属性の変更

void GroupManager.modify(List<ModAttribute> attrVals, ModifyOptions opts)

グループ・リストの取得

ResultSet GroupManager.searchGroups(SearchFilter filter, SearchOptions opts)

26.5 アイデンティティ・ディレクトリAPIの例

この項では、次のアイデンティティ・ディレクトリAPIの使用例を紹介します。


関連項目:

第22.1項「Java SEアプリケーションでのOPSSの使用」のOPSSを使用したJava SEアプリケーションの保護の詳細。


26.5.1 アイデンティティ・ディレクトリ・ハンドルの初期化と取得

このサンプル・コードでは、アイデンティティ・ディレクトリへのハンドルを初期化して取得します。

/**
 * This is a sample program for initializing Identity Directory Service with the configuration
 * that is already persisted in IDS config location.
 * Basic User and Group CRUDS are performed using this IDS instance
 */
 
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
 
import java.security.Principal;
 
import oracle.igf.ids.Entity;
import oracle.igf.ids.User;
import oracle.igf.ids.UserManager;
import oracle.igf.ids.Group;
import oracle.igf.ids.GroupManager;
import oracle.igf.ids.config.OperationalConfig;
import oracle.igf.ids.IdentityDirectoryFactory;
import oracle.igf.ids.IdentityDirectoryInfo;
import oracle.igf.ids.IdentityDirectory;
import oracle.igf.ids.IDSException;
import oracle.igf.ids.ReadOptions;
import oracle.igf.ids.CreateOptions;
import oracle.igf.ids.ModifyOptions;
import oracle.igf.ids.DeleteOptions;
import oracle.igf.ids.SearchOptions;
import oracle.igf.ids.SearchFilter;
import oracle.igf.ids.ResultSet;
import oracle.igf.ids.Attribute;
import oracle.igf.ids.ModAttribute;
 
import oracle.dms.context.ExecutionContext;
 
 
public class Ids1Test {
 
    private IdentityDirectory ids;
    private UserManager uMgr;
    private GroupManager gMgr;
 
 
    /**
     * Get Identity Store Service
     */
    public Ids1Test() throws IDSException {
 
        // Set Operational Config
        OperationalConfig opConfig = new OperationalConfig();
 
        // Set the application credentials: this overrides the credentials 
        // set in physical ID store configuration
        //opConfig.setApplicationUser("cn=test_user1,l=amer,dc=example,dc=com");
        //opConfig.setApplicationPassword("welcome123".toCharArray());
 
        // Set search/crate base, name, objclass, etc. config.  
        // This overrides default operational configuration in IDS
        opConfig.setEntityProperty("User", opConfig.SEARCH_BASE,          "l=amer,dc=example,dc=com");
        opConfig.setEntityProperty("User", opConfig.CREATE_BASE,          "l=amer,dc=example,dc=com");
        opConfig.setEntityProperty("User", opConfig.FILTER_OBJCLASSES, "person");
        opConfig.setEntityProperty("User", opConfig.CREATE_OBJCLASSES,          "inetorgperson");
        opConfig.setEntityProperty("Group", opConfig.SEARCH_BASE,          "cn=dlcontainerOCS,dc=example,dc=com");
        opConfig.setEntityProperty("Group", opConfig.CREATE_BASE,          "cn=dlcontainerOCS,dc=example,dc=com");
        opConfig.setEntityProperty("Group", opConfig.FILTER_OBJCLASSES,          "groupofuniquenames");
        opConfig.setEntityProperty("Group", opConfig.CREATE_OBJCLASSES,          "groupofuniquenames,orclgroup");
 
        // Get IdentityDirectoryService "userrole" configured in IDS config
        IdentityDirectoryFactory factory = new IdentityDirectoryFactory();
        //ids = factory.getDefaultIdentityDirectory(opConfig);
        ids = factory.getIdentityDirectory("userrole", opConfig);
 
        // Get UserManager and GroupManager handles
        uMgr = ids.getUserManager();
        gMgr = ids.getGroupManager();
    }
 

26.5.2 ユーザーの作成

このサンプル・コードでは、アイデンティティ・ストア内にユーザーを作成します。

 public Principal createUser() {
        Principal principal = null;
        
        List<Attribute> attrs = new ArrayList<Attribute>();
        attrs.add(new Attribute("commonname", "test1_user1"));
        attrs.add(new Attribute("password", "welcome123".toCharArray()));
        attrs.add(new Attribute("firstname", "test1"));
        attrs.add(new Attribute("lastname", "user1"));
        attrs.add(new Attribute("mail", "test1.user1@example.com"));
        attrs.add(new Attribute("telephone", "1 650 123 0001"));
        attrs.add(new Attribute("title", "Senior Director"));
        attrs.add(new Attribute("uid", "tuser1"));
        // Adding locale specific value
        attrs.add(new Attribute("description", "created test user 1", 
         new java.util.Locale("us", "en")));
        try {
            CreateOptions createOpts = new CreateOptions();
            createOpts.setCreateBase("l=apac,dc=example,dc=com");
 
            principal = uMgr.createUser(attrs, createOpts);
 
            System.out.println("Created user " + principal.getName());
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
 
        return principal;
    }

26.5.3 ユーザーの取得

このサンプル・コードでは、アイデンティティ・ストアからユーザーを取得します。

 public User getUser(Principal principal) {
        User user = null;
 
        try {
            ReadOptions readOpts = new ReadOptions();
            // Getting specific locale values
            readOpts.setLocale("us-en");
 
            user = uMgr.getUser(principal, readOpts);
            
            printEntity(user);
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
 
        return user;
    }

26.5.4 ユーザーの変更

このサンプル・コードでは、新しいユーザー属性を追加することにより既存のユーザーを変更します。

 public void modifyUser(User user) {
 
        try {
            ModifyOptions modifyOpts = new ModifyOptions();
 
            List<ModAttribute> attrs = new ArrayList<ModAttribute>();
            attrs.add(new ModAttribute("description", "modified test user 1"));
            //attrs.add(new ModAttribute("uid", "testuser1"));
 
            user.modify(attrs, modifyOpts);
            
            System.out.println("Modified user " + user.getName());
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

26.5.5 ユーザーの簡易検索

このサンプル・コードでは、基本的なユーザー検索を実行します。

 try {
            ReadOptions readOpts = new ReadOptions();
            readOpts.setSearchBase("l=apac");
 
            User user = uMgr.searchUser("tuser1", readOpts);
            
            printEntity(user);
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

26.5.6 ユーザーの複合検索

このサンプル・コードでは、複合検索フィルタを使用して一致するユーザーを返します。

public void searchUsers() {
 
   try {
      // Complex search filter with nested AND and OR conditiions
      SearchFilter filter = new SearchFilter(
         SearchFilter.LogicalOp.OR,
         new SearchFilter(SearchFilter.LogicalOp.AND,
         new SearchFilter("firstname", SearchFilter.Operator.BEGINS_WITH, "ve"),
         new SearchFilter("telephone", SearchFilter.Operator.CONTAINS, "506")),
         new SearchFilter(SearchFilter.LogicalOp.AND,
         new SearchFilter("firstname", SearchFilter.Operator.BEGINS_WITH, "ra"),
         new SearchFilter(SearchFilter.LogicalOp.OR,
         new SearchFilter("orgunit", SearchFilter.Operator.BEGINS_WITH, "ldap"),
         new SearchFilter("orgunit", SearchFilter.Operator.BEGINS_WITH, "sun"),
         new SearchFilter("orgunit", SearchFilter.Operator.BEGINS_WITH,           "access")),
         new SearchFilter("telephone", SearchFilter.Operator.CONTAINS, "506")));
 
      // Requesting attributes
      List<String> reqAttrs = new ArrayList<String>();
      reqAttrs.add("jpegphoto");
 
      SearchOptions searchOpts = new SearchOptions();
      searchOpts.setPageSize(3);
      searchOpts.setRequestedPage(1);
      searchOpts.setRequestedAttrs(reqAttrs);
      searchOpts.setSearchBase("l=amer");
 
      ResultSet<User> sr = uMgr.searchUsers(filter, searchOpts);
         while (sr.hasMore()) {
            User user = sr.getNext();
            //printEntity(user);
            //System.out.println(" ");
            System.out.println(user.getSubjectName());
            System.out.println("    " + user.getAttributeValue("commonname"));
         }
 
      } catch (Exception e) {
         System.out.println(e.getMessage());
         e.printStackTrace();
      }
    }

26.5.7 グループの作成

このサンプル・コードではグループを作成します。

 public Principal createGroup() {
        Principal principal = null;
        
        List<Attribute> attrs = new ArrayList<Attribute>();
        attrs.add(new Attribute("name", "test1_group1"));
        attrs.add(new Attribute("description", "created test group 1"));
        attrs.add(new Attribute("displayname", "test1 group1"));
        try {
            CreateOptions createOpts = new CreateOptions();
 
            principal = gMgr.createGroup(attrs, createOpts);
 
            System.out.println("Created group " + principal.getName());
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
 
        return principal;
    }

26.5.8 グループの取得

このサンプル・コードでは特定のグループを返します。

 public Group getGroup(Principal principal) {
        Group group = null;
 
        try {
            ReadOptions readOpts = new ReadOptions();
 
            group = gMgr.getGroup(principal, readOpts);
            
            printEntity(group);
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
 
        return group;
    }

26.5.9 検索フィルタを使用したグループの取得

このサンプル・コードでは、検索フィルタを使用してグループを返します。

 public void searchGroups() {
 
        try {
            SearchFilter filter = new SearchFilter("name",
                                SearchFilter.Operator.BEGINS_WITH, "test");
 
            SearchOptions searchOpts = new SearchOptions();
            searchOpts.setPageSize(10);
 
            ResultSet<Group> sr = gMgr.searchGroups(filter, searchOpts);
            while (sr.hasMore()) {
                Group group = sr.getNext();
                System.out.println(group.getSubjectName());
            }
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

26.5.10 グループの削除

このサンプル・コードでは、ストアからグループを削除します。

 public void deleteGroup(Principal principal) {
 
        try {
            DeleteOptions deleteOpts = new DeleteOptions();
 
            gMgr.deleteGroup(principal, deleteOpts);
            
            System.out.println("Deleted group " + principal.getName());
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

26.5.11 グループへのメンバーの追加

このサンプル・コードでは、グループにメンバーを追加します。

 public void addMember() {
        try {
            ReadOptions readOpts = new ReadOptions();
            User user = uMgr.searchUser("testuser1", readOpts);
            Group group = gMgr.searchGroup("test1_group1", readOpts);
 
            ModifyOptions modOpts = new ModifyOptions();
            user.addMemberOf(group, modOpts);
 
            System.out.println("added testuser1 as member of test1_group1");
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

26.5.12 グループからのメンバーの削除

このサンプル・コードでは、グループからメンバーを削除します。

 public void deleteMember() {
        try {
            ReadOptions readOpts = new ReadOptions();
            User user = uMgr.searchUser("testuser1", readOpts);
            Group group = gMgr.searchGroup("test1_group1", readOpts);
 
            ModifyOptions modOpts = new ModifyOptions();
            group.deleteMember(user, modOpts);
 
            System.out.println("deleted testuser1 from the group test1_group1");
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

26.6 SSL構成

アイデンティティ・ディレクトリAPIの使用時のSSL構成の詳細は、第7.5項「アイデンティティ・ストア・サービスでのSSLの使用」を参照してください。