list of accounts of a specific login id

list of accounts of a specific login id


We can get the list of accounts of a user in OIM console, Accounts Tab.
Now we are getting the accounts with the help of  OIM api.
we have to write the java code for this.

code:
package client;
import Thor.API.Operations.tcGroupOperationsIntf;
import java.util.Hashtable;
import java.util.logging.Logger;
import oracle.iam.platform.OIMClient;
import Thor.API.Operations.tcUserOperationsIntf;
import Thor.API.tcResultSet;
import java.util.ArrayList;
import java.util.List;
import oracle.iam.provisioning.api.ProvisioningService;
import oracle.iam.provisioning.exception.GenericProvisioningException;
import oracle.iam.provisioning.exception.UserNotFoundException;
import oracle.iam.provisioning.vo.Account;
import java.util.HashMap;

public class ListOfAccountsOfAUser {
  public ListOfAccountsOfAUser() {
    super();
  }
 
  private static final String CLASS_NAME = ListOfAccountsOfAUser.class.getSimpleName();
  private static Logger logger = Logger.getLogger("Oimapi.OCS.SCHTASK");
  private static String OIMUserName = "xelsysadm";
  private static String OIMPassword = "";
  private static String OIMURL = "t3://<HostName>:<PortNo>";
  private static String OIMInitialContextFactory ="weblogic.jndi.WLInitialContextFactory";
  static ListOfAccountsOfAUser accounts = new ListOfAccountsOfAUser();
      OIMClient client=loginWithCustomEnv();
     
   // OIM Client Initiallization
  public static OIMClient loginWithCustomEnv() {
  Hashtable env = new Hashtable();
  env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, OIMInitialContextFactory);
  env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, OIMURL);
  // New Properties needs to be added into system property.
  System.setProperty("OIM.AppServerType", "wls");
  System.setProperty("APPSERVER_TYPE", "wls");
  System.setProperty("java.security.auth.login.config","C:\\Oracle\\Middleware\\Oracle_IDM1\\server\\config\\authwl.conf");
  OIMClient client = new OIMClient(env);
  try {
  System.out.println("12");
  client = new OIMClient(env);
  System.out.println("Initiating Oim Client");
  client.login(OIMUserName, OIMPassword.toCharArray());
  System.out.println("got OIm client successfully");
  System.out.println("Client - " + client);
  } catch (Exception e) {
  System.out.println("Error: " + e);
  client = null;
        }
  return client;
  }

  public static void main(String[] ar) throws UserNotFoundException,
                                              GenericProvisioningException {
   
  
    List<Account> listOfAccounts = new ArrayList<Account>();
    listOfAccounts=accountsList("<User Login>");
    System.out.println("List of accounts of a user : ");
   
    for(Account acc : listOfAccounts){
      if(acc.getAccountStatus().equalsIgnoreCase("enabled") || acc.getAccountStatus().equalsIgnoreCase("provisioned")){
      System.out.println(acc.getAppInstance().getDisplayName()+" "+acc.getAccountStatus());
      }
    }
   
  }
 
  public static List accountsList(String userID) throws UserNotFoundException,
                                                        GenericProvisioningException {
    List<Account> listOfAccounts = new ArrayList<Account>();
    ProvisioningService provServ = accounts.client.getService(ProvisioningService.class);
    tcUserOperationsIntf intf = accounts.client.getService(tcUserOperationsIntf.class);
    String userKey=""+getUserKey(intf, userID);
   
    listOfAccounts=provServ.getAccountsProvisionedToUser(userKey);
   
    return listOfAccounts;
  }
 
  public static long getUserKey(tcUserOperationsIntf usrIntf, String usrLogin) {
    long usrKey = 0;
    try {
      HashMap hm = new HashMap();
      hm.put("Users.User ID", usrLogin);
      tcResultSet rs = usrIntf.findUsers(hm);
      rs.goToRow(0);
      usrKey = rs.getLongValue("Users.Key");

    } catch (Exception e) {
      e.printStackTrace();
    }
    return usrKey;
  }
 
}



By using this program we will get the accounts of a particular user. In this program, we have to give user Login as input in main method.
By using that user login, we will get user key by sing "tcUserOperationsIntf". In this we will get any attribute of the user. Here we are writing one method for getting the user key.
findUsers(hashMap) ===> This method taking hashmap as input and providing all the user details as a resultset. In that result set we will have all user data. By using that user data we can get all attributes of the users. like user key, first name, last name etc...

hashmap<User> ===> hashmap.put("Users.User ID", <value>);
here we are adding the userlogin into hashmap. Key field as user attributes defaults. value field as, for which user we need to get the data, that user login.
based on that user key as input for the method "getAccountsProvisionedToUser", which is taking user key as string input.
This method is available in "ProvisioningService".

tcUserOperationsInf:
https://docs.oracle.com/cd/E52734_01/oim/OMJAV/Thor/API/Operations/tcUserOperationsIntf.html
go through the above link for tcUserOpetationsIntf
ProvisioningService :
https://docs.oracle.com/cd/E52734_01/oim/OMJAV/oracle/iam/provisioning/api/ProvisioningService.html

Comments

Post a Comment

Popular posts from this blog

Grant Entitlements To User Using API

CREATING USER BY USING DYNAMIC VALUES