Skip Headers
Oracle® Fusion Middleware Developer's Guide for Oracle Identity Manager
11g Release 2 (11.1.2.2.0)

Part Number E27150-19
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

31 Using APIs

Oracle provides a network-aware, Java-based application programming interface (API) that exposes Services, called Utility in earlier releases, available in Oracle Identity Manager. This API is based on Plain Old Java Objects (POJO) and takes care of all the plumbing required to interact with Oracle Identity Manager. This API can be used for building clients for Oracle Identity Manager and for integrating third-party products with the Oracle Identity Manager platform.

This chapter contains these sections:

31.1 Accessing Oracle Identity Manager Services

The entry point to Oracle Identity Manager Services is through oracle.iam.platform.OIMClient class. Thor.API.tcUtilityFactory used in earlier releases is also supported. Oracle recommends using the oracle.iam.platform.OIMClient for developing clients to integrate with Oracle Identity Manager.

This section describes the following topics:

31.1.1 Using OIMClient

OIMClient is the entry point for accessing the services available in Oracle Identity Manager. You use the following sequence of steps when using OIMClient:

  1. Create an instance of OIMClient with the environment information required to connect to Oracle Identity Manager application, as shown:

    Hashtable env = new Hashtable();
    
    env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
    env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, t3://OIM_HOSTNAME:OIM_PORT);
    OIMClient oimClient = new OIMClient(env);
    

    Here, replace OIM_HOSTNAME with the host name on which Oracle Identity Manager is deployed and OIM_PORT with the port number.

  2. Login to the Oracle Identity Manager with the appropriate credentials, as shown:

    oimClient.login(OIM_USERNAME, OIM_PASSWORD);
    
  3. Lookup a service, as shown:

    UserManager usermgr = oimClient.getService(UserManager.class);
    OR
    tcLookupOperationsIntf lookupIntf = oimClient.getService(tcLookupOperationsIntf.class);
    
  4. Call method on a service, as shown:

    HashMap userAttributes = new HashMap();
    ……………..
    UserManagerResult result = userMgr.create(new User(null, userAttributes));
    

31.1.2 Using the tcUtilityFactory

Earlier releases of Oracle Identity Manager supports tcUtilityFactory for accessing Oracle Identity Manager Services (or Utilities, as they are called in legacy releases). tcUtilityFactory continues to be supported. However, as mentioned earlier, Oracle recommends using OIMClient for building all client applications for Oracle Identity Manager.

You use the following sequence of steps when using tcUtilityFactory:

  1. Create an instance of tcUtilityFactory with the environment information, such as username and password, as shown:

    tcUtilityFactory ioUtilityFactory = new tcUtilityFactory(env, "OIM_USERNAME", "OIM_PASSWORD");
    
  2. Look up utility or service by providing the fully qualified name of the utility, as shown:

    tcUserOperationsIntf moUserUtility = (tcUserOperationsIntf)ioUtilityFactory.getUtility("Thor.API.Operations.tcUserOperationsIntf");
    
  3. Run operations on the utility, as shown:

    Hashtable mhSearchCriteria = new Hashtable();
    mhSearchCriteria.put("Users.First Name", psFirstName);
    tcResultSet moResultSet = moUserUtility.findUsers(mhSearchCriteria);
    

31.1.3 Using OIMClient and tcUtilityFactory in Integrated Deployments

