プライマリ・コンテンツに移動
Oracle® Fusion Middleware Oracle Platform Security Servicesによるアプリケーションの保護
12c (12.2.1)
E72537-01
  目次へ移動
目次

前
 
次
 

20 Identity Governance Frameworkを使用した開発

この章では、Identity Governance Frameworkに用意されているアイデンティティ・ディレクトリAPIを使用してアイデンティティにアクセスする方法およびメンテナンスする方法について説明します。

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

20.1 Identity Governance Frameworkについて

Identity Governance Frameworkを使用すると、アプリケーションでは、基礎となるアイデンティティ・リポジトリの種類を問わず、統一的な方法でアイデンティティ・データにアクセスできます。このフレームワークには、アイデンティティ・ディレクトリAPIが組み込まれていますが、このAPIはアイデンティティ・ストアのアーティファクトにアクセスできるインタフェースの集合で、柔軟に全面的に構成できます。

アイデンティティ・ディレクトリAPIを使用するには、igf-manifest.jarファイルをアプリケーション・クラスパスに追加します。


関連項目:

Oracle Fusion Middleware Identity Governance Framework Identity Directory用のJava APIリファレンス


20.1.1 アイデンティティ・ディレクトリAPIの概要

アイデンティティ・ディレクトリAPIを使用すると、Java EEアプリケーションおよびJava SEアプリケーションでアイデンティティ・データへのアクセスおよび管理が可能になります。このAPIは、Identity Governance Frameworkに付属し、アイデンティティ制御に関するフレームワークの利点をすべて提供します。

アイデンティティ・ディレクトリAPIを使用すると、次のことが可能になります。

  • ユーザーおよびグループの操作。

  • パスワードの変更。

  • パスワード変更の施行。

  • 複数の値を持つ属性、静的グループおよび動的グループのメンテナンス。

20.2 アイデンティティ・ディレクトリAPIの構成について

アイデンティティ・ディレクトリAPIは、異なるアイデンティティ・ストアに格納されているユーザーおよびグループ情報にアクセスし、それらを変更するためのインタフェースを提供します。構成は、DOMAIN_HOME/config/fmwconfig/ids-config.xmlファイル、ovd/ids/adapters.os.xmlファイルおよびOPSS構成ファイルに指定します。


関連項目:

第9.6項「Fusion Middleware Controlを使用したセキュリティ・プロバイダの構成」

第F.2.4項「LDAPアイデンティティのプロパティ」

Oracle Fusion Middleware Identity Governance Framework Identity Directory用のJava APIリファレンスのアイデンティティ・ディレクトリAPIの構成に関する項

Oracle Fusion Middleware Identity Governance Framework Identity Directory用のJava APIリファレンス


20.3 アイデンティティ・ディレクトリAPIの使用

次の各項では、ユーザーおよびグループを管理するためのアイデンティティ・ディレクトリAPIの使用例を示します。

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

次の例では、アイデンティティ・ディレクトリ・ハンドルおよびディレクトリ・インスタンスを取得する方法を示します。

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

次の例では、IDSの場所にある構成でサービスを初期化しています。すべてのユーザーおよびグループの操作は、このIDSインスタンスを使用して実行されます。

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;
    public Ids1Test() throws IDSException {
        // Set Operational Config
        OperationalConfig opConfig = new OperationalConfig();

        // 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.getIdentityDirectory("userrole", opConfig);
 
        // Get UserManager and GroupManager handles
        uMgr = ids.getUserManager();
        gMgr = ids.getGroupManager();
    }

20.3.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"));
        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;
    }
 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();
        }
    }

20.3.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;
    }
 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();
        }
    }

20.3.4 ユーザーの簡易検索と複合検索

次の例では、簡易ユーザー検索と複合ユーザー検索を示します。

 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();
        }
    }
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")));
 
      // Request 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();
            System.out.println(user.getSubjectName());
            System.out.println("    " + user.getAttributeValue("commonname"));
         }
      } catch (Exception e) {
         System.out.println(e.getMessage());
         e.printStackTrace();
      }
    }

20.3.5 グループの作成と削除

次の例では、グループを作成および削除する方法を示します。

 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;
    }

20.3.6 グループの取得

次の例では、グループへのハンドルを取得する方法を示します。

 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;
    }

20.3.7 グループ検索フィルタ

次の例では、複数のグループを返す検索フィルタを示します。

 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();
        }
    }

20.3.8 グループに対するメンバーの追加と削除

次の例では、グループに対してユーザーを追加および削除する方法を示します。

 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();
        }
    }
 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();
        }
    }

20.4 アイデンティティ・ディレクトリAPIを使用したSSLの構成

アイデンティティ・ディレクトリAPI使用時のSecure Sockets Layer (SSL)構成の詳細は、第8.5項「アイデンティティ・ストア用のSSLの構成」を参照してください。