Fetch OrganizationAdmins in OIM through API

try {       
System.out.println("Prototype for invoking an OIM API from a SOA Composite");       
System.out.println("RTM Usecase: Self Registration Approval by Organization Administrator");       
String oimUserName = "";       
String oimPassword = "";       
String oimURL = "";       
//get system administrator?s credentials        
oracle.security.jps.JpsContext ctx =         
oracle.security.jps.JpsContextFactory.getContextFactory().getContext();        
final oracle.security.jps.service.credstore.CredentialStore cs =         
(oracle.security.jps.service.credstore.CredentialStore)ctx.getServiceInstance( 
oracle.security.jps.service.credstore.CredentialStore.class); 				        
oracle.security.jps.service.credstore.CredentialMap cmap = cs.getCredentialMap("oracle.oim.sysadminMap");        
oracle.security.jps.service.credstore.Credential cred = cmap.getCredential("sysadmin");        
if (cred instanceof oracle.security.jps.service.credstore.PasswordCredential) {        
oracle.security.jps.service.credstore.PasswordCredential pcred = (oracle.security.jps.service.credstore.PasswordCredential)cred;        
char[] p = pcred.getPassword();        
oimUserName = pcred.getName();        
oimPassword = new String(p);        
} 
//get oimurl       
Object obj = getVariableData("oimurl");           
oimURL = obj.toString();          
System.out.println("oimurl=" + oimURL); 
// set the initial context factory       
String oimInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";         
// set up the environment for making the OIM API invocation       
java.util.Hashtable env = new java.util.Hashtable(); 
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL, 
oimInitialContextFactory); 	    
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL, oimURL);   	 
oracle.iam.platform.OIMClient client = new oracle.iam.platform.OIMClient(env);       
client.login(oimUserName, oimPassword.toCharArray());       
System.out.println("Login Successful");       
// get the RequestService to get details of the request       
oracle.iam.request.api.RequestService reqSvc = 
(oracle.iam.request.api.RequestService)client.getService(       
oracle.iam.request.api.RequestService.class);	 
Object reqIdXMLElem = getVariableData("inputVariable",                       
"payload",                        
"/ns3:process/ns4:RequestID");	 
String reqId = ((oracle.xml.parser.v2.XMLElement)reqIdXMLElem).getText();           
System.out.println("The request ID is "+reqId);       
// invoke the getBasicRequestData() method on the RequestService API       
oracle.iam.request.vo.Request req = reqSvc.getBasicRequestData(reqId);       
String act_key = "";       
java.util.List< oracle.iam.request.vo.RequestEntity> targetEntities =  
req.getTargetEntities();       
for( oracle.iam.request.vo.RequestEntity reqEntity: targetEntities){      
java.util.List< oracle.iam.request.vo.RequestEntityAttribute> attributes = reqEntity.getEntityData();       
for( oracle.iam.request.vo.RequestEntityAttribute attribute : attributes){       
if(attribute.getName().equalsIgnoreCase("Organization")){       
act_key = attribute.getValue().toString();       
}       
}       
}       
System.out.println("Organization Key is "+act_key);       
if(act_key != "" && act_key != " ") {       
Thor.API.Operations.tcOrganizationOperationsIntf orgAPI = (Thor.API.Operations.tcOrganizationOperationsIntf)client.getService(				            Thor.API.Operations.tcOrganizationOperationsIntf.class);       
Thor.API.tcResultSet rset= orgAPI.getAdministrators(Long.parseLong(act_key));      
StringBuffer sb = new StringBuffer();  
for (int i = 0; i < rset.getRowCount();i++){   
rset.goToRow(i);   
sb.append(rset.getStringValue("Groups.Group Name")) ;   
if(i >= 0 && i < (rset.getRowCount()-1)){   
sb.append(",");   
}   
}		   
String grpNames = sb.toString();      
System.out.println("Groups="+grpNames);    
setVariableData("orgadmin",grpNames);       
}        
else{ 
setVariableData("orgadmin","SYSTEM ADMINISTRATORS");       
} 
Object obj1 = getVariableData("orgadmin");     
System.out.println("OrganizationAdmins = " + obj1.toString());     
} catch (Exception e){ 
System.out.println("----------------------");       
e.printStackTrace();       
System.out.println("----------------------");       
}

Leave a Reply

Your email address will not be published. Required fields are marked *