In Oracle Identity Manager deployment that is integrated with Access Manager (OAM), OIMSignatureAuthenticator is not configured in the Oracle Identity Manager domain's security realm. Therefore, all the custom or partner applications that you want to integrate with Oracle Identity Manager must not use signature-based login to Oracle Identity Manager. Instead, you must follow any one of the following approaches:

  • Oracle Platform Security Services (OPSS) Framework: If the partner or client application is a J2EE application based on Fusion Middleware stack, then it can use the following from OPSS framework:

    Note:

    See "Introduction to Oracle Platform Security Services" in the Oracle Fusion Middleware Application Security Guide for information about OPSS and its main features

    • OPSS credential store: This allows credentials to be managed (store, retrieve, modify) in a secure manner. You can store the password in the OPSS credential store, and retrieve it while performing a Oracle Identity Manager client login by using user ID and password. See "Managing the Credential Store" in the Oracle Fusion Middleware Application Security Guide for more information about OPSS credential store.

    • OPSS SubjectSecurity API: If a partner application wants to invoke Oracle Identity Manager EJB/Service APIs with a higher privilege, such as system administrator user, then OPSS SubjectSecurity API can be used. The following sample partner application code tries to invoke Oracle Identity Manager API with higher privilege:

      See Also:

      Oracle Fusion Middleware Java API Reference for Oracle Platform Security Services for detailed information about the SubjectSecurity API

      //Get ActionExecutor for OIM System administrator, xelsysadm
      ActionExecutor actionExecutor = SubjectSecurity.getInstance().getActionExecutor("xelsysadm");
      actionExecutor.execute(new PrivilegedAction<Object>() {
        public Object run() {
             //OIM EJB method invocation goes here….
                         Hashtable env = new Hashtable();
            //serverURL – OIM server's RMI URL
                         // ctxFactory – WLS/WAS context factory class
               env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, serverURL);
               env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL,ctxFactory);
               OIMClient client = new OIMClient(env);
        //Invoking EJB service method as "xelsysadm"
               RequestService reqSrvc = client.getService(RequestService.class);
               reqSrvc.getBasicRequestData("1");//1 is the request ID.
                    }
      });
      
  • If using the OPSS framework is not possible for some reason, then it is recommended to invoke the OIMClient API with user ID and password. However, it is up to the client or partner to store and manage the Oracle Identity Manager user's password in a secure manner.

31.2 Oracle Identity Manager Services

The Oracle Identity Manager API provides access to services available in Oracle Identity Manager. Because the APIs in Oracle Identity Manager 11g Release 1(11.1.1) onwards and the legacy APIs use different conventions, this section discusses them separately in the following topics:

31.2.1 Services in Oracle Identity Manager 11g

Services in Oracle Identity Manager 11g onwards are based on the following conventions:

  • Package Names: Services are in packages whose names end with "api", for example:

    oracle.iam.request.api
    oracle.iam.identity.usermgmt.api
    
  • Service Interface Names: Services introduced in 11g typically use the naming convention of "*Service", for example:

    oracle.iam.request.api.RequestService
    oracle.iam.selfservice.self.selfmgmt.api.AuthenticatedSelfService
    

    Some Identity Administration APIs use the "*Manager" naming convention for their APIs, for example:

    oracle.iam.identity.usermgmt.api.UserManager
    

Some new services introduced in Oracle Identity Manager 11g Release 2 (11.1.2.2.0) are:

oracle.iam.api.OIMService
oracle.iam.platform.authopss.api.AuthorizationService
oracle.iam.provisioning.api.ProvisioningService
oracle.iam.provisioning.api.ApplicationInstanceService

31.2.2 Legacy Services or Utilities

Legacy services, also called utilities, follow the following naming conventions

  • Package Names: All legacy APIs are in Thor.API.Operations package.

  • Service Interface Names: Service names are of the form "*Intf", for example, Thor.API.Operations.tcImportOperationsIntf.

See Also:

Oracle Fusion Middleware Java API Reference for Oracle Identity Manager for a full list of services available in Oracle Identity Manager. You can use the naming conventions above to find the APIs.

31.3 Commonly Used Services

Table 31-1 lists some commonly used services in Oracle Identity Manager.

Table 31-1 Commonly Used Services

Service Name Description

UserManager

Provides operations for user management, such as create, search, modify, and delete users

RequestService

Provides operations to submit, withdraw, close, and search requests.

RoleManager

Provides operations for role management such as create, search, modify, and delete roles. In addition, this service provides operations for management of role members and relationships between roles.

OrganizationManager

Provides operations for organization management such as create, search, modify, delete, enable, and disable organizations.

oracle.iam.api.OIMService

Provides method to perform an operation in Oracle Identity Manager. You can pass an intent while calling API of this service. Intent here can be request or direct.


31.3.1 Mapping Between Legacy and New Services

In Oracle Identity Manager, some of the legacy APIs have been rewritten by using new architecture and the corresponding utility services or interface classes have been changed. Table 31-2 provides a high-level correspondence between the legacy and new interfaces.

Table 31-2 Mapping Between Legacy and New Services

