Thursday, 30 June 2011

Code to get(retrive) the Groups assigned to a OIM User

This code will return the groups assigned to a user present in OIM

//#######Getting User Key##########

public long getUserKey(String obj){
long key = 0;
HashMap userMap = new HashMap();

try {
userMap.put("Users.User ID", obj);
tcResultSet moResultSet = moUserUtility.findUsers(userMap);

for (int i=0; i < moResultSet.getRowCount(); i++){ moResultSet.goToRow(i); key = moResultSet.getLongValue("Users.Key"); } }catch(Exception e){ e.printStackTrace(); } return key; } public long getGroupKey(String obj){ long key = 0; HashMap userMap = new HashMap();

try {
userMap.put("Groups.Group Name", obj);
tcResultSet moResultSet = moGroupUtility.findGroups(userMap);

for (int i=0; i < moResultSet.getRowCount(); i++){ moResultSet.goToRow(i); key = moResultSet.getLongValue("Groups.Key"); } }catch(Exception e){ e.printStackTrace(); } return key; } //##########Getting the OIM groups for the particulat User######### public ArrayList getGroups(String uid){
ArrayList GroupList = new ArrayList();
String str = "";
HashMap userMap = new HashMap();

try {
userMap.put("Users.User ID", uid);
System.out.println("UID==>"+uid);
tcResultSet moResultSet = moUserUtility.getGroups(getUserKey(uid));

for (int i=0; i < moResultSet.getRowCount(); i++){ moResultSet.goToRow(i); str = moResultSet.getStringValueFromColumn(1); if ((!((str.equals("ALL USERS")) || (str.equals("SYSTEM ADMINISTRATORS"))||(str.equals("SELF OPERATORS"))))) GroupList.add(str); System.out.println("Groups assigned to the user"+uid+"==>"+str);
}
}catch(Exception e){
e.printStackTrace();
}
return GroupList;

}

No comments:

Post a Comment