Sunday, 26 February 2017

OIM API - Stand Alone Code to Manual Complete Failed Process Task.

To execute below code you have to add following jars in classpath:

  • commons-logging.jar
  • eclipselink.jar
  • jrf-api.jar
  • oimclient.jar
  • spring.jar
  • wlfullclient.jar

Stand Alone Code:


import Thor.API.Operations.tcProvisioningOperationsIntf;
import Thor.API.tcResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;

public class ManualCompleteProcessTask {
    OIMClient oimClient = null;
   
    //identity self service details
    String username = "xelsysadm";
    String password = "<password>"; //xelsysadm password
    String t3url = "t3://<hostname>:<port>"; //OIM HostName and Port
    String authwl_location = "<location of authwl.conf file in your local machine>"; //eg. D:\\authwl.conf
   
    public void getOIMConnection() {
        System.out.println("getOIMConnection() : Start");
       
        //set system properties
        System.setProperty("java.security.auth.login.config", authwl_location);
        System.setProperty("OIM.AppServerType", "wls");
        System.setProperty("APPSERVER_TYPE", "wls");

        Hashtable oimenv = new Hashtable();
        oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
        oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url);
        oimClient = new OIMClient(oimenv);
        try {
            oimClient.login(username, password.toCharArray());
            System.out.println("Connected");
        } catch (LoginException e) {
            e.printStackTrace();
        }
        System.out.println("getOIMConnection() : End");
    }
   
    public void setTaskCompletedManually(String resourceName, String taskName, String taskStatus) {
        try {
            System.out.println("setTaskCompletedManually() : Start");
            tcProvisioningOperationsIntf tcOp = oimClient.getService(tcProvisioningOperationsIntf.class);

            Map<String, String> filter = new HashMap<String, String>();
            filter.put("Objects.Name", resourceName);
            filter.put("Process Definition.Tasks.Task Name", taskName);

            //Failed Task Status
            String taskStaus[] = new String[] {taskStatus};
            tcResultSet trs = tcOp.findAllOpenProvisioningTasks(filter, taskStaus);
            List<Map<String, Object>> taskLists = new ArrayList<Map<String, Object>>();

            int rowCount = trs.getRowCount();
            System.out.println("Total " + taskStatus + " Task(s) for Application Instance("  + resourceName + ") : " + trs.getRowCount());
           
           
            if (rowCount > 0) {
                for (int i = 0; i < rowCount; i++) {
                    trs.goToRow(i);
                    System.out.println(taskName + " Task completed manually for User : " + trs.getStringValue("Process Instance.Task Information.Target User"));
                    tcOp.setTasksCompletedManually(new long[] {trs.getLongValue("Process Instance.Task Details.Key")} );
                }
            }
            System.out.println("setTaskCompletedManually() : End");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }    
   
    public static void main(String[] args) {
        try {
            ManualCompleteProcessTask manualCompleteProcessTask = new ManualCompleteProcessTask();
           
            //Get OIM Connection
            manualCompleteProcessTask.getOIMConnection();

            //Resource Object Name
            String resourceName = "AD User";
            //Failed Task Name
            String taskName = "Create User";
            // If you want to manual complete pending task, replace Rejected with 'Pending'
            String taskStatus = "Rejected";
           
            //Manual Complete
            manualCompleteProcessTask.setTaskCompletedManually(resourceName, taskName, taskStatus);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}


Happy Learning!!!

OIM API - Stand Alone Code to Fetch Failed Process Task.

To execute below code you have to add following jars in classpath:

  • commons-logging.jar
  • eclipselink.jar
  • jrf-api.jar
  • oimclient.jar
  • spring.jar
  • wlfullclient.jar

Stand Alone Code:


import Thor.API.Operations.tcProvisioningOperationsIntf;
import Thor.API.tcResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;

public class FetchFailedProcessTask {
    OIMClient oimClient = null;
   
    //identity self service details
    String username = "xelsysadm";
    String password = "<password>"; //xelsysadm password
    String t3url = "t3://<hostname>:<port>"; //OIM HostName and Port
    String authwl_location = "<location of authwl.conf file in your local machine>"; //eg. D:\\authwl.conf
   
    public void getOIMConnection() {
        System.out.println("getOIMConnection() : Start");
       
        //set system properties
        System.setProperty("java.security.auth.login.config", authwl_location);
        System.setProperty("OIM.AppServerType", "wls");
        System.setProperty("APPSERVER_TYPE", "wls");

        Hashtable oimenv = new Hashtable();
        oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
        oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url);
        oimClient = new OIMClient(oimenv);
        try {
            oimClient.login(username, password.toCharArray());
            System.out.println("Connected");
        } catch (LoginException e) {
            e.printStackTrace();
        }
        System.out.println("getOIMConnection() : End");
    }
   
    public void getOpenTasks(String resourceName, String taskName, String taskStatus) {
        try {
            System.out.println("getOpenTasks() : Start");
            tcProvisioningOperationsIntf tcOp = oimClient.getService(tcProvisioningOperationsIntf.class);

            Map<String, String> filter = new HashMap<String, String>();
            filter.put("Objects.Name", resourceName);
            filter.put("Process Definition.Tasks.Task Name", taskName);

            //Failed Task Status
            String taskStaus[] = new String[] {taskStatus};
            tcResultSet trs = tcOp.findAllOpenProvisioningTasks(filter, taskStaus);
            List<Map<String, Object>> taskLists = new ArrayList<Map<String, Object>>();

            int rowCount = trs.getRowCount();
            System.out.println("Total " + taskStatus + " Task(s) for Application Instance("  + resourceName + ") : " + trs.getRowCount());

            if (rowCount > 0) {
                for (int i = 0; i < rowCount; i++) {
                    trs.goToRow(i);
                    System.out.println("Process Instance.Task Information.Target User : " + trs.getStringValue("Process Instance.Task Information.Target User"));
                    System.out.println("Process Instance.Task Details.Key : " + trs.getLongValue("Process Instance.Task Details.Key"));
                    System.out.println("*****************************************************");
                }
            }
            System.out.println("getOpenTasks() : End");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            FetchFailedProcessTask fetchFailedProcessTask = new FetchFailedProcessTask();
           
            //Get OIM Connection
            fetchFailedProcessTask.getOIMConnection();

            //Resource Object Name
            String resourceName = "AD User";
            //Failed Task Name
            String taskName = "Create User";
            // If you need pending task, replace Rejected with 'Pending'
            String taskStatus = "Rejected";
           
            //Get Failed Tasks
            fetchFailedProcessTask.getOpenTasks(resourceName, taskName, taskStatus);

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


Happy Learning!!!

OIM API - Stand Alone Code to Retry Failed Process Task.

To execute below code you have to add following jars in classpath:

  • commons-logging.jar
  • eclipselink.jar
  • jrf-api.jar
  • oimclient.jar
  • spring.jar
  • wlfullclient.jar
 

Stand Alone Code:

 

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import Thor.API.tcResultSet;
import java.util.List;
import java.util.Map;
import Thor.API.Operations.tcProvisioningOperationsIntf;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;

public class RetryProcessTask {
    OIMClient oimClient = null;
   
    //identity self service details
    String username = "xelsysadm";
    String password = "<password>"; //xelsysadm password
    String t3url = "t3://<hostname>:<port>"; //OIM HostName and Port
    String authwl_location = "<location of authwl.conf file in your local machine>"; //eg. D:\\authwl.conf
   
    public void getOIMConnection() {
            System.out.println("getOIMConnection() : Start");
            //set system properties
            System.setProperty("java.security.auth.login.config", authwl_location);
            System.setProperty("OIM.AppServerType", "wls");
            System.setProperty("APPSERVER_TYPE", "wls");
   
            Hashtable oimenv = new Hashtable();
            oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
            oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url);
            oimClient = new OIMClient(oimenv);
            try {
                oimClient.login(username, password.toCharArray());
                System.out.println("Connected");
            } catch (LoginException e) {
                e.printStackTrace();
            }
            System.out.println("getOIMConnection() : End");
    }
  
    public void retryTask(String resourceName, String taskName, String taskStatus) {
        try {
            System.out.println("retryTask() : Start");
            tcProvisioningOperationsIntf tcOp = oimClient.getService(tcProvisioningOperationsIntf.class);

            Map<String, String> filter = new HashMap<String, String>();
            filter.put("Objects.Name", resourceName);
            filter.put("Process Definition.Tasks.Task Name", taskName);

            //Failed Task Status
            String taskStaus[] = new String[] {taskStatus};
            tcResultSet trs = tcOp.findAllOpenProvisioningTasks(filter, taskStaus);
            List<Map<String, Object>> taskLists = new ArrayList<Map<String, Object>>();

            int rowCount = trs.getRowCount();
            System.out.println("Total " + taskStatus + " Task(s) for Application Instance("  + resourceName + ") : " + trs.getRowCount());
           
           
            if (rowCount > 0) {
                for (int i = 0; i < rowCount; i++) {
                    trs.goToRow(i);
                    System.out.println(taskName + " Task retried for User : " + trs.getStringValue("Process Instance.Task Information.Target User"));
                    tcOp.retryTask(trs.getLongValue("Process Instance.Task Details.Key"));
                }
            }
            System.out.println("retryTask() : End");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
   
    public static void main(String[] args) {
        try {
            RetryProcessTask retryProcessTask = new RetryProcessTask();
           
            //Get OIM Connection
            retryProcessTask.getOIMConnection();

            //Resource Object Name
            String resourceName = "AD User";
            //Failed Task Name
            String taskName = "Create User";
            // If you need pending task, replace Rejected with 'Pending'
            String taskStatus = "Rejected";
           
            //Retry Failed Task
            retryProcessTask.retryTask(resourceName, taskName, taskStatus);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

Happy Learning!!!

SOA Composite - Read Credentials from the Credential Store in Java Embedding.

Login to Oracle Enterprise Manager Console (http://<hostname>:7001/em).

Expand WebLogic Domain, right click on the name of your domain, go to Security, and then click on Credentials.


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

You can read keys to existing map or create a new map with new keys. Each key can store credentials. For this example I am using existing map "oracle.wsm.security" and key "OIMAdmin".


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Use Case: Read Credential from the Credentials Store in Java Embedding.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Use below code in Java Embedding to read xelsysadm credential and get OIM Client handle. 

To execute below code you have to add following jars in <Application_Name><Project_Name>\SCA-INF\lib:

  • jps-api.jar
  • jps-manifest.jar
  • oimclient.jar

String username = null, password = null;
String t3url = "t3://<hostname>:<port>"; //OIM host name and port
String credentialStoreProvider = "oracle.wsm.security"; //Map name
String OIMAdminName = "OIMAdmin"; //Key name
try {       
        //read xelsysadm credential from credential store  
        oracle.security.jps.JpsContextFactory jpsCtxFactory = oracle.security.jps.JpsContextFactory.getContextFactory();                
        oracle.security.jps.JpsContext jpsCtx = jpsCtxFactory.getContext();                
        oracle.security.jps.service.credstore.CredentialStore credStore = jpsCtx.getServiceInstance(oracle.security.jps.service.credstore.CredentialStore.class);                
        oracle.security.jps.service.credstore.PasswordCredential cred = (oracle.security.jps.service.credstore.PasswordCredential)credStore.getCredential(credentialStoreProvider,OIMAdminName);                
        if (cred != null) {
            username = cred.getName();                
            password = String.valueOf(cred.getPassword());           
        } else {                
            System.out.println("Credential not found");              
        }                
       
        System.out.println("Username : " + username);
        System.out.println("Password : " + password);
       
        //get OIMClient Handle  
        java.util.Hashtable env = new java.util.Hashtable();                              
        env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");                              
        env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL,t3url);                              
        oracle.iam.platform.OIMClient client = new oracle.iam.platform.OIMClient(env);                              
        client.login(username, password.toCharArray());
        System.out.println("Connected, OIMClient Handle : " + client);
       
} catch (Exception e) {                   
    e.printStackTrace();
}


Happy Learning!!!

Sunday, 11 December 2016

OIM 11g R2 - How to Create Approval Policy.


In this post I am creating Approval Policy for provisioning Application Instance. This Approval Policy will be initiated when Application Instance request is raised. In the same way we can create Approval Policy for other operation.


OIM Version – 11g R2 PS1 & 11g R2 PS2



Login to Identity System Administration console and go to Approval Policies Tab.

 

 

In PS1 and PS2 we have to create two approval policies, i.e one for Operational Level and other for Request Level.


Creating Operation Level Approval:


Click on highlighted icon.



Provide required information.



Select composite.

  

 

 Click Next.



Provide Rule Name and then click Add Simple Rule.



Provide required information.



 Click Next.



 Click Finish.



Operation Level Approval Policy is created successfully.




Creating Request Level Approval:

 

Click on highlighted icon.



Provide required information and then click Next.



Provide Rule Name and then click on Add Simple Rule tab.



Provide required information and then save.



Click Next.

Click Finish.


 

Request Level Approval Policy is created successfully.





OIM Version – 11g R2 PS3


Login to Identity System Administration console and go to Approval Tab.


 

Select Provision ApplicationInstance and then click Create.



Provide information as shown in below screen shots.



Select "Operation".





Select "Application".



Click on value and then select Provision "ApplicationInstance".



Select "Workflow Name.





Select Composite.





Click on Create.


Approval Policy is created successfully.





Happy Learning!!!