プライマリ・コンテンツに移動
Oracle® Fusion Middleware Identity Governance Frameworkによるアプリケーションの開発
12c (12.2.1.1)
E79304-01
目次へ移動
目次

前
前へ
次
次へ

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

アイデンティティ・ディレクトリAPIは、ユーザー、グループおよび組織へのアクセスと管理をサポートします。また、新しいエンティティ・タイプおよびそれらのエンティティ間で定義されたリレーションシップをサポートするように拡張することもできます。

次の各トピックで、Identity Governance Framework、アイデンティティ・ディレクトリAPIおよびIdentity Directory Serviceのアーキテクチャと主要な機能について説明します。

注意:

Oracle® Fusion Middleware Oracle Platform Security Servicesによるアプリケーションの保護

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

アイデンティティ・ディレクトリAPIは、アイデンティティ管理アプリケーションがアイデンティティ情報にアクセスし、管理するためのサービスを提供します。柔軟性のあるこのAPIは、クライアントによって完全に構成可能であり、標準および固有のスキーマを持つ様々なアイデンティティ・ストアをサポートします。さらに堅牢であり、高可用性およびフェイルオーバー・サポートの両方を提供します。

このAPIは、Identity Governance Frameworkを使用し、Identity Governanceによるアイデンティティ情報の規制および制御がもたらすすべての利点を提供します。このAPIはJava EEおよびJava SEの両方のモードで使用できます。Identity Governance Frameworkの詳細は、Identity Governance Frameworkの概要を参照してください。

APIでサポートされるアクションは次のとおりです。

  • ユーザー、グループ、組織のエンティティおよび汎用エンティティに対する作成/読取り/更新/削除(CRUD)操作の実行

  • ユーザー・アカウント状態の取得操作

  • アイデンティティ・ディレクトリAPIの構成の共有

  • Oracle Internet Directory、Oracle Unified Directory、Oracle Directory Server EE、Active Directoryなどのディレクトリ・サーバーのサポート

Identity Directory Serviceには次のものが含まれます。

  • アイデンティティ・ディレクトリAPI

    ドメイン・アイデンティティ・ストアであるディレクトリ・サーバー内でアイデンティティ情報にアクセスし、管理する方法を提供します。エンティティ定義、エンティティ・リレーションシップ、およびその物理的なアイデンティティ・ストアの詳細は、アイデンティティ・ディレクトリの構成APIまたはMbeanを使用して構成できます。ディレクトリ・サービス・インスタンスの機能は、ゲッター・メソッドを使用して問い合せることができます。

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

    アイデンティティ・ディレクトリAPIの構成には、論理的なエンティティ構成と物理的なアイデンティティ・ストア構成が含まれます。

この項では、次の項目について説明します。

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

Identity Directory Serviceの初期化にはアイデンティティ・ディレクトリAPIを使用します。

Identity Directory Serviceは、アイデンティティ管理製品がアイデンティティ・ディレクトリにアクセスし、管理するために使用する共通サービスです。Identity Directory Serviceは、異なるアイデンティティ・ストアに格納されているユーザーおよびグループ情報にアクセスし、それらを変更するためのインタフェースを提供します。アイデンティティ・ディレクトリはIdentity Directory Serviceのインスタンスであり、次のものが含まれています。

  • 一意の名前 (IDS名)

  • 論理的なエンティティ構成

  • 物理的なアイデンティティ・ストア構成

アイデンティティ・ストア・サービスとも呼ばれるIdentity Directory Serviceの詳細は、Oracle® Fusion Middleware Oracle Platform Security Servicesによるアプリケーションの保護を参照してください。

2.1.2 Identity Directory Serviceのアーキテクチャ

アイデンティティ・ディレクトリ・サービスAPIを使用するには、アイデンティティの統合方法と使用方法を理解することが重要です。

図2-1に、の論理アーキテクチャを示します。

図2-1 アイデンティティ・ディレクトリAPIのアーキテクチャ

図2-1の説明が続きます
「図2-1 アイデンティティ・ディレクトリAPIのアーキテクチャ」の説明

