Search Admin Roles Using Search Criteria


  1. import java.util.HashMap;
  2. import java.util.Hashtable;
  3. import java.util.List;
  4. import oracle.iam.platform.OIMClient;
  5. import oracle.iam.platform.authopss.vo.AdminRole;
  6. import oracle.iam.platform.entitymgr.vo.SearchCriteria;
  7. import oracle.iam.platformservice.api.AdminRoleService;
  8. import oracle.iam.reconciliation.api.ReconOperationsService;
  9. public class SearchCriteriaTest {
  10.     private final static String serverURL = "t3://localshot:14000";
  11.     private final static String username = "xelsysadm";
  12.     private final static char[] password = "Welcome1".toCharArray();
  13.     private static Hashtable<String, String> env;
  14.     private static ReconOperationsService srv1;
  15.     public static void main(String[] args) {
  16.         String ctxFactory = "weblogic.jndi.WLInitialContextFactory";
  17.         System.setProperty("OIM.AppServerType", "wls");
  18.         System.setProperty("APPSERVER_TYPE", "wls");
  19.         System.setProperty("java.security.auth.login.config", "conf/authwl.conf");
  20.         env = new Hashtable<String, String>();
  21.         env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, ctxFactory);
  22.         env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, serverURL);
  23.         try {
  24.             OIMClient oimClient = new OIMClient(env);
  25.             oimClient.login(username, password);
  26.             AdminRoleService aRoleServ= oimClient.getService(AdminRoleService.class);
  27.             SearchCriteria criteria1 =
  28.                 new SearchCriteria("role_display_name", "OrclOIMApplicationInstanceAdministratorRole", SearchCriteria.Operator.EQUAL);
  29.             SearchCriteria criteria2 = new SearchCriteria("scoped", "0", SearchCriteria.Operator.EQUAL);
  30.             SearchCriteria criteriaFinal1 = new SearchCriteria(criteria1, criteria2, SearchCriteria.Operator.OR);
  31.             SearchCriteria criteriaFinal2 = new SearchCriteria(criteria2, criteria1, SearchCriteria.Operator.OR);
  32.             try {
  33.                 System.out.println("========== First query ==========");
  34.                 searchRolesPerCriteria(aRoleServ, null, criteriaFinal1);
  35.                 System.out.println("========== Second query ==========");
  36.                 searchRolesPerCriteria(aRoleServ, null, criteriaFinal2);
  37.             } catch (Exception e) {
  38.                 e.printStackTrace();
  39.             }
  40.         } catch (Exception e) {
  41.             e.printStackTrace();
  42.         }
  43.     }
  44.     private static void searchRolesPerCriteria(AdminRoleService aRoleServ, HashMap<String, Object> configParams,
  45.                                                SearchCriteria criteriaFinal1) throws Exception {
  46.         List<AdminRole> adminRoleList = aRoleServ.search(criteriaFinal1, configParams);
  47.         System.out.println("Using Search: List Size [" + adminRoleList.size() + "]");
  48.         for (AdminRole ar : adminRoleList) {
  49.             System.out.print("Role Id : [" + ar.getRoleId() + "]\t");
  50.             System.out.println("Role Name : [" + ar.getRoleName() + "]");
  51.         }
  52.     }
  53. }

No comments:

Post a Comment