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 = "";

//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);
Thor.API.Operations.tcObjectOperationsIntf objAPI =
client.getService(Thor.API.Operations.tcObjectOperationsIntf.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 beneficiary: beneficiaries){
java.util.HashMap beneficairyAttrs = beneficiary.getAttributes();
java.util.List rbes =
beneficiary.getTargetEntities();
for(oracle.iam.request.vo.RequestBeneficiaryEntity rbe : rbes){
String resource_key = rbe.getEntityKey();
String type = rbe.getEntityType();

if(type.equalsIgnoreCase("Resource")) {
Thor.API.tcResultSet resultSet =
objAPI.getAdministrators(Long.parseLong(resource_key));
StringBuffer resourceAdminsBuffer = new StringBuffer();
for (int i = 0; i < resultSet.getRowCount();i++){ resultSet.goToRow(i); resourceAdminsBuffer.append(resultSet.getStringValue("Groups.Group Name")) ; if(i >= 0 && i < (resultSet.getRowCount()-1)){ resourceAdminsBuffer.append(","); } } setVariableData("resourceAdmins", resourceAdminsBuffer.toString()); } break; } break; } } System.out.println("Resource Administartors=" + getVariableData("resourceAdmins").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 *