図2-2に、のコンポーネント間の関係を示します。

図2-2 アイデンティティ・ディレクトリAPIのコンポーネント

図2-2の説明が続きます
「図2-2 アイデンティティ・ディレクトリAPIのコンポーネント」の説明

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

アイデンティティ・ディレクトリAPIは、異なるアイデンティティ・ストアに格納されているユーザーおよびグループ情報にアクセスし、それらを変更するためのインタフェースを提供します。

Identity Directory Serviceの構成は、論理的なエンティティ構成、物理的なアイデンティティ・ストア構成およびオペレーション構成の組合せになります。

論理的なエンティティ構成およびオペレーション構成は、ids-config.xmlに格納されています。このファイルは、jps-config.xmlと同じディレクトリにあります。たとえば、Java EE環境では次の場所にあります。

DOMAIN_HOME/config/fmwconfig/ids-config.xml

物理的なアイデンティティ・ストア構成は、ovd/ids/adapters.os.xmlにあります。たとえば、ovdディレクトリは、Java EE環境では次の場所にあります。

DOMAIN_HOME/config/fmwconfig

この項では、次の項目について説明します。

2.2.1 Identity Directory Serviceの論理的なエンティティ構成

Identity Directory Serviceの構成は、論理的なエンティティ構成、物理的なアイデンティティ・ストア構成およびオペレーション構成の組合せになります。

次の各トピックで、Identity Directory Serviceの論理的なエンティティ構成について説明します。

2.2.1.1 論理的なエンティティ構成のプロパティ

論理的なエンティティ構成のプロパティに留意する必要があります。


名前 説明

name

Identity Directory Serviceを一意に識別する名前です。

description

Identity Directory Serviceの詳細な説明です。

ovd.context

有効な値はdefaultまたはidsです。OPSSで構成されている同じアイデンティティ・ストアに接続するには、defaultを使用します。OPSSに依存せず構成された物理的なアイデンティティ・ストアに接続するには、idsを使用します。デフォルトのアイデンティティ・ディレクトリ(userroleおよびidxuserrole)のみdefault値を使用します。

app.name

Identity Directory Serviceの構成対象である特定のアプリケーションを指定するプロパティです(オプション)。


2.2.1.2 論理的なエンティティ構成の属性

次の表に、論理的なエンティティ属性を示します。


名前 説明

name

論理的な属性の名前です。

dataType

有効なデータ・タイプの値は、stringbooleanintegerdoubledatetimebinaryx500nameおよびrfc822nameです。

description

論理的な属性の詳細な説明です。

readOnly

デフォルトはfalseです。属性が読取り専用の場合はtrueを使用します。

pwdAttr

デフォルトはfalseです。属性がパスワード属性の場合はtrueを使用します。


注意:

12c (12.1.3)リリース以降、アイデンティティ・ディレクトリAPIは、エンティティ属性パススルーをサポートします。パススルーをサポートする場合、属性定義(論理的なエンティティ構成の属性で説明)およびエンティティ定義の下の属性参照(論理的なエンティティ定義のプロパティで説明)に各属性をすべて含める必要はありません。

IDS APIでは、追加、変更、リクエスト済属性、または検索フィルタ操作での任意の属性を許可します。エンティティ定義は、バックエンド・アイデンティティ・ストアとは異なる論理的な属性名を使用してエンティティ関係を定義するための、または属性のデフォルトのフェッチのための、属性の最小限のセットを保持できます。

入力属性がアイデンティティ・ストア・スキーマにない場合、IDS APIはアイデンティティ・ストアによってスローされたエラーを返します。

2.2.1.3 論理的なエンティティ定義のプロパティ

論理的なエンティティ定義ごとに必要なプロパティに留意する必要があります。


名前 説明

name

エンティティの名前。

type

有効なエンティティの値は、usergrouporgおよびotherです。

idAttr

エンティティを一意に識別する論理的な属性です。

create

このエンティティの作成が許可されている場合はtrueを使用します。そうでない場合はfalseを使用します。

modify