Legacy Service New Service

Thor.API.Operations.tcUserOperationsIntf

oracle.iam.identity.usermgmt.api.UserManager

Thor.API.Operations.tcGroupOperationsIntf

Note: The Group Manager APIs related all delegated admin APIs for adding and removing admins have been deprecated.

oracle.iam.identity.rolemgmt.api.RoleManager

Thor.API.Operations.tcOrganizationOperationsIntf

oracle.iam.identity.orgmgmt.api.OrganizationManager

Thor.API.Operations.tcRequestOperationsIntf

oracle.iam.request.api.RequestService

Thor.API.Operations.tcSchedulerOperationsIntf

oracle.iam.scheduler.api.SchedulerService

Thor.API.Operations.tcEmailOperationsIntf

oracle.iam.notification.api.NotificationService


31.4 Developing Clients for Oracle Identity Manager

This section includes the following topics:

31.4.1 Prerequisites for Developing Clients

The following prerequisites must be met for developing clients for Oracle Identity Manager:

  • Java Development Kit (JDK) 1.6 installed and set in the path

  • ANT 1.7 installed and set in the path

31.4.2 Setup and Configuration

Oracle Identity Manager package contains a ZIP file that contains the required libraries and configuration files for developing clients.

To run an application client for Oracle Identity Manager:

  1. Copy OIM_ORACLE_HOME/server/client/oimclient.zip to the computer on which you want to develop the client, for example the oimclient/ directory. This directory is referred to as OIM_CLIENT_HOME in this document. Extract the ZIP file. Note that the oimclient.zip file consists of the conf, lib, and oimclient.jar.

  2. Copy the following files manually after unzipping oimclient.zip in the remote machine:

    1. Copy $OIM_HOME/server/client/oimWASClient.ear to the same location of oimclient.jar.

    2. Copy $OIM_HOME/server/client/config/xl.policy to the conf directory.

    3. Copy $OIM_HOME/server/client/config/authws.conf to the conf directory.

    4. Copy $MW_HOME/oracle_common/modules/oracle.jrf_11.1.1/jrf-api.jar to the lib directory.

  3. Copy the application server-specific client library to the OIM_CLIENT_HOME/lib/ directory. For Oracle WebLogic Server, wlfullclient.jar is the client library. It is created in MIDDLEWARE_HOME/WL_HOME/server/lib/ directory, for example, /scratch/beahome/wlserver_10.3/server/lib/. Check if wlfullclient.jar is present. If not, then you must generate one by using the jarbuilder tool. See Oracle WebLogic Server documentation on how to generate wlfullclient.jar.

  4. Pass the following system properties for running API clients:

    • java.security.auth.login.config=OIM_CLIENT_HOME/conf/authwl.conf

    • APPSERVER_TYPE=wls

  5. Make sure following jars are in the class path:

    • commons-logging.jar

    • spring.jar

    • oimclient.jar

    • wlfullclient.jar

    • jrf-api.jar

31.5 Working With Legacy Oracle Identity Manager APIs

This section describes the following topics:

31.5.1 Using a Result Set Object

Legacy Oracle Identity Manager APIs extensively use the tcResultSet interface. The Thor.API.tcResultSet interface is a data structure that stores records retrieved from the database. Methods in the Oracle Identity Manager API that must return a set of data use a result set. This is a two-dimensional data structure in which the columns correspond to the attributes and rows correspond to the entities. For example, a result set that is returned by the method that searches for users, each row would represent data pertaining to one user, and each column in the row would be an attribute for that user.

You can scroll through the result set and retrieve individual entries corresponding to particular attributes by using the various methods provided. To locate a particular row in the result set, use the goToRow() method with the row number as a parameter. To retrieve the values for the columns from a row, use appropriate accessor methods, such as getStringValue(). To obtain the value from a specific column, pass the column name as a parameter to the accessor method. The column name is the descriptive code defined in the Oracle Identity Manager Meta-Data system.

The following table shows some sample metadata values. This mapping is based on lookup codes and can be looked up in the Design Console by using the Lookup Definition Form.

Column Code Explanation

IT Resources.Name

The name of an IT resource

Process Definition.Name

The name of a provisioning process


Note:

Keep track of the result set objects that are retrieved, because they will be required when updating an existing record.

