Monday, 10 December 2012

Code to add values to child table


public void childvalue(String res_Name,String User){
            long parentformkey;
            try {
                  parentformkey = moform.getProcessFormDefinitionKey(getProcessInstKeyOfRes(res_Name,getUserKey(User)));
                  int parentformver = moform.getProcessFormVersion(getProcessInstKeyOfRes(res_Name,getUserKey(User)));
                  tcResultSet childforms = moform.getChildFormDefinition(parentformkey, parentformver);

                  for (int childFormCounter = 0; childFormCounter < childforms.getRowCount(); childFormCounter++) {
                      childforms.goToRow(childFormCounter);
                      String childTableName = childforms.getStringValue("Structure Utility.Table Name");
                      System.out.println(childTableName);
                      if (childTableName.equals("UD_CHFORM")) {
                  //    long formkey = childforms.getLongValue("Structure Utility.Child Tables.Child Key");
                  //    tcResultSet childFormData = moform.getProcessFormChildData(formkey, getProcessInstKeyOfRes(res_Name,getUserKey(User)));
                        //long childFormKey =0;



                        System.out.println(childforms.getRowCount());
                        for (int k = 0; k < childforms.getRowCount(); k++) {
                              childforms.goToRow(k);

                              long childFormKey = childforms.getLongValue("Structure Utility.Child Tables.Child Key");
                              HashMap<String, String> memberMap = new HashMap<String, String>();
                              HashMap<String, String> memberMap1 = new HashMap<String, String>();

                              memberMap1.put("UD_CHFORM_LOCATION","newvalue1");
                              memberMap.put("UD_CHFORM_LOCATION","newvalue2");
                              moform.addProcessFormChildData(childFormKey,getProcessInstKeyOfRes(res_Name,getUserKey(User)), memberMap);
                              moform.addProcessFormChildData(childFormKey,getProcessInstKeyOfRes(res_Name,getUserKey(User)), memberMap1);
                              System.out.println("added");

                            }
                      }
                  }



            } catch (tcAPIException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcProcessNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcFormNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcNotAtomicProcessException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcVersionNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcVersionNotDefinedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcColumnNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcRequiredDataMissingException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcInvalidValueException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

      }

Tuesday, 6 November 2012

Java code to get the details of IT resource

public final Hashtable getITResourceProperties(String itResourceName)throws Exception {

            System.out.println("getITResourceProperties -- IT Resource Name: "+ itResourceName);
            long svrKey = 0;
            Hashtable map = new Hashtable();
            map.put("IT Resources.Name", itResourceName);
            tcResultSet set = moitres.findITResourceInstances(map);
            svrKey = set.getLongValue("IT Resources.Key");
            System.out.println("getITResourceProperties -- IT Resources.Key = " + svrKey);
            set = moitres.getITResourceInstanceParameters(svrKey);
            map.clear();
            map.put("svr_key",(new StringBuffer(String.valueOf(svrKey))).toString());
            System.out.println("getITResourceProperties-- svr_key = " + String.valueOf(svrKey).toString());

            for (int i = 0; i < set.getRowCount(); i++) {
                  set.goToRow(i);
                  String s3 = set.getStringValue("IT Resources Type Parameter.Name");
                  String s4 = set.getStringValue("IT Resources Type Parameter Value.Value");
                  map.put(s3, s4);
                  System.out.println(s3+"----"+s4);
            }

            return map;

      }

OES import Error

Recently when we tried to import xml policies using  poilcyIX.sh, we faced issues like Object NOT Found, this happened because there is a mismatch between attribute definition name and the the group attriute name.

Example:
IN attribute defintion its defined as pop_value and in group attributes its defined as pop_values

Friday, 24 August 2012

OIM Code to get the userlist Assocaiated with a resource

public String associatedUsersResource(String resource,String status){


//Pass the resource name as input
//status will be either provisioedor provisioning or disabled
//If we pass * in the status ,it will return all the users assocaited with the resource with all status

HashMap status1=new HashMap();
status1.put("Objects.Object Status.Status", status);
try {
tcResultSet result=prov.getAssociatedUsers(getObjectKey(resource), status1);
for(int i=0;i<=result.getRowCount()-1;i++){
result.goToRow(i);
System.out.println(result.getStringValue("Users.User ID"));
}
} catch (tcAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (tcObjectNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (tcColumnNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return status;
}

Monday, 13 August 2012

Error while updating user



Normally when we update a user ,we used to call findusers and then call a update

tcResultSet moResultSet = moUserUtility.findUsers(userMap);
hmUser.put("Users.User ID", UID);
hmUser.put("Users.Password", pwd);
moUserUtility.updateUser(moResultSet, hmUser);

now if you call a second update like

hmUser.put("Users.User ID", UID);
 hmUser.put("Users.First Name", FN);
moUserUtility.updateUser(moResultSet, hmUser);

it will throw exception like threw Exception Thor.API.Exceptions.tcStaleDataUpdateException which is caused because for the second update it did not call the find users.It should be like

tcResultSet moResultSet = moUserUtility.findUsers(userMap);
hmUser.put("Users.User ID", UID);
 hmUser.put("Users.First Name", FN);
moUserUtility.updateUser(moResultSet, hmUser);

Now the update works fine.


Thursday, 31 May 2012

code to trigger a particular task of a resource

In this code,The API uses the method addProcessTaskInstance which takes the taskKey and the processinstancekey as input

I have written a seperate blogs to get the taskKey and getting the processInstance key

public void executeTask(String resourceName,String taskName,String userId){

try{
//pass the Task Key and thProcess instance key
moOperations.addProcessTaskInstance(taskKey(taskName,resourceName),getProcessInstKeyOfRes(resourceName,getUserKey(userId)));
System.out.println("executed");
}catch(Exception e){
}
}

Code to get the processInstanceKey of a resource provisioned to a user

private long getProcessInstKeyOfRes(String res_Name,long userkey) {
long longProcessInstanceKey = 0;
try{
tcResultSet resultGetObjects = moUserUtility.getObjects(userkey);
int countResultGetObjects = resultGetObjects.getRowCount();
for(int i = 0; i < countResultGetObjects; i++) {
resultGetObjects.goToRow(i);
String objetcName = resultGetObjects.getStringValue("Objects.Name");
System.out.println("---------Object name"+objetcName);
if(res_Name.equalsIgnoreCase(objetcName)) {
String status = resultGetObjects.getStringValue("Objects.Object Status.Status");
status = status.toLowerCase();
System.out.println(status);
longProcessInstanceKey = resultGetObjects.getLongValue("Process Instance.Key");
System.out.println("Process Instance Key"+ longProcessInstanceKey);
}
}

}catch (Exception e) {
}
return longProcessInstanceKey;
}

code to get the task Key of a Resource

public long taskKey(String taskname,String resourceName){
long ret=0;
try
{

Class.forName("oracle.jdbc.driver.OracleDriver");
  String url = "jdbc:oracle:thin:@localhost1:siddb";
  Connection conn = DriverManager.getConnection(url,"adm","password");
System.out.println("connected");
Statement stmt = conn.createStatement();
ResultSet rset =
stmt.executeQuery("SELECT m.mil_key,m.MIL_NAME FROM mil m, pkg p, tos t WHERE m.mil_name = '"+taskname+"' AND m.TOS_KEY = t.TOS_KEY AND t.PKG_KEY = p.PKG_KEY AND p.pkg_name='"+resourceName+"'");


while (rset.next()) {
String convertret=rset.getString(1);
long longKey = Long.parseLong(convertret);
System.out.println ("TaskKey-->"+longKey);
System.out.println ("TaskName-->"+rset.getString(2));
return longKey;

}
stmt.close();
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
return ret;


}

Provision a resource to a user

public void provisionResource(String resourcetobeProvisioned,String UserID){
try{
long moResultSet = moUserUtility.provisionObject(getUserKey(UserID),getObjectKey(resourcetobeProvisioned));
System.out.println("Added");

}catch(Exception e){

}
}

Monday, 28 May 2012


Create a table in DB

CREATE TABLE "XLADM(DBUSERNAME)"."USER_DATA(TABLENAME)" ( "USER_ID" VARCHAR2(20 BYTE) NOT NULL ENABLE, "FIRSTNAME" VARCHAR2(20 BYTE), "LASTNAME" VARCHAR2(20 BYTE), "ORGANIZATION" VARCHAR2(20 BYTE), "PASSWORD" VARCHAR2(20 BYTE), "EMAIL" VARCHAR2(20 BYTE), "COMPANY" VARCHAR2(20 BYTE), CONSTRAINT "USER_DATA_PK" PRIMARY KEY ("USER_ID") )

Provisioning to a DB table

Download DBAT_91050

IN GTC connector, select provisioning
Connector Name DB APP
Transport Provider (Provisioning) DBProvisioningTransport
Format Provider (Provisioning) DBProvisioningFormat

Database Driver: oracle.jdbc.driver.OracleDriver
Database URL: jdbc:oracle:thin:@locahost:1521:oimsr
Database User ID: xladm
Database Password: password

Parent Table/View Name: USER_DATA(Table Name)
No need to make changes to to the Mappings shown in GTC..

Thats it you are done.Now select the resource from resource object and follow the normal provisioning to a user.

OIM SQL Query 1

To check for users created today whose resource status is provisioning

select oiu.usr_key,obj.obj_key, obj.OBJ_NAME, usr.USR_LOGIN , usr.usr_first_name , usr.USR_LAST_NAME , ost.ost_status from oiu , ost, obj , USR where oiu.ost_key =ost.ost_key and oiu.usr_key = usr.usr_key and ost.obj_key = obj.obj_key and trunc(usr.usr_create) = trunc(sysdate) and (obj.obj_name= 'OID' or obj.obj_name = 'FLAT_GTC')and ost.ost_status = 'Provisioning';

To check for users whose resource status is provisioning

select oiu.usr_key,obj.obj_key, obj.OBJ_NAME, usr.USR_LOGIN , usr.usr_first_name , usr.USR_LAST_NAME , ost.ost_status from oiu , ost, obj , USR where oiu.ost_key =ost.ost_key and oiu.usr_key = usr.usr_key and ost.obj_key = obj.obj_key and (obj.obj_name= 'OID' or obj.obj_name = 'FLAT_GTC')and ost.ost_status = 'Provisioning';

To check the resource assigned to a user

select obj.obj_name from OBJ,OST,OIU,USR where OST.OBJ_KEY = obj.OBJ_KEY and oiu.ost_key = ost.ost_key and oiu.usr_key = usr.usr_key and USR.USR_LAST_NAME='asdf';

Getting accesspolicyDetails

select pol.pol_key , pol.pol_name , pol.pol_description from pol;

Monday, 23 April 2012

Trigger a Update on OIM field to OID


Recently we had a requirement like we need to update a field in OIM and it should inturn update in OID.Many of you might know how to achieve this.This is only for some basic understanding.

Steps

1.Create a user defined Field say UserDN(USR_UDF_USERSN)

2.In OID process definition create a task like Change UserDN and map it to modifyuser adaptor.While doing the attribute mappings for Attrvalue map it to user Definition(UserDN) and AttrName make it to literal(UserDN)

3.Go to Lookup,Search for *USR_Trigger*---For code key(USR_UDF_USERDN)and in decode key(Change UserDN).the decode should be same as that of task name in process definition(I Presume this)

4.Go to OID attribute mapping(AttrName.OID.Map) . In code key add the OIM fieldname and in decode key map it to OID attribute.If the attribute is created in process form add the code key to Process form field name and decode key to OID.

So whenever a user is getting updated in OIM,It will change the value in OID.Also note that to update that field in OIM proocess form create process definition tasks like UserDN Updated.Also add a prepopulate to the field to update in OID form.

Saturday, 21 January 2012

11g Code to get the roles of the user and the roles assigned to users

public void getUsersByRole(String rolename){
RoleManager rolemanager=client.getService(RoleManager.class);
List s2;
try {
s2 = rolemanager.getRoleMembers(getRoleKey(rolename),false);
for (User user: s2)
{
System.out.println("User ID : "+user.getAttribute("User Login"));
}

} catch (RoleMemberException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AccessDeniedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getRolesForUser(String username){
try{
RoleManager rolemanager=client.getService(RoleManager.class);
List s3=rolemanager.getUserMemberships(getUserKey(username).toString),false);

for(Role role:s3){
System.out.println("Roles :" +role.getAttribute("Role Display Name"));
}
// System.out.println(s3);
}catch(Exception e){
e.printStackTrace();
}
}

11g getting rolekey,userkey,objectkey

public Long getUserKey(String userLogin) {
Long userKey = null;
SearchCriteria criteria = new SearchCriteria("User Login", userLogin,SearchCriteria.Operator.EQUAL);
Set retAttrs = new HashSet();
retAttrs.add("usr_key");
UserManager usrMgr = client.getService(UserManager.class);
try {
usrMgr.search(criteria, retAttrs, null);
List users = usrMgr.search(
criteria, retAttrs, null);

userKey = (Long) users.get(0).getAttribute("usr_key");
} catch (Exception e) {
e.printStackTrace();
}
return userKey;
}

public long getObjectKey(String object) {
HashMap objectMap = new HashMap();
long key = 0;
try {
tcObjectOperationsIntf moObjectUtility = client.getService(tcObjectOperationsIntf.class);

objectMap.put("Objects.name", object);
tcResultSet moResultSet = moObjectUtility.findObjects(objectMap);

if (moResultSet.getRowCount() == 0) {
} else {
moResultSet.goToRow(0);
key = moResultSet.getLongValue("Objects.name");
}
} catch (Exception e) {
e.printStackTrace();
}
return key;
}


public String getRoleKey(String roleName)
{
String roleKey=null;
SearchCriteria criteria = new SearchCriteria(RoleAttributeName.NAME.getId(), roleName, SearchCriteria.Operator.EQUAL);
Set retAttrs = new HashSet();
retAttrs.add(RoleAttributeName.KEY.getId());
RoleManager roleMgr = (RoleManager)client.getService(RoleManager.class);
try {
List roles= roleMgr.search(criteria, retAttrs, null);
roleKey = roles.get(0).getAttribute(RoleAttributeName.KEY.getId()).toString();
} catch (Exception e) {
}
return roleKey;
}

Friday, 20 January 2012

11g OIM connect

Please find the code snippet
Make sure you add the required jars from lib/ext and also weblogic.jar.


public class OIM11g {

public static String id;
private OIMClient client;
private tcUtilityFactory ioUtilityFactory;


private static String OIMUserName = "xelsysadm";
private static String OIMPassword = "testpass";
private static String OIMURL = ReadProperty.getProp("URL");
private static String OIMInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";
private static String config = ReadProperty.getProp("Configuration");
private static String homeDir = ReadProperty.getProp("HomeDirectory");
public OIM11g(){

}

public Boolean connect(String user, String pwd)
{
Boolean result=true;
Hashtable env = new Hashtable();
System.setProperty("java.security.auth.login.config",config);
System.out.println(config);
System.setProperty("XL.HomeDir", homeDir);
System.out.println(homeDir);
env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL,OIMInitialContextFactory);
env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, OIMURL);
System.out.println(OIMURL);
client = new OIMClient(env);
try {
System.out.println("Establishing connection...");
client.login(user, pwd.toCharArray());
ioUtilityFactory = new tcUtilityFactory(env,user,pwd);
System.out.println("connected");
}catch (Exception e){
e.printStackTrace();
}
return result;
}

Saturday, 7 January 2012

Cookie value not set in OAM

In OAM 11g, we tried setting the cookie names in the authorization policies,but it was a unsuccessful attempt since the browser is unable to retrieve the cookies.

Reason for this Issue

The flag SSOOnlyMode needs to be set to false for enabling Authorization Module.

Solution

The parameter SSOOnlyMode in oam-config.xml is set to true. If it is set to below mentioned value it will not invoke the Authorization module.

setting Name="SSOOnlyMode" Type="xsd:boolean"true

To avoid this issue

1. Shutdown all your Servers
1. Modify the file Domain_home/config/fmwconfig/oam-config.xml.
setting Name="SSOOnlyMode" Type="xsd:boolean"false
4. Start all the servers.
5. Retest the issue again.