In this post I am creating the Organisation and Assigning the Membership Rule through Client Code.
I am reading the Organisation Details and Membership Rule from CSV File.
---------------------------------------------bulkOrg.csv------------------------------------------------------
Once Organisation-TestOrg4 will be created I'll assign the membershipRule as- Property ID="1314" .
============================OIM Client Code============================
package com.oim.scheduler;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;
import javax.security.auth.login.LoginException;
import com.csvreader.CsvReader;
import Thor.API.Operations.tcOrganizationOperationsIntf;
import oracle.iam.identity.exception.OrganizationManagerException;
import oracle.iam.identity.orgmgmt.api.OrganizationManager;
import oracle.iam.identity.orgmgmt.vo.Organization;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.api.UserManagerConstants;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.Platform;
import oracle.iam.platform.authz.exception.AccessDeniedException;
import oracle.iam.platform.entitymgr.vo.SearchCriteria.Operator;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;
import oracle.iam.platform.entitymgr.vo.SearchRule;
public class OrgOperation {
public static OIMClient oimClient;
OrganizationManager organizationmanager;
UserManagerConstants usrmgconst;
public static void getOIMConnection() throws LoginException{
System.out.println("INSIDE getOIMConnection");
String PROVIDER_URL = "t3://OIMHost.nssd.star:14000";
String USERNAME = "xelsysadm";
String PASSWORD = "Password";
System.setProperty("java.security.auth.login.config", "C:\\CB\\authwlConfig\\authwl.conf");
System.setProperty("APPSERVER_TYPE", "wls");
Hashtable env = new Hashtable();
env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, PROVIDER_URL);
env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL,OIMClient.WLS_CONTEXT_FACTORY);
oimClient = new OIMClient(env);
oimClient.login(USERNAME, PASSWORD);
System.out.println("<<<<<<<<<<<<<<<connection established>>>>>>>>>>>>>>>>>");
}
void readCSV(String csvFileLoc,String csvSeparator) throws IOException{
System.out.println("<<<<<<<<<<<<Read CSV Method>>>>>>>>>>>>>>>>");
System.out.println("CSV File Loc:"+csvFileLoc+"CSV Separator:"+csvSeparator);
CsvReader dataValue;
char c[]=csvSeparator.toCharArray();
System.out.println("value of c[0]----> "+c[0]);
dataValue = new CsvReader(csvFileLoc,c[0]);
dataValue.readHeaders();
String s[] = dataValue.getHeaders();
for(int i=0;i<s.length;i++){
System.out.println("Header name: ----> "+s[i]);
}
try {
while (dataValue.readRecord()){
String OrgName = dataValue.get("Organization Name");
String parOrgeKey = dataValue.get("Parent Organization Key");
String OrgType = dataValue.get("Organization Type");
String propertyID=dataValue.get("Property ID");
System.out.println("OrgName-->"+OrgName+"parOrgeKey----->"+parOrgeKey+"OrgType---->"+OrgType+"Property ID---->"+propertyID);
System.out.println("<<<<<<<<<<<<Before Calling Create Organization Method>>>>>>>>>>>>>>>>");
createOrg(OrgName,parOrgeKey,OrgType,propertyID);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public String createOrg(String orgName,String parorgKey, String orgType, String PropertyID){
System.out.println("<<<<<<<<<<<<Create Organization Method>>>>>>>>>>>>>>>>");
organizationmanager = oimClient.getService(OrganizationManager.class);
//usrmgconst = oimClient.getService(UserManagerConstants.class);
System.out.println("<<<<<<<<<<<<Before Search rule>>>>>>>>>>>>>>>>");
SearchRule sc = new SearchRule("PropertyID",propertyID,Operator.EQUAL); System.out.println("<<<<<<<<<<<<After Search Rule>>>>>>>>>>>>>>>>");
System.out.println("Search Rule is: "+sc);
Organization organization = new Organization("Test");
organization.setAttribute("Organization Name", orgName);
organization.setAttribute("parent_key", parorgKey);
organization.setAttribute("Organization Customer Type", orgType);
System.out.println("<<<<<<<<<<<<Organization is: "+organization);
/*****After org creation it returns orgKey as return value. This is org key for newly created organization.*****/
String orgKey = null;
try {
System.out.println("<<<<<<<<<<<<Before Create Organization Method>>>>>>>>>>>>>>>>");
//orgKey = organizationmanager.create(organization);
System.out.println("Organization Key is: "+orgKey);
System.out.println("<<<<<<<<<<<<Before Assigning membersigip>>>>>>>>>>>>>>>>");
organizationmanager.setUserMembershipRule(orgKey, sc);
System.out.println("<<<<<<<<<<<<After Assigning membersigip>>>>>>>>>>>>>>>>");
} catch (OrganizationManagerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AccessDeniedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return orgKey;
}
public static void main(String[] arg) throws LoginException, IOException {
OrgOperation op=new OrgOperation();
op.getOIMConnection();
op.readCSV("C:/CB/CsvLoc/OrgCSV/bulkOrg.csv", ",");
}
}
I am reading the Organisation Details and Membership Rule from CSV File.
---------------------------------------------bulkOrg.csv------------------------------------------------------
============================OIM Client Code============================
package com.oim.scheduler;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;
import javax.security.auth.login.LoginException;
import com.csvreader.CsvReader;
import Thor.API.Operations.tcOrganizationOperationsIntf;
import oracle.iam.identity.exception.OrganizationManagerException;
import oracle.iam.identity.orgmgmt.api.OrganizationManager;
import oracle.iam.identity.orgmgmt.vo.Organization;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.api.UserManagerConstants;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.Platform;
import oracle.iam.platform.authz.exception.AccessDeniedException;
import oracle.iam.platform.entitymgr.vo.SearchCriteria.Operator;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;
import oracle.iam.platform.entitymgr.vo.SearchRule;
public class OrgOperation {
public static OIMClient oimClient;
OrganizationManager organizationmanager;
UserManagerConstants usrmgconst;
public static void getOIMConnection() throws LoginException{
System.out.println("INSIDE getOIMConnection");
String PROVIDER_URL = "t3://OIMHost.nssd.star:14000";
String USERNAME = "xelsysadm";
String PASSWORD = "Password";
System.setProperty("java.security.auth.login.config", "C:\\CB\\authwlConfig\\authwl.conf");
System.setProperty("APPSERVER_TYPE", "wls");
Hashtable env = new Hashtable();
env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, PROVIDER_URL);
env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL,OIMClient.WLS_CONTEXT_FACTORY);
oimClient = new OIMClient(env);
oimClient.login(USERNAME, PASSWORD);
System.out.println("<<<<<<<<<<<<<<<connection established>>>>>>>>>>>>>>>>>");
}
void readCSV(String csvFileLoc,String csvSeparator) throws IOException{
System.out.println("<<<<<<<<<<<<Read CSV Method>>>>>>>>>>>>>>>>");
System.out.println("CSV File Loc:"+csvFileLoc+"CSV Separator:"+csvSeparator);
CsvReader dataValue;
char c[]=csvSeparator.toCharArray();
System.out.println("value of c[0]----> "+c[0]);
dataValue = new CsvReader(csvFileLoc,c[0]);
dataValue.readHeaders();
String s[] = dataValue.getHeaders();
for(int i=0;i<s.length;i++){
System.out.println("Header name: ----> "+s[i]);
}
try {
while (dataValue.readRecord()){
String OrgName = dataValue.get("Organization Name");
String parOrgeKey = dataValue.get("Parent Organization Key");
String OrgType = dataValue.get("Organization Type");
String propertyID=dataValue.get("Property ID");
System.out.println("OrgName-->"+OrgName+"parOrgeKey----->"+parOrgeKey+"OrgType---->"+OrgType+"Property ID---->"+propertyID);
System.out.println("<<<<<<<<<<<<Before Calling Create Organization Method>>>>>>>>>>>>>>>>");
createOrg(OrgName,parOrgeKey,OrgType,propertyID);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public String createOrg(String orgName,String parorgKey, String orgType, String PropertyID){
System.out.println("<<<<<<<<<<<<Create Organization Method>>>>>>>>>>>>>>>>");
organizationmanager = oimClient.getService(OrganizationManager.class);
//usrmgconst = oimClient.getService(UserManagerConstants.class);
System.out.println("<<<<<<<<<<<<Before Search rule>>>>>>>>>>>>>>>>");
SearchRule sc = new SearchRule("PropertyID",propertyID,Operator.EQUAL); System.out.println("<<<<<<<<<<<<After Search Rule>>>>>>>>>>>>>>>>");
System.out.println("Search Rule is: "+sc);
Organization organization = new Organization("Test");
organization.setAttribute("Organization Name", orgName);
organization.setAttribute("parent_key", parorgKey);
organization.setAttribute("Organization Customer Type", orgType);
System.out.println("<<<<<<<<<<<<Organization is: "+organization);
/*****After org creation it returns orgKey as return value. This is org key for newly created organization.*****/
String orgKey = null;
try {
System.out.println("<<<<<<<<<<<<Before Create Organization Method>>>>>>>>>>>>>>>>");
//orgKey = organizationmanager.create(organization);
System.out.println("Organization Key is: "+orgKey);
System.out.println("<<<<<<<<<<<<Before Assigning membersigip>>>>>>>>>>>>>>>>");
organizationmanager.setUserMembershipRule(orgKey, sc);
System.out.println("<<<<<<<<<<<<After Assigning membersigip>>>>>>>>>>>>>>>>");
} catch (OrganizationManagerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AccessDeniedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return orgKey;
}
public static void main(String[] arg) throws LoginException, IOException {
OrgOperation op=new OrgOperation();
op.getOIMConnection();
op.readCSV("C:/CB/CsvLoc/OrgCSV/bulkOrg.csv", ",");
}
}