The following is an example of how to use a result set. This example obtains a result set by calling the findAllUsers() method. This method searches for all users matching certain criteria:

tcResultSet moResultSet = moUserUtility.findAllUsers(mhAttribs);

To check if the findAllUsers() method returned any records, use the isEmpty() method, for example:

boolean mbEmpty = moResultSet.isEmpty();

To retrieve the number of records found, use the getRowCount() method. If no records are found, then the method returns 0. The following is an example:

int mnNumRec = moResultSet.getRowCount();

To select a particular record in the system, use the goToRow() method:

moResultSet.goToRow(5);

To retrieve the values of attributes from the current row, use the appropriate accessor method, for example:

String msUserLastName = moResultSet.getStringValue("Users.Last Name");

31.5.2 Handling Oracle Identity Manager Exceptions

The API methods throw Oracle-defined Java exceptions. Instead of using the getMessage() method on the exception object received, you can access the isMessage internal variable to retrieve the exception message.

31.5.3 Cleaning Up

The tcUtilityFactory class manages all resources used by a utility or factory instance and provides a means to release these resources after they are used.

If you instantiate and use tcUtilityFactory to obtain utility class instances, to release the resources that are associated with the utility class, call the close(utility Object) method on the factory class. If the session has ended, then call the close() method on the factory instance to release all the utility classes, the session objects, and the database objects.

If you obtain a utility class directly by using static calls, after the utility object is no longer needed, call the close(object) method on the utility object.

31.6 Code Samples

This section contains the following code samples:

31.6.1 Retrieving Oracle Identity Manager Information

Example 31-1 illustrates how to retrieve Oracle Identity Manager information. This example creates an instance of the factory class. The instance is then called several times to retrieve individual utility classes and use them to retrieve Oracle Identity Manager information.

Example 31-1 Retrieving Oracle Identity Manager Information

/*
 This class is intented to showcase some of OIM API's. These API's are 
 specific to OIM 11g release. As an example, Legacy API's usage for
 Organization is also shown. 
*/
 
 
package oracle.iam.samples;
 
 
// Role related API's
import oracle.iam.identity.rolemgmt.api.RoleManager;
import oracle.iam.identity.rolemgmt.vo.Role;
import oracle.iam.identity.exception.RoleSearchException;
import oracle.iam.identity.rolemgmt.api.RoleManagerConstants.RoleAttributeName;
import oracle.iam.identity.rolemgmt.api.RoleManagerConstants.RoleCategoryAttributeName;
 
// User related API's
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.identity.exception.UserSearchException;
import oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName;
 
// Organization Legacy API's
import Thor.API.Operations.tcOrganizationOperationsIntf;
import Thor.API.tcResultSet;
import Thor.API.Exceptions.tcAPIException; 
import Thor.API.Exceptions.tcColumnNotFoundException; 
import Thor.API.Exceptions.tcOrganizationNotFoundException; 
 
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.authz.exception.AccessDeniedException;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;
 
import java.util.*;
 
import javax.naming.NamingException;
import javax.security.auth.login.LoginException;
 
 
public class Sample {
 
     private static OIMClient oimClient;
 
