Friday, November 2, 2012

OIM 11G: Helpful API methods


Today I’ll talk about some new methods available using OIM 11g API.
First java method: How to get any user attribute in OIM.

Fig1: UserAttribute method. With this method you’ll be able to collect any attribute from OIM User.
Source:
1
2
3
4
5
6
7
8
9
public String getUserAttribute(String userName,String getAttribute) throws AccessDeniedException,UserSearchException,NoSuchUserException,UserLookupException, SearchKeyNotUniqueException
{
        UserManager usrService= oimClient.getService(UserManager.class);
        User user = usrService.getDetails("User Login", userName, null);
        HashMap mapAttrs = user.getAttributes(); 
        String temp=(String) mapAttrs.get(getAttribute);
        System.out.println("Output is :" + temp);
  return temp;
}
Example:
If I call ..getUserAttribute(Username, Status);
Expected result:
Second java method: Assign a group to another group.

Fig2: goi.addMemberGroup(groupKey, groupKeytoADD);
Source:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void addGroupToGroup(tcGroupOperationsIntf goi, String groupNametoADD, String groupName) throws tcInvalidMemberGroupException,                                                            tcMemberGroupNotFoundException {
         long groupKeytoADD = getGroupKey(goi, groupNametoADD);
         long groupKey = getGroupKey(goi, groupName);
         if (groupKeytoADD == -1L || groupKey == -1L) {
                 System.out.println("Error adding user to group");
                 return;
         }
         try {
                 goi.addMemberGroup(groupKey, groupKeytoADD);
                 System.out.println("Added Group " + groupName + " to group "+ groupKeytoADD);
         } catch (tcAPIException e) {
                 logger.info(""+e.toString());
         } catch (tcGroupNotFoundException e) {
                 logger.info(""+e.toString());
         }        
 }
You can use these methods into an adapter or any client Java class. Just be aware of the different ways to call tcDataProvider or oimClient.login(OIMUserName,OIMPassword.toCharArray());
In a Java client:
1-You should create a ‘void static main method’.
2-Include this class into your manifest file and deploy as jar.
3-To Run you’ll need these helpful steps(3.0-based on first method above and sending arguments as args[0] and args[1] on ‘static void main method’):
3.1- java -jar yourjarfile.jar username attribute
3.2-If you need to import one lib: java –classpath oimclient.jar jar yourjarfile.jar username attribute
3.2-If you need to import more than one lib: java -cp $CLASSPATH:yourjarfile.jar username attribute
Using: $CLASSPATH=.:./lib/oimclient.jar:./lib/iam-platform-auth-client.jar:./lib/iam-platform-utils.jar:./lib/iam-platform-context.jar
Using tcDataProvider:
1-Add as part of ‘IN’ variables on your OIM adapter.
2-Using DataSet or request from constructor method(tcDataProvider _tcDataPro)
I hope this helps,
Thiago Leoncio.

No comments:

Post a Comment