このエンティティの変更が許可されている場合はtrueを使用します。そうでない場合はfalseを使用します。

delete

このエンティティの削除が許可されている場合はtrueを使用します。そうでない場合はfalseを使用します。

search

このエンティティの検索が許可されている場合はtrueを使用します。そうでない場合はfalseを使用します。

Attribute References

次の詳細を含むエンティティ属性のリファレンスのリストです。

  • name: 論理的な属性の名前。

  • defaultFetch: デフォルト値はtrueです。属性がデフォルトでフェッチされる場合はtrueを使用します。たとえば、アイデンティティ・ディレクトリAPIを使用してエンティティを読み取る場合、リクエストした属性にこの属性が含まれていなくても、この属性値はアイデンティティ・ストアからフェッチされます。

  • filter: 検索フィルタのタイプです。有効な値として、nonedynamicequalsnotequalsbeginswithcontainsdoesnotcontainendswithgreaterequallessequalgreaterthanおよびlessthanのいずれかの値を持ちます。noneはフィルタのサポートがないことを意味します。


2.2.1.4 論理的なエンティティ・リレーションシップのプロパティ

論理的なエンティティ・リレーションシップ定義ごとに必要なプロパティに留意する必要があります。


名前 説明

name

エンティティ・リレーションシップの名前です。

type

有効なエンティティの値は、OneToOneOneToManyManyToOneおよびManyToManyです。

fromEntity

エンティティ・リレーションシップの最初のエンティティの名前です。

fromAttr

最初のエンティティの属性です。この属性値は、リレーションシップの2番目のエンティティに関連します。

toEntity

エンティティ・リレーションシップの2番目のエンティティの名前です。

toAttr

2番目のエンティティの属性です。fromAttrプロパティの値は、2番目のエンティティのこの属性にマップされます。

recursive

エンティティ・リレーションシップが再帰的な場合はtrueを使用します。デフォルトはfalseです。


2.2.2 Identity Directory Serviceの物理的なアイデンティティ・ストア構成

Identity Directory Serviceの物理的なアイデンティティ・ストア構成に留意する必要があります。

次の表に、物理的なアイデンティティ・ストア構成のプロパティを示します。


名前 説明

HostおよびPort

アイデンティティ・ストアのホストおよびポートの情報です。フェイルオーバー用に代替ホストおよびポートの詳細を設定することもできます。

Directory Type

ディレクトリのタイプです。有効な値は、OIDACTIVE_DIRECTORYIPLANETEDIRECTORYOPEN_LDAPWLS_OVDおよびOUDです。

Bind DNおよびPassword

ディレクトリに接続するための資格証明です。


2.2.3 Identity Directory Serviceのオペレーション構成

Identity Directory Serviceのオペレーション構成を参照する必要があります。

オペレーション構成には、主に、各エンティティのbasename attributeおよびobjectclassの構成が含まれます。

次の表に、オペレーション構成のエンティティを示します。


名前 説明

entity.searchbase

エンティティを検索する必要のあるコンテナです。

entity.createbase

新しいエンティティが作成されるコンテナです。

entity.name.attr

エンティティのRDN属性です。

entity.filter.objclasses

このエンティティの検索時に使用されるobjectclassフィルタです。

entity.create.objclasses

この新しいエンティティの作成時に追加されるobjectclassesです。


2.3 アイデンティティ・ディレクトリAPIの設計に関する推奨事項

新しいアイデンティティ・ディレクトリAPIを設計するときは、推奨事項に留意する必要があります。

次の各トピックで、推奨事項について説明します。

2.3.1 defaultFetch属性の使用を最小限に抑える

新しいアイデンティティ・ディレクトリを構成するときは、エンティティ属性の数をできるかぎり少なくする必要があります。

エンティティ属性はdefaultFetchの値によって定義されます。また、jpegphotoのように値が大きい属性は、defaultFetchの値をfalseで構成します。これは、エンティティをバックエンドから読み取るたびに、すべてのdefaultFetch属性がバックエンド・ディレクトリから取得されるためです。defaultFetch属性が多すぎるとパフォーマンスに影響を与えます。