     /*
      * Initialize the context and login with client supplied environment
     */
     public void init() throws LoginException {
        System.out.println("Creating client....");
        String ctxFactory = "weblogic.jndi.WLInitialContextFactory";
        String serverURL = "t3://OIM_HOSTNAME:OIM_PORT";
        String username = "xelsysadm";
        char[] password = "xelsysadm".toCharArray();
        Hashtable env = new Hashtable();
        env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL,ctxFactory);
        env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, serverURL);
 
        oimClient = new OIMClient(env);
        System.out.println("Logging in");               
        oimClient.login(username, password);
        System.out.println("Log in successful");
     }
 
     /**
     * Retrieves User login based on the first name using OIM 11g 
     * UserManager service API. 
     */
     public List getUserLogin(String psFirstName) {
        Vector mvUsers = new Vector();
        UserManager userService = oimClient.getService(UserManager.class); 
        Set<String> retAttrs = new HashSet<String>();
 
        // Attributes that should be returned as part of the search. 
        // Retrieve "User Login" attribute of the User.
        // Note: Additional attributes can be specified in a 
        // similar fashion.
        retAttrs.add(AttributeName.USER_LOGIN.getId());
 
        // Construct a search criteria. This search criteria states 
        // "Find User(s) whose 'First Name' equals 'psFirstName'".  
        SearchCriteria criteria;
        criteria = new SearchCriteria(AttributeName.FIRSTNAME.getId(), psFirstName, SearchCriteria.Operator.EQUAL);
        try {
            // Use 'search' method of UserManager API to retrieve 
            // records that match the search criteria. The return 
            // object is of type User. 
            List<User> users = userService.search(criteria, retAttrs, null);
                        
            for (int i = 0; i < users.size(); i++) {
                //Print User First Name and Login ID 
                System.out.println("First Name : " + psFirstName + "  --  Login ID : " + users.get(i).getLogin());
                mvUsers.add(users.get(i).getLogin());
            }
        } catch (AccessDeniedException ade) {
            // handle exception
        } catch (UserSearchException use) {
            // handle exception
        }
       return mvUsers;
    }
 
    /** 
     * Retrieves the administrators of an Organization based on the 
     * Organization name. This is Legacy service API usage. 
     */
    public List getAdministratorsOfOrganization(String psOrganizationName) {
        Vector mvOrganizations = new Vector();
        tcOrganizationOperationsIntf moOrganizationUtility = oimClient.getService(tcOrganizationOperationsIntf.class);
        Hashtable mhSearchCriteria = new Hashtable();
        mhSearchCriteria.put("Organizations.Organization Name", psOrganizationName);
        try {
            tcResultSet moResultSet = moOrganizationUtility.findOrganizations(mhSearchCriteria);
            tcResultSet moAdmins;
            for (int i = 0; i < moResultSet.getRowCount(); i++) {
                moResultSet.goToRow(i);
                moAdmins = moOrganizationUtility.getAdministrators(moResultSet.getLongValue("Organizations.Key"));
                mvOrganizations.add(moAdmins.getStringValue("Groups.Group Name"));
                System.out.println("Organization Admin Name : " + moAdmins.getStringValue("Groups.Group Name"));
            }
        } catch (tcAPIException tce) {
            // handle exception
        } catch (tcColumnNotFoundException cnfe) {
            // handle exception
        } catch (tcOrganizationNotFoundException onfe) {
            // handle exception
        }
        return mvOrganizations;
    }
 
    /**
     * Retrieves Role Display Name based on Role name and Role Category 
     * using OIM 11g RoleManager service API. This example shows how 
     * to construct compound search criteria.
     */
    public List getRoleDisplayName(String roleName, String roleCategory ) {
        Vector mvRoles = new Vector();
        RoleManager roleService = oimClient.getService(RoleManager.class); 
        Set<String> retAttrs = new HashSet<String>();
 
        // Attributes that should be returned as part of the search. 
        // Retrieve the "Role Display Name" attribute of a Role.
        // Note: Additional attributes can be specified in a 
        // similar fashion.
        retAttrs.add(RoleAttributeName.DISPLAY_NAME.getId());
 
        // Construct the first search criteria. This search criteria 
        // states "Find Role(s) whose 'Name' equals 'roleName'".  
        SearchCriteria criteria1;
        criteria1 = new SearchCriteria(RoleAttributeName.NAME.getId(), roleName, SearchCriteria.Operator.EQUAL);
 
        // Construct the second search criteria. This search criteria 
        // states "Find Role(s) whose 'category' equals 'roleCategory'".  
        SearchCriteria criteria2;
        criteria2 = new SearchCriteria(RoleCategoryAttributeName.NAME.getId(), roleCategory, SearchCriteria.Operator.EQUAL);
                
        // Construct the compound search criteria using 'criteria1' and 
        // 'criteria2' as arguments. This showcases how to construct
        // compound search criterias. 
        SearchCriteria criteria = new SearchCriteria(criteria1, criteria2, SearchCriteria.Operator.AND);
        try {
            // Use 'search' method of RoleManager API to retrieve 
            // records that match the search criteria. The return 
            // object is of type Role. 
            List<Role> roles = roleService.search(criteria, retAttrs, null);
 
            for (int i = 0; i < roles.size(); i++) {
                //Print Role Display Name
                System.out.println("Role Display Name : " + 
                    roles.get(i).getDisplayName());
                mvRoles.add(roles.get(i).getDisplayName());
            }
        } catch (AccessDeniedException ade) {
            // handle exception
        } catch (RoleSearchException use) {
            // handle exception
        }
        return mvRoles;
    }
 
    // Main method invocation 
    // Following assumptions are made
    //1. A User "Joe Doe" already exists in OIM
    //2. An Organization  "Example Organization" already exists in OIM
    //3. A Role "Foobar" already exists in OIM
    public static void main(String args[]) {
        List moList = null;
        
        try {
            Sample oimSample = new Sample();
 
            // initialize resources
            oimSample.init();
            // retrieve User logins with first name 'Joe'
            moList=oimSample.getUserLogin("Joe");
            // retrieve User logins with first names starting with 'J'
            moList=oimSample.getUserLogin("J*");
            // retrieve the administrators of an Organization with name 
            // 'Example Organization'
            moList=oimSample.getAdministratorsOfOrganization(
                "Example Organization");
            // retrieve Role display name with role name 'FooBar'
            // and role category as 'Defaut' 
            moList=oimSample.getRoleDisplayName("foobar", "Default");
            // release resources
            oimClient.logout();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

The following is the sample output:

[java] Creating client....
[java] Logging in
[java] Log in successful
[java] First Name : Joe  --  Login ID : JDOE
[java] First Name : J*  --  Login ID : JHOND
[java] First Name : J*  --  Login ID : JDOE
[java] Organization Admin Name : SYSTEM ADMINISTRATORS
[java] Role Display Name : foobar

31.6.2 Using Certification APIs

This section provides code examples for using APIs related to certification, such as CertificationService.

Example 31-2 provides the code sample to get certifications belonging to a user.

Example 31-2 Retrieving Certifications Belonging to a User

public List<CertificationInstance> findCertifications(SearchCriteria
searchCriteria, Set<String> retAttrs, Map<String,Object> configParams) throws
CertificationServiceException;
Example of searchCriteria to use:
  SearchCriteria searchCriteria1 = new
SearchCriteria(CertificationConstants.CERTIFICATION_SEARCH_FIELDPRIMARY_REVIEW
ER_ID, userKey, SearchCriteria.Operator.EQUAL);
  SearchCriteria searchCriteria2 = new
SearchCriteria("certificationStatusForQuery",
CertificationConstants.STATE_IN_PROGRESS.toString(),
SearchCriteria.Operator.EQUAL);
  SearchCriteria searchCriteria = new SearchCriteria(searchCriteria1,
searchCriteria2, SearchCriteria.Operator.AND);

Example 31-3 provides the code sample to retrieve an application instance certification.

Example 31-3 Retrieving an Application Instance Certification

public List<IDCAccountAttributeAndRoleWrapper> loadBatchUserEntitlements(LongcertificationId, String taskUid, Long userId, PaginationContext context,SearchCriteria searchCriteria) throws CertificationServiceException;

Example 31-4 provides the code sample to certify or deny entitlements.

Example 31-4 Certify or Deny Certifications

public void certifyUserEntitlements(Long certId, String taskUid, Long
userEntityId, Set<Long> roleEntityIds, Set<Long> accountEntityIds, Set<Long>
accountAttributeEntityIds, Integer certified, Date statusEndDate, String
comments) throws CertificationServiceException;

Example 31-5 provides the code sample to complete the certification.

Example 31-5 Complete the Certification

public CertificationInstance completeCertification(final Long certificationId, String taskUid, char[] cleartextPassword)

31.6.3 Using OIMService API

This section lists out sample usage for few operations by using the OIMService API. It contains the following topics:

31.6.3.1 RequestData Object Construction

For invoking the operations supported through OIMService API, you must first construct the RequestData object.

For all the operations that involve target user and cart item, such as role, application instance, or entitlement, construct the RequestData object as follows:

  1. Create an instance of the RequestData object.

  2. Create List of Beneficiary object(s), set the fields, and associate the object with RequestData object by invoking:

    requestData.setBeneficiaries();
    
  3. Create List of RequestBeneficiaryEntity object(s), and set the cart item data, such as entity type, entity key, and operation. Associate the object with Beneficiary object by invoking:

    beneficiary.setTargetEntities();
    

    The entityKey, which is set by using the entity.setEntityKey() method for a given operation, must be based on Table 31-3.

    Table 31-3 Operation and entityKey

    Operation entityKey

    Provision Application Instance

    Application Instance Key

    Modify Account

    Account Key

    Revoke Account

    Account Key

    Enable Account

    Account Key

    Disable Account

    Account Key

    Provision Entitlement

    Entitlement Key

    Modify Entitlement

    Entitlement Instance Key

    Revoke Entitlement

    Entitlement Instance Key


  4. Create List of RequestBeneficiaryEntityAttribute object(s), and set the attribute name and value in each object. Associate the object with the entity object by invoking entity.setEntityData().This is required only if the cart item is associated with a form.

    Note:

For all the operations that involve only the User entity, such as Create User, Modify User, Enable User, Disable User, and Delete User, the RequestData object must be populated as follows:

  1. Create an instance of the RequestData object.

  2. Create List of RequestEntity object(s) by setting entity type, entity key, and operation. Entity key must be set as user key for all the operations exception Create User.

  3. Create List of RequestEntityAttribute object(s), and set attribute name and value in each object. This is required only for Create User and Modify User operations.

31.6.3.2 Samples of OIMService API Usage

This section provides code samples of using the OIMService API.

Example 31-6 provides the code sample for revoking an account.

Example 31-6 Revoking an Account

RequestData requestData = new RequestData();
Beneficiary beneficiary = new Beneficiary();
beneficiary.setBeneficiaryKey("12"); //User with key 12
beneficiary.setBeneficiaryType(Beneficiary.USER_BENEFICIARY);
 
RequestBeneficiaryEntity entity = new RequestBeneficiaryEntity();
entity.setEntityType("ApplicationInstance");
entity.setEntityKey(String.valueOf(accountKey));
entity.setOperation("REVOKE");
 
List<RequestBeneficiaryEntity> entities = new ArrayList<RequestBeneficiaryEntity>();
 
entities.add(entity);
beneficiary.setTargetEntities(entities);
 
List<Beneficiary> beneficiaries = new ArrayList<Beneficiary>();
beneficiaries.add(beneficiary);
requestData.setBeneficiaries(beneficiaries);
OperationResult result = oimService.doOperation(requestData, OIMService.Intent.ANY);
if( result.getRequestID() != null ) {
//Operation resulted in to request creation.
System.out.println("Request submitted with ID: " + result.getRequestID());
} else {
System.out.println("Account is revoked successfully");
}

Example 31-7 provides the code sample for creating a user.

Example 31-7 Creating a User

RequestData requestData = new RequestData("Create User");
RequestEntity ent = new RequestEntity();
ent.setRequestEntityType(OIMType.User);
ent.setOperation("CREATE");
HashMap<String, String> userData = new HashMap<String, String>();
 
List<RequestEntityAttribute> attrs = new ArrayList<RequestEntityAttribute>();
 
RequestEntityAttribute attr = new RequestEntityAttribute("Last Name", "Doe", RequestEntityAttribute.TYPE.String);
attrs.add(attr);        
attr = new RequestEntityAttribute("First Name", "John", RequestEntityAttribute.TYPE.String);
attrs.add(attr);
attr = new RequestEntityAttribute("User Login", "jdoe", RequestEntityAttribute.TYPE.String);
attrs.add(attr);
Long organizationKey = new Long(1);
attr = new RequestEntityAttribute("Organization", organizationKey , RequestEntityAttribute.TYPE.Long);
attrs.add(attr);
attr = new RequestEntityAttribute("Role", "Full-Time", RequestEntityAttribute.TYPE.String);
attrs.add(attr);
 
ent.setEntityData(attrs);
 
List<RequestEntity> entities = new ArrayList<RequestEntity>();
entities.add(ent);
requestData.setTargetEntities(entities);
OperationResult result = oimService.doOperation(requestData, OIMService.Intent.ANY);
if( result.getRequestID() != null ) {
//Operation resulted in to request creation.
System.out.println("Request submitted with ID: " + result.getRequestID());
} else {
System.out.println("User is created successfully");
}