| Oracle® Fusion Middleware Oracle Platform Security Servicesによるアプリケーションの保護 12c (12.1.3) E59413-03 |
|
![]() 前 |
![]() 次 |
この章では、アイデンティティ・ディレクトリAPIを使用して、アイデンティティ・ストアにアクセスして操作する方法について説明します。
この章の内容は次のとおりです。
アイデンティティ・ディレクトリAPIを使用すると、アプリケーションは、基礎となるアイデンティティ・リポジトリの種類を問わず、統一的で移植可能な方法でアイデンティティ情報(ユーザーやその他のエンティティ)にアクセスすることができます。
アイデンティティ・ディレクトリAPIの特徴:
柔軟性が高い
標準スキーマおよび特定のスキーマを持つ様々なアイデンティティ・ストアをサポートし、クライアントによって完全に構成可能
ユーザーおよびグループの取得と管理をサポートする
拡張可能であり、新しいエンティティ・タイプおよびそれらのエンティティ間の関係の定義をサポートする
堅牢であり、高可用性/フェイルオーバー・サポートを提供する
アイデンティティ・ディレクトリAPIはIdentity Governance Frameworkを使用し、このフレームワークのすべての利点を提供することにより、個人情報(PII)、アクセス権限、属性およびその他のエンティティなどのアイデンティティ関連の情報が使用および格納され、組織間で伝播される方法を制御することを可能にします。
この項では、アイデンティティ・ディレクトリAPIによってサポートされている機能について説明します。
ユーザー・エンティティに対する機能
ユーザーに対して次の機能がサポートされています。
ユーザーに対する作成、読取り、更新、削除(CRUD)の操作の実行
次の手順を実行します。
ユーザー属性の取得と設定
アイデンティティ・ストアのネイティブ認証メカニズムでのユーザーの認証
ユーザーが属するグループの取得(オプションで、ネストされたグループも含む)
グループのメンバーとしてのユーザーの追加
ユーザー・パスワードの変更
ユーザー・パスワードの変更の強制
ユーザー状態(有効/無効、ロックアウト、パスワード変更が必要)の取得と設定
グループ・エンティティに対する機能
グループに対して次の機能がサポートされています。
グループに対するCRUD操作の実行
次の手順を実行します。
属性の取得と設定
グループのメンバーの取得と検索
グループが属するグループの取得(オプションで、ネストされたグループも含む)
グループが別のグループのメンバーであるかどうかの判別
複数の値を持つ属性のサポート
静的グループおよび動的グループのサポート
表21-1に、アイデンティティ・ディレクトリAPIのクラスをリストします。
表21-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 |
様々な基準によりユーザーを作成、削除、検索するためのメソッドを含みます。 |
アイデンティティ・ディレクトリの構成は、論理的なエンティティ構成と物理的なアイデンティティ・ストア構成の組合せになります。
論理エンティティ構成を使用するアイデンティティ・ディレクトリは次の場所に格納されています。
DOMAIN_HOME/config/fmwconfig/ids-config.xml
デフォルトのアイデンティティ・ディレクトリに対する物理的なアイデンティティ・ストア構成は次の場所にあります。
DOMAIN_HOME/config/fmwconfig/ovd/default
デフォルトのアイデンティティ・ディレクトリでは、OPSS (WebLogic認証プロバイダまたはjps-config.xml)で構成されているものと同じアイデンティティ・ストア・プロパティ(つまり、ホスト、ポート、資格証明、検索ベース、作成ベース、名前属性など)が使用されます。詳細は、第F.2.4項「LDAPアイデンティティ・ストアのプロパティ」を参照してください。
この項では、アプリケーションがアイデンティティ・ディレクトリ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();
ユーザーとグループに対して、作成、取得、更新および削除(CRUD)操作を実行できます。
ユーザーに対する基本的な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)
グループに対する基本的な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)
この項では、次のアイデンティティ・ディレクトリAPIの使用例を紹介します。
アイデンティティ・ディレクトリへのハンドルを初期化し、取得するには、次のようにします。
/**
* 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();
}
このサンプル・コードでは、アイデンティティ・ストア内にユーザーを作成します。
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;
}
このサンプル・コードでは、アイデンティティ・ストアからユーザーを取得します。
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")));
// 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();
}
}
このサンプル・コードではグループを作成します。
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 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 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の使用時のSSL構成の詳細は、第8.5項「アイデンティティ・ストア・サービス向けSSLの構成」を参照してください。