Prototype for invoking an OIM API from a SOA Composite


try {
System.out.println("Prototype for invoking an OIM API from a SOA Composite");
System.out.println("RTM Usecase: Organization Administrator");
String oimUserName = "";
String oimPassword = "";
String oimURL = "";
String roleApprover = "";
String actKey = "";

//get oimuser 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();

// 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 Service
oracle.iam.request.api.RequestService reqSvc =
client.getService(oracle.iam.request.api.RequestService.class);
oracle.iam.identity.rolemgmt.api.RoleManager roleSvc =
client.getService(oracle.iam.identity.rolemgmt.api.RoleManager.class);
oracle.iam.identity.usermgmt.api.UserManager usersvc =
client.getService(oracle.iam.identity.usermgmt.api.UserManager.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);
java.util.List beneficiaries = req.getBeneficiaries();

if(beneficiaries != null){
for(oracle.iam.request.vo.Beneficiary benf: beneficiaries){
//get org key
java.util.HashSet searchAttrs = new java.util.HashSet();
searchAttrs.add(oracle.iam.identity.usermgmt.api.UserManagerConstants.
AttributeName.USER_LOGIN.getId());
searchAttrs.add(oracle.iam.identity.usermgmt.api.UserManagerConstants.
AttributeName.USER_ORGANIZATION.getId());

oracle.iam.identity.usermgmt.vo.User user1 =
usersvc.getDetails(benf.getBeneficiaryKey(),searchAttrs, false);
actKey = user1.getAttribute("act_key").toString();
//get org admin
if(actKey != "" && actKey != " ") {
Thor.API.Operations.tcOrganizationOperationsIntf orgAPI = (Thor.API.Operations.tcOrganizationOperationsIntf)client.getService(
Thor.API.Operations.tcOrganizationOperationsIntf.class);
Thor.API.tcResultSet rset =
orgAPI.getAdministrators(Long.parseLong(actKey));
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); } //get role approver java.util.List rbes =
benf.getTargetEntities();
for(oracle.iam.request.vo.RequestBeneficiaryEntity rbe : rbes){
String key = rbe.getEntityKey();
String type = rbe.getEntityType();
if(type.equalsIgnoreCase("Role")){
java.util.HashSet roleAttrs = new
java.util.HashSet();
roleAttrs.add("Role Approver");
oracle.iam.identity.rolemgmt.vo.Role role =
roleSvc.getDetails(key,roleAttrs);
roleApprover = (String)role.getAttribute("Role Approver");
setVariableData("roleApprover", roleApprover);
break;
}
}
break;
}
}
System.out.println("OrgAdmin=" + getVariableData("orgAdmin").toString());
System.out.println("roleApprover=" + getVariableData("roleApprover").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 *