2.3.2 アイデンティティ・ディレクトリの初期化を1回にする

アイデンティティ・ディレクトリは1回のみ初期化する必要があります。

アイデンティティ・ディレクトリの初期化では、ArisIdスタック全体の初期化にかなりの負荷がかかります。そのため、アプリケーションでのアイデンティティ・ディレクトリの初期化は1回のみ、できれば起動時に実行し、全体を通して1つのハンドルのみを使用することをお薦めします。

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

アイデンティティ・ディレクトリAPIに関連する各種の操作を実行するには、次のサンプル・コードを使用します。

次の各トピックで、アイデンティティ・ディレクトリAPIに関連する操作について説明します。

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

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

import oracle.igf.ids.UserManager;
import oracle.igf.ids.GroupManager;
import oracle.igf.ids.config.OperationalConfig;
import oracle.igf.ids.IdentityDirectoryFactory;
import oracle.igf.ids.IdentityDirectory;
import oracle.igf.ids.IDSException;


public class IdsSample {

    private IdentityDirectory ids;
    private UserManager uMgr;
    private GroupManager gMgr;

    public IdsSample() throws IDSException {
        // Set Operational Config
        OperationalConfig opConfig = new OperationalConfig();

        // Set the application credentials (optional).  This
 overrides the credentials set in
        // physical ID store configuration 
opConfig.setApplicationUser("cn=user1,dc=us,dc=example,dc=com");
opConfig.setApplicationPassword("password".toCharArray());

        // Set search/crate base, name, objclass, etc. config
 (optional).  This overrides default operational configuration
 in IDS
        opConfig.setEntityProperty("User", opConfig.SEARCH_BASE,
 "dc=us,dc=example,dc=com");
        opConfig.setEntityProperty("User", opConfig.CREATE_BASE,
 "dc=us,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=groups,dc=us,dc=example,dc=com");
        opConfig.setEntityProperty("Group", opConfig.CREATE
_BASE, "cn=groups,dc=us,dc=example,dc=com");
        opConfig.setEntityProperty("Group", opConfig.FILTER
_OBJCLASSES, "groupofuniquenames");
        opConfig.setEntityProperty("Group", opConfig.CREATE
_OBJCLASSES, "groupofuniquenames");

        // Get IdentityDirectory "ids1" configured in IDS config
        IdentityDirectoryFactory factory = new
 IdentityDirectoryFactory();
        ids = factory.getIdentityDirectory("ids1", opConfig);

        // Get UserManager and GroupManager handles
        uMgr = ids.getUserManager();
        gMgr = ids.getGroupManager();
    }
}

注意:

認証プロバイダとしてTivoliを使用する場合は、認証プロバイダのタイプとしてOPEN_LDAPを選択する必要があります。これは、Oracle WebLogic ServerでTivoliがサポートされていないためです。

Tivoliのディレクトリ・ハンドルを取得するようにIdentity Governance FrameworkまたはIdentity Directory Serviceを初期化すると、生成されたadapters.os_xmlファイルに次のパラメータが含まれています。

<param name="mapAttribute" value="orclGUID=entryUUID"/>

このTivoliのシナリオでは、次のようにorclGUID属性をibm-entryUUIDにマップする必要があります。

<param name="mapAttribute" value="orclGUID=ibm-entryUUID"/>

これらの変更を反映するため、adapters.os_xmlファイルを手動で更新する必要があります。さらに、属性マッピングの更新を有効にするためにOracle WebLogic Serverを再起動する必要があります。

2.4.2 JPSコンテキストからのアイデンティティ・ディレクトリ・ハンドルの初期化と取得

JPSコンテキストからアイデンティティ・ディレクトリ・ハンドルを初期化して取得するには、次のコード・サンプルを使用します。

import oracle.igf.ids.UserManager;
import oracle.igf.ids.GroupManager;
import oracle.igf.ids.config.OperationalConfig;
import oracle.igf.ids.IdentityDirectoryFactory;
import oracle.igf.ids.IdentityDirectory;
import oracle.igf.ids.IDSException;

import oracle.security.jps.JpsContext;
import oracle.security.jps.JpsContextFactory;
import oracle.security.jps.service.idstore.IdentityStoreService;

public class IdsSample {

    private IdentityDirectory ids;
    private UserManager uMgr;
    private GroupManager gMgr;

    public IdsSample() throws IDSException {

        // Get IdentityDirectory from JpsContext
        try {
            JpsContext context =
JpsContextFactory.getContextFactory().getContext();
            IdentityStoreService idstore = (IdentityStoreService)
context.getServiceInstance(IdentityStoreService.class);
            ids = idstore.getIdentityStore();
        } catch (Exception e) {
            throw new IDSException(e);
        }        

 // Get UserManager and GroupManager handles
        uMgr = ids.getUserManager();
        gMgr = ids.getGroupManager();
    }
}

2.4.3 メモリー内アイデンティティ・ディレクトリ・ハンドルの初期化と取得

メモリー内アイデンティティ・ディレクトリ・ハンドルを初期化して取得するには、次のコード・サンプルを使用します。

import java.util.ArrayList;
import java.util.List;

import oracle.igf.ids.UserManager;
import oracle.igf.ids.GroupManager;
import oracle.igf.ids.config.AttributeDef;
import oracle.igf.ids.config.AttributeRef;
import oracle.igf.ids.config.EntityDef;
import oracle.igf.ids.config.EntitiesConfig;
import oracle.igf.ids.config.EntityRelationship;
import oracle.igf.ids.config.IdentityStoreConfig;
import oracle.igf.ids.config.OperationalConfig;
import oracle.igf.ids.IdentityDirectoryFactory;
import oracle.igf.ids.IdentityDirectory;
import oracle.igf.ids.IDSException;

public class IdsSample {

    private IdentityDirectory ids;
    private UserManager uMgr;
    private GroupManager gMgr;
    public IdsSample() throws IDSException {

        // Add Attribute definitions
        List<AttributeDef> attrDefs = new ArrayList<AttributeDef>();
        attrDefs.add(new AttributeDef("cn", AttributeDef.DataType.STRING));
        attrDefs.add(new AttributeDef("firstname", AttributeDef.DataType.STRING));
        attrDefs.add(new AttributeDef("sn", AttributeDef.DataType.STRING));
        attrDefs.add(new AttributeDef("telephonenumber",
 AttributeDef.DataType.STRING));
        attrDefs.add(new AttributeDef("uid", AttributeDef.DataType.STRING));
        attrDefs.add(new AttributeDef("uniquemember",
 AttributeDef.DataType.STRING));

        // Add User entity definition
        List<EntityDef> entityDefs = new ArrayList<EntityDef>();
        EntityDef userEntityDef = new EntityDef("User", EntityDef.EntityType.USER,
 "cn");
        userEntityDef.addAttribute(new AttributeRef("cn"));
        userEntityDef.addAttribute(new AttributeRef("firstname"));
        userEntityDef.addAttribute(new AttributeRef("sn"));
        userEntityDef.addAttribute(new AttributeRef("telephonenumber"));
        userEntityDef.addAttribute(new AttributeRef("uid"));
        entityDefs.add(userEntityDef);

        // Add Group entity definition
        EntityDef groupEntityDef = new EntityDef("Group",
 EntityDef.EntityType.GROUP, "cn");
        groupEntityDef.addAttribute(new AttributeRef("cn"));
        groupEntityDef.addAttribute(new AttributeRef("uniquemember", false,
 AttributeRef.FilterType.EQUALS));
        entityDefs.add(groupEntityDef);

        // Add Entity relationship definition
        List<EntityRelationship> entityRelations = new
 ArrayList<EntityRelationship>();
        entityRelations.add(new EntityRelationship("user_memberOfGroup",
                EntityRelationship.RelationshipType.MANYTOMANY, "User",
 "principal", "Group", "uniquemember"));
        entityRelations.add(new EntityRelationship("group_memberOfGroup",
                EntityRelationship.RelationshipType.MANYTOMANY, "Group",
 "principal", "Group", "uniquemember", true));
        EntitiesConfig entityCfg = new EntitiesConfig(attrDefs,
 entityDefs, entityRelations);


        // Create physical Identity Store configuration
        IdentityStoreConfig idStoreCfg = new IdentityStoreConfig(
            "ldap://host1:389,ldap://host2:389", "cn=orcladmin",
 "password".toCharArray(), IdentityStoreConfig.IdentityStoreType.OID);
       
 idStoreCfg.setHighAvailabilityOption(IdentityStoreConfig.HAOption.FAILOVER);
        idStoreCfg.setProperty(IdentityStoreConfig.HEARTBEAT_INTERVAL, "60");
        idStoreCfg.setProperty(IdentityStoreConfig.CONN_TIMEOUT, "30000");    //
 milli sec
        idStoreCfg.setProperty(IdentityStoreConfig.MIN_POOLSIZE, "5");
        idStoreCfg.setProperty(IdentityStoreConfig.MAX_POOLSIZE, "10");
        idStoreCfg.setProperty(IdentityStoreConfig.MAX_POOLWAIT, "1000");     //
 milli sec
        idStoreCfg.setProperty(IdentityStoreConfig.MAX_POOLCHECKS, "10");
        idStoreCfg.setProperty(IdentityStoreConfig.FOLLOW_REFERRAL, "false");
        idStoreCfg.setAttrMapping("firstname", "givenname");

        // Set operational config
        OperationalConfig opConfig = new OperationalConfig();
        opConfig.setEntityProperty(opConfig.USER_ENTITY, opConfig.SEARCH_BASE,
 "cn=users,dc=us,dc=example,dc=com");
        opConfig.setEntityProperty(opConfig.USER_ENTITY, opConfig.CREATE_BASE,
 "cn=users,dc=us,dc=example,dc=com");
        opConfig.setEntityProperty(opConfig.USER_ENTITY, opConfig.NAME_ATTR,
 "cn");
        opConfig.setEntityProperty(opConfig.USER_ENTITY, opConfig.FILTER
_OBJCLASSES, "inetorgperson");
        opConfig.setEntityProperty(opConfig.USER_ENTITY, opConfig.CREATE
_OBJCLASSES, "inetorgperson");
        opConfig.setEntityProperty(opConfig.GROUP_ENTITY, opConfig.SEARCH_BASE,
 "cn=groups,dc=us,dc=example,dc=com");
        opConfig.setEntityProperty(opConfig.GROUP_ENTITY, opConfig.CREATE_BASE,
 "cn=groups,dc=us,dc=example,dc=com");
        opConfig.setEntityProperty(opConfig.GROUP_ENTITY, opConfig.NAME_ATTR,
 "cn");
        opConfig.setEntityProperty(opConfig.GROUP_ENTITY, opConfig.FILTER
_OBJCLASSES, "groupofuniquenames");
        opConfig.setEntityProperty(opConfig.GROUP_ENTITY, opConfig.CREATE
_OBJCLASSES, "groupofuniquenames");

        // Initialize Identity Store Service
        IdentityDirectoryFactory factory = new IdentityDirectoryFactory();
        ids = factory.getIdentityDirectory("ids1", entityCfg, idStoreCfg,
 opConfig);

        // Get UserManager and GroupManager handles
        uMgr = ids.getUserManager();
        gMgr = ids.getGroupManager();
    }

}

2.4.4 ユーザーの追加

アイデンティティ・ストアにユーザーを追加できます。

次のコード・サンプルでは、アイデンティティ・ストアにユーザーを追加します。

Principal principal = null;
        
        List<Attribute> attrs = new ArrayList<Attribute>();
        attrs.add(new Attribute("commonname", "test1_user1"));
        attrs.add(new Attribute("password", "mypassword".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"));

        try {
            CreateOptions createOpts = new CreateOptions();

            principal = uMgr.createUser(attrs, createOpts);



            System.out.println("Created user " + principal.getName());

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

2.4.5 指定されたプリンシパルのユーザーの取得

指定されたプリンシパルのユーザーを取得するには、次のサンプル・コードを使用します。

User user = null;

        try {
            ReadOptions readOpts = new ReadOptions();

            user = uMgr.getUser(principal, readOpts);
            
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

2.4.6 ユーザーの変更

アイデンティティ・ディレクトリのユーザーを変更するには、次のコード・サンプルを使用します。

try {
            ModifyOptions modifyOpts = new ModifyOptions();

            List<ModAttribute> attrs = new ArrayList<ModAttribute>();
            attrs.add(new ModAttribute("description", "modified test user 1"));

            user.modify(attrs, modifyOpts);
            

            System.out.println("Modified user " + user.getName());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

2.4.7 指定されたID値のユーザーの取得

指定されたアイデンティティ値と一致するユーザーを取得するには、次のサンプル・コードを使用します。

try {
            ReadOptions readOpts = new ReadOptions();

            User user = uMgr.searchUser("tuser1", readOpts);
            
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

2.4.8 複雑な検索フィルタを使用したユーザーの検索

複雑な検索フィルタを使用してユーザーを検索するには、次のコード・サンプルを使用します。

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,
 "test"),
                  new SearchFilter("telephone", SearchFilter.Operator.CONTAINS,
 "650")),
                new SearchFilter(SearchFilter.LogicalOp.AND,
                  new SearchFilter("firstname", SearchFilter.Operator.BEGINS_WITH,
 "demo"),
                  new SearchFilter(SearchFilter.LogicalOp.OR,
                    new SearchFilter("orgunit", SearchFilter.Operator.BEGINS_WITH,
 "hr"),
                    new SearchFilter("orgunit", SearchFilter.Operator.BEGINS_WITH,
 "it"),
           
                  new SearchFilter("telephone", SearchFilter.Operator.CONTAINS,
 "650")));

            // Requesting attributes
            List<String> reqAttrs = new ArrayList<String>();
            reqAttrs.add("jpegphoto");

            SearchOptions searchOpts = new SearchOptions();
            searchOpts.setPageSize(100);
            searchOpts.setRequestedAttrs(reqAttrs);
            searchOpts.setSortAttrs(new String[] {"firstname"});

            ResultSet<User> sr = uMgr.searchUsers(filter, searchOpts);
            while (sr.hasMore()) {
                User user = sr.getNext();
                System.out.println(user.getSubjectName());
            }

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    

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

次のコード・サンプルは、ユーザー・パスワードの変更方法を示しています。

ModifyOptions modOpts = new ModifyOptions();

        try {
            user.changePassword("welcome123".toCharArray(),
 "welcome1".toCharArray(), modOpts);
            System.out.println("Changed user password");
        } catch (Exception e) {
            System.out.println("Failed to change user password");
            e.printStackTrace();
        }

2.4.10 ユーザー・パスワードのリセット

ユーザー・パスワードをリセットするには、次のサンプル・コードを使用します。

ModifyOptions modOpts = new ModifyOptions();

        try {
            user.resetPassword("welcome123".toCharArray(), modOpts);
            System.out.println("Reset user password");
        } catch (Exception e) {
            System.out.println("Failed to reset user password");
            e.printStackTrace();
        }

2.4.11 ユーザーの認証

APIを使用してユーザーを認証できます。

次のコード・サンプルは、ユーザーの認証方法を示しています。

        ReadOptions readOpts = new ReadOptions();
        try {
            User user = uMgr.authenticateUser("tuser1",
 "mypassword".toCharArray(), readOpts);   
            System.out.println("authentication success");
        } catch (Exception e) {
            System.out.println("Authentication failed. " + e.getMessage());
            e.printStackTrace();
        }

2.4.12 ユーザーの削除

ユーザーを削除するには、次のコード・サンプルを使用します。

try {
            DeleteOptions deleteOpts = new DeleteOptions();

            uMgr.deleteUser(principal, deleteOpts);
            
            System.out.println("Deleted user " + principal.getName());

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

2.4.13 グループの作成

グループを作成するには、次のサンプル・コードを使用します。

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

2.4.14 グループの検索

グループを検索するには、次のコード・サンプルを使用します。

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

2.4.15 管理チェーンの取得

次のコード・サンプルを使用して、管理チェーンの取得方法を示します。

try {
            ReadOptions readOpts = new ReadOptions();
            User user = uMgr.searchUser("tuser1", readOpts);

            SearchOptions searchOpts = new SearchOptions();
            searchOpts.setPageSize(10);
            int nLevels = 0;

            ResultSet<User> sr  = user.getManagementChain(nLevels, searchOpts);
            while (sr.hasMore()) {
                User u = sr.getNext();
                System.out.println(u.getSubjectName());
            }

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

2.4.16 ユーザーのReporteeの取得

次のコード・サンプルを使用して、ユーザーのReporteeの取得方法を示します。

// Get Reportees with target search filter
    public void getReportees() {

        try {
            ReadOptions readOpts = new ReadOptions();
            User user = uMgr.searchUser("tuser1", readOpts);

            SearchOptions searchOpts = new SearchOptions();
            searchOpts.setPageSize(20);
            int nLevels = 0;

            // get all the direct/indirect reporting of tuser1 who are
 "developers"
            SearchFilter filter = new SearchFilter("title",
 SearchFilter.Operator.CONTAINS, "developer");
            ResultSet<User> sr  = user.getReportees(nLevels, filter, searchOpts);
            while (sr.hasMore()) {
                User u = sr.getNext();
                System.out.println(u.getSubjectName());
            }

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

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

グループにメンバーを追加できます。

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

try {
            ReadOptions readOpts = new ReadOptions();
            User user = uMgr.searchUser("tuser1", readOpts);
            Group group = gMgr.searchGroup("test1_group1", readOpts);

            ModifyOptions modOpts = new ModifyOptions();
            user.addMemberOf(group, modOpts);

            System.out.println("added tuser1 as a member of test1_group1");

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

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

グループからメンバーを削除するには、次のコード・サンプルを使用します。

try {
            ReadOptions readOpts = new ReadOptions();
            User user = uMgr.searchUser("tuser1", readOpts);
            Group group = gMgr.searchGroup("test1_group1", readOpts);

            ModifyOptions modOpts = new ModifyOptions();
            group.deleteMember(user, modOpts);

            System.out.println("deleted tuser1 from the group test1_group1");

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

注意:

Identity Governance Framework/Identity Directory Serviceのグループ・メンバーシップ検索では、静的グループと動的グループの両方を評価します。ただし、メンバーシップの更新(追加/削除)は、動的グループではサポートされません。たとえば、グループからメンバーを削除する際に、そのメンバーがそのグループの動的メンバーである場合、動的グループでは削除操作がサポートされません。

2.4.19 ユーザーがメンバーとなっているすべてのグループの取得

ユーザーがメンバーとなっているグループをすべて取得するには、次のコード・サンプルを使用します。

try {
            ReadOptions readOpts = new ReadOptions();
            User user = uMgr.searchUser("tuser1", readOpts);

            SearchOptions searchOpts = new SearchOptions();
            searchOpts.setPageSize(10);
            int nLevels = 0;

            ResultSet<Group> sr  = user.getMemberOfGroups(nLevels, null,
 searchOpts);
            while (sr.hasMore()) {
                Group group = sr.getNext();
                System.out.println(group.getSubjectName());
            }

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

2.4.20 検索フィルタでの論理NOT演算子の使用

次のコード・サンプルを使用して、検索フィルタでのNOT演算子の使用方法を示します。

try {
     SearchFilter f1 = new SearchFilter("firstname", SearchFilter.Operator.BEGINS_WITH, "demo");
     SearchFilter f2 = new SearchFilter("orgunit", SearchFilter.Operator.CONTAINS, "myorg");
     f2.negate();
     SearchFilter filter = new SearchFilter(SearchFilter.LogicalOp.AND, f1, f2);

     ResultSet<User> sr = uMgr.searchUsers(filter, searchOpts);
    }