ヘッダーをスキップ
Oracle® Fusion Middleware Identity Governance Framework開発者ガイド
11g リリース1(11.1.1)
B66695-02
  目次へ移動
目次

前
 
次
 

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

この章では、Identity Governance Framework Identity Directory API (アイデンティティ・ディレクトリAPI)およびIdentity Directory Serviceのアーキテクチャと主要な機能について説明します。アイデンティティ・ディレクトリAPIは、ユーザー、グループおよび組織へのアクセスと管理をサポートします。また、新しいエンティティ・タイプおよびそれらのエンティティ間で定義されたリレーションシップをサポートするように拡張することもできます。この章の内容は次のとおりです。

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

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

このAPIは、Identity Governance Frameworkを使用し、Identity Governanceのすべての利点を提供します。このAPIはJava EEおよびJava SEの両方のモードで使用できます。Identity Governance Frameworkの詳細は、第1章「Identity Governance Frameworkの概要」を参照してください。

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

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

2.1.1 Identity Directory Serviceについて

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

  • 一意の名前 (IDS名)

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

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

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

図2-2は、アイデンティティ・ディレクトリAPIの論理的なアーキテクチャを示します。

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

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

図2-2は、アイデンティティ・ディレクトリAPIのコンポーネント間のリレーションシップを示します。

図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 論理的なエンティティ構成

表2-1は、論理的なエンティティ構成のプロパティについて説明しています。

表2-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は、論理的な属性を説明します。

表2-2 論理的なエンティティ属性

名前 説明

name

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

dataType

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

description

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

readOnly

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

pwdAttr

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


表2-3は、論理的なエンティティ定義ごとに必要なプロパティを説明します。

表2-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-4は、論理的なエンティティ・リレーションシップ定義ごとに必要なプロパティを説明します。

表2-4 論理的なエンティティ・リレーションシップのプロパティ

名前 説明

name

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

type

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

fromEntity

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

fromAttr

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

toEntity

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

toAttr

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

recursive

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


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

表2-5は、物理的なアイデンティティ・ストア構成のプロパティについて説明します。

表2-5 物理的なアイデンティティ・ストア構成のプロパティ

名前 説明

HostおよびPort

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

Directory Type

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

Bind DNおよびPassword

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


2.2.3 オペレーション構成

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

表2-6は、オペレーション構成のエンティティを説明します。

表2-6 オペレーション構成のエンティティ

名前 説明

entity.searchbase

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

entity.createbase

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

entity.name.attr

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

entity.filter.objclasses

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

entity.create.objclasses

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


2.3 設計に関する推奨事項

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

2.3.1 defaultFetch属性を少なくする

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

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

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

2.4

この項では、次のコード・サンプルを示します。

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

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 ユーザーの認証

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

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

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