Tuesday 2 June 2015

Fetch Application Instances, ORC Key, Resource Status


Below code will Fetch the assigned Application Instances (Resources), Resource Status and ORC Key from user
==============================================================
For Client Code below JAR need to be added in Eclipse or JDeveloper.

1) commons-logging.jar
2) jrf-api.jar
3) oimclient.jar
4) spring.jar
5) wlfullclient.jar
==============================================================

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

import javax.security.auth.login.LoginException;

import oracle.iam.identity.exception.NoSuchUserException;
import oracle.iam.identity.exception.UserLookupException;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.authz.exception.AccessDeniedException;
import oracle.iam.provisioning.api.ProvisioningService;
import oracle.iam.provisioning.exception.GenericProvisioningException;
import oracle.iam.provisioning.exception.UserNotFoundException;
import oracle.iam.provisioning.vo.Account;
import oracle.iam.provisioning.vo.ApplicationInstance;


public class FetchAppInstance {

public static OIMClient oimClient;


public void OIMConnection(){

String oimInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";
java.util.Hashtable<String, String> env = new java.util.Hashtable<String, String>();
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL,oimInitialContextFactory);
//Provide the OIM t3 URL below
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL, "t3://localhost:14000");
//provide the authwl.conf file path from your local system. Copy the authwl.conf from designconsole\config to your local system
System.setProperty("java.security.auth.login.config", "C:\\Software\\designconsole\\designconsole\\config\\authwl.conf");
System.setProperty("OIM.AppServerType", "wls");        
   System.setProperty("APPSERVER_TYPE", "wls");
   oimClient = new OIMClient(env);
   try {
//Pass the OIM Admin Username and password
oimClient.login("xelsysadm","Password".toCharArray());
System.out.println("Connected Successfully");
} catch (LoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void fetchAppInst(Long userKey){
String ukey=String.valueOf(userKey);
ProvisioningService ps = oimClient.getService(ProvisioningService.class);
List<Account> userAccount;
try {
userAccount = ps.getAccountsProvisionedToUser(ukey);
System.out.println("size of list--->" + userAccount.size());
       System.out.println(userAccount);
       for (Account account : userAccount)
                {
                System.out.println("Application instance is --->"+account.getAppInstance()+"<-----Resource Status--->"+account.getAccountStatus()+"<---Process Instance Key(orckey)-->"+account.getProcessInstanceKey());
                //System.out.println("Application instance is --->"+account.getAccountStatus());
                }
} catch (UserNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GenericProvisioningException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

     
}
public static void main(String[] args)  {
FetchAppInstance fo=new FetchAppInstance();
fo.OIMConnection();
//Pass the user key here
fo.fetchAppInst(144L);

}

}

No comments:

Post a Comment