OIM API for Search Role


  1. package com.oimacademy.role;
  2. import static oracle.iam.identity.rolemgmt.api.RoleManagerConstants.ROLE_CATEGORY_KEY;
  3. import static oracle.iam.identity.rolemgmt.api.RoleManagerConstants.ROLE_DESCRIPTION;
  4. import static oracle.iam.identity.rolemgmt.api.RoleManagerConstants.ROLE_DISPLAY_NAME;
  5. import static oracle.iam.identity.rolemgmt.api.RoleManagerConstants.ROLE_KEY;
  6. import static oracle.iam.identity.rolemgmt.api.RoleManagerConstants.ROLE_LDAP_DN;
  7. import static oracle.iam.identity.rolemgmt.api.RoleManagerConstants.ROLE_NAME;
  8. import static oracle.iam.identity.rolemgmt.api.RoleManagerConstants.ROLE_OWNER_KEY;
  9. import static oracle.iam.identity.utils.Constants.SEARCH_ENDROW;
  10. import static oracle.iam.identity.utils.Constants.SEARCH_SORTEDBY;
  11. import static oracle.iam.identity.utils.Constants.SEARCH_SORTORDER;
  12. import static oracle.iam.identity.utils.Constants.SEARCH_STARTROW;
  13. import java.util.HashMap;
  14. import java.util.HashSet;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.Set;
  18. import oracle.iam.identity.rolemgmt.api.RoleManager;
  19. import oracle.iam.identity.rolemgmt.vo.Role;
  20. import oracle.iam.platform.entitymgr.spi.entity.Searchable;
  21. import oracle.iam.platform.entitymgr.vo.SearchCriteria;
  22. import com.oimacademy.connection.Platform;
  23. public class SearchRole {
  24.    protected static final String ROLE_NAME_PREFIX = "load*";
  25.    protected RoleManager m_roleManager = Platform.getService(RoleManager.class);   
  26.    public static void main(String args[]) throws Exception{
  27.     //long startTime = System.currentTimeMillis();  
  28.     System.out.println("***");
  29.     new SearchRole().searchRoleConfigParams(ROLE_NAME_PREFIX);
  30. /*    long endTime   = System.currentTimeMillis();
  31.     long totalTime = endTime - startTime;
  32.     System.out.println(totalTime/1000.0);*/
  33.    }
  34.  public List searchRoleConfigParams(String ROLE_NAME_PREFIX) throws Exception {
  35.      SearchCriteria criteria =   new SearchCriteria(ROLE_NAME, ROLE_NAME_PREFIX, SearchCriteria.Operator.EQUAL);
  36.      Set<String> searchAttrs = getSearchRoleAttributes();  
  37.      Map<String, Object> configParams = new HashMap<String, Object>();
  38.      int start = 0;
  39.      int end = 250;
  40.      configParams.put(SEARCH_STARTROW, start);
  41.      configParams.put(SEARCH_ENDROW, end);
  42.      configParams.put(SEARCH_SORTORDER, Searchable.SortOrder.DESCENDING);
  43.      configParams.put(SEARCH_SORTEDBY,ROLE_NAME);  
  44.      List<Role> roles =null;;
  45.      try {
  46.          roles =  m_roleManager.search(criteria, searchAttrs, configParams);
  47.         // System.out.println(roles);
  48.      } catch (Exception e) {
  49.        e.printStackTrace();
  50.      }
  51.      return roles; } 
  52.     protected HashSet<String> getSearchRoleAttributes() {
  53.         // NOTE for SRGs we can't use getEntityAttributes()
  54.         HashSet<String> searchAttributes = new HashSet<String>();
  55.         searchAttributes.add(ROLE_KEY);
  56.         searchAttributes.add(ROLE_NAME);
  57.         searchAttributes.add(ROLE_DISPLAY_NAME);
  58.         searchAttributes.add(ROLE_DESCRIPTION);
  59.         searchAttributes.add(ROLE_OWNER_KEY);
  60.         searchAttributes.add(ROLE_CATEGORY_KEY);
  61.         searchAttributes.add(ROLE_LDAP_DN);
  62.         return searchAttributes;
  63.     }
  64. }

No comments:

Post a Comment