OIM API To Get Accounts List From Logged In User


  1. package com.oimacademy.NeedEvaluate;
  2. import java.lang.annotation.AnnotationTypeMismatchException;
  3. import java.util.HashMap;
  4. import java.util.Hashtable;
  5. import java.util.List;
  6. import javax.faces.validator.ValidatorException;
  7. import javax.management.RuntimeErrorException;
  8. import javax.security.auth.login.LoginException;
  9. import oracle.iam.identity.exception.NoSuchUserException;
  10. import oracle.iam.identity.exception.UserLookupException;
  11. import oracle.iam.identity.exception.UserSearchException;
  12. import oracle.iam.platform.OIMClient;
  13. import oracle.iam.platform.entitymgr.vo.SearchCriteria;
  14. import oracle.iam.provisioning.api.ProvisioningConstants;
  15. import oracle.iam.provisioning.api.ProvisioningService;
  16. import oracle.iam.provisioning.exception.ApplicationInstanceNotFoundException;
  17. import oracle.iam.provisioning.exception.GenericAppInstanceServiceException;
  18. import oracle.iam.provisioning.exception.GenericProvisioningException;
  19. import oracle.iam.provisioning.exception.UserNotFoundException;
  20. import oracle.iam.provisioning.vo.Account;
  21. import Thor.API.tcResultSet;
  22. import Thor.API.Operations.tcLookupOperationsIntf;
  23. import Thor.API.Operations.tcUserOperationsIntf;
  24. import Thor.API.Security.XLClientSecurityAssociation;
  25. public class GetAccountListsFromLoggedInUser {        
  26.     public GetAccountListsFromLoggedInUser() {
  27.         super();
  28.     }

  29.     public static void main(String[] args) throws Exception, AnnotationTypeMismatchException {
  30.        
  31.             System.out.println("In Main Method ....!!!!!");           
  32.             GetAccountList();            
  33.     }
  34.     public static boolean GetAccountList() throws GenericProvisioningException, UserSearchException, UserNotFoundException, RuntimeErrorException, NullPointerException, LoginException, GenericAppInstanceServiceException, ApplicationInstanceNotFoundException, ClassNotFoundException,
  35.                                                           NoSuchUserException, UserLookupException, ValidatorException {                     
  36.                String ctxFactory = "weblogic.jndi.WLInitialContextFactory";              
  37.                     System.setProperty("APPSERVER_TYPE", "wls");             
  38.                Hashtable env = new Hashtable();
  39.                env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, ctxFactory);               
  40.                env.put(OIMClient.APPSERVER_TYPE_WEBLOGIC,"wls");
  41.                 //Establishing OIM Client
  42.                 OIMClient oimClient =new OIMClient(env);        
  43.                 try{               
  44.                 XLClientSecurityAssociation.setClientHandle(oimClient);              
  45.                 }catch(Exception e) {
  46.                     System.out.println(e);
  47.                 }          
  48.           String descriptionArray[] = new String[50];
  49.           Long accountIdArray[] = new Long[50];
  50.             int z3 =0;          
  51.           try {
  52.              boolean isAccountExist = false;
  53.               ProvisioningService proSer = oimClient.getService(ProvisioningService.class);
  54.               
  55.               tcUserOperationsIntf userOps = oimClient.getService(tcUserOperationsIntf.class);
  56.               tcResultSet rs = userOps.getSelfProfile();
  57.               String usrKey = rs.getStringValue("Users.Key");
  58.               String userLogin = rs.getStringValue("Users.User ID");
  59.               SearchCriteria provisionedCriterion = new SearchCriteria(ProvisioningConstants.AccountSearchAttribute.ACCOUNT_STATUS.getId(), ProvisioningConstants.ObjectStatus.PROVISIONED.getId(), SearchCriteria.Operator.EQUAL);
  60.               System.out.println("User Logged In::"+userLogin+"::usrKey::"+usrKey);          
  61.               List<Account> provInstList = proSer.getAccountsProvisionedToUser(usrKey, provisionedCriterion, new HashMap<String,Object>(), true);
  62.                 System.out.println("Prov List::"+provInstList.toString()); // used to print the Accounts provisioned list
  63.           tcLookupOperationsIntf lookupIntf = oimClient.getService(tcLookupOperationsIntf.class);
  64.           tcResultSet lookupVal = lookupIntf.getLookupValues("Lookup.OID.Accounts");
  65.               for(Account ac : provInstList){
  66.                   String accountID = ac.getAccountID();                  
  67.                   System.out.println("Account ID::"+accountID);                  
  68.                   long accountId = Long.parseLong(accountID);
  69.                   String description= ac.getAppInstance().getDescription();
  70.                   System.out.println("Account ID::"+accountID);
  71.                       for(int i=0;i<lookupVal.getRowCount();i++){
  72.                           lookupVal.goToRow(i);
  73.                           if(lookupVal.getStringValue("Lookup Definition.Lookup Code Information.Code Key").equalsIgnoreCase(description)){
  74.                            descriptionArray[z3] = description;
  75.                            accountIdArray[z3] = accountId;
  76.                            isAccountExist = true;
  77.                         z3++;
  78.                         }                        
  79.                         }
  80.                           }
  81.                       for(int x1 =0; descriptionArray[x1]!=null| accountIdArray[x1]!=null; x1++){
  82.                           System.out.println(descriptionArray[x1]);
  83.                           System.out.println(accountIdArray[x1]);
  84.                       }
  85.                     return isAccountExist;
  86.                   } catch (Exception e) {
  87.                   System.out.println(e);
  88.                   return false;
  89.                   }                             
  90.            }
  91. }

2 comments:

  1. Your blog is big and there is a lot of good information! Thanks This Iam Solutions easy-to-use active directory user termination tool allows IT administrators to automate common tasks when an employee leaves the company. Try out today!

    ReplyDelete
  2. Can we get the reverse? I am doing reconciliation from target system and need to find out the user key from the account id coming from target system. Thanks for the help

    ReplyDelete