Oracle® Fusion Middleware Oracle Platform Security Servicesによるアプリケーションの保護 12c (12.2.1.3.0) E92000-01 |
|
前 |
次 |
この章の内容は次のとおりです。
Identity Governance Frameworkを使用すると、アプリケーションでは、基礎となるアイデンティティ・リポジトリの種類を問わず、統一的な方法でアイデンティティ・データにアクセスできます。このフレームワークには、アイデンティティ・ディレクトリAPIが組み込まれていますが、このAPIはアイデンティティ・ストアのアーティファクトにアクセスできるインタフェースの集合で、柔軟に全面的に構成できます。
アイデンティティ・ディレクトリAPIを使用するには、igf-manifest.jar
ファイルをアプリケーション・クラスパスに追加します。
関連項目:
Identity Governance Frameworkアイデンティティ・ディレクトリJava APIリファレンス
アイデンティティ・ディレクトリAPIは、異なるアイデンティティ・ストアに格納されているユーザーおよびグループ情報にアクセスし、それらを変更するためのインタフェースを提供します。構成は、DOMAIN_HOME/config/fmwconfig/ids-config.xml
ファイル、ovd/ids/adapters.os.xml
ファイルおよびOPSS構成ファイルに指定します。
関連項目:
Fusion Middleware Controlを使用したセキュリティ・プロバイダの構成
『Identity Governance Frameworkによるアプリケーションの開発』のアイデンティティ・ディレクトリAPIの構成
Identity Governance Frameworkアイデンティティ・ディレクトリJava APIリファレンス
次の各項では、ユーザーおよびグループを管理するためのアイデンティティ・ディレクトリAPIの使用例を示します。
次の例では、アイデンティティ・ディレクトリ・ハンドルおよびディレクトリ・インスタンスを取得する方法を示します。
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(); }
次の例では、ユーザーを作成および削除する方法を示します。
public Principal createUser() { Principal principal = null; List<Attribute> attrs = new ArrayList<Attribute>(); attrs.add(new Attribute("commonname", "test1_user1")); attrs.add(new Attribute("password", "password23".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(); } }
次の例では、ユーザーへのハンドルを取得し、変更する方法を示します。
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(); } }
次の例では、簡易ユーザー検索と複合ユーザー検索を示します。
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(); } }
次の例では、グループを作成および削除する方法を示します。
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; }
次の例では、グループへのハンドルを取得する方法を示します。
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; }
次の例では、複数のグループを返す検索フィルタを示します。
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(); } }
次の例では、グループに対してユーザーを追加および削除する方法を示します。
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(); } }
アイデンティティ・ディレクトリAPI使用時のSecure Sockets Layer (SSL)構成の詳細は、「アイデンティティ・ストア用のSSLの構成」を参照してください。