Thursday, September 3, 2015

OIM 11G R2 creating Roles with roleCategory


  1. package oimclient;

  2. import java.util.HashMap;
  3. import java.util.HashSet;
  4. import java.util.Hashtable;
  5. import java.util.List;
  6. import java.util.Set;

  7. import oracle.iam.identity.rolemgmt.api.RoleCategoryManager;
  8. import oracle.iam.identity.rolemgmt.api.RoleManager;
  9. import oracle.iam.identity.rolemgmt.api.RoleManagerConstants;
  10. import oracle.iam.identity.rolemgmt.vo.Role;
  11. import oracle.iam.identity.rolemgmt.vo.RoleCategory;
  12. import oracle.iam.identity.rolemgmt.vo.RoleManagerResult;
  13. import oracle.iam.platform.OIMClient;
  14. import oracle.iam.platform.entitymgr.vo.SearchCriteria;

  15. public class CreateRoleWithCategory {
  16.     public CreateRoleWithCategory() {
  17.         super();
  18.     }
  19.     public static void main(String[] args) throws Exception {
  20.         Hashtable env = new Hashtable();
  21.         env.put("java.naming.provider.url", "t3://localhost:14000");
  22.         env.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
  23.         System.setProperty("java.security.auth.login.config","G:/Oracle/Middleware/Oracle_IDM1/server/config/authwl.conf");
  24.         System.setProperty("APPSERVER_TYPE","wls");

  25.         OIMClient oimClient = new OIMClient(env);
  26.         oimClient.login("xelsysadm", "Welcome1".toCharArray());
  27.                 
  28.         String roleName = "Testrole"; 
  29.         String categoryName = "TestroleCat";
  30.                            
  31.         RoleManager roleMgr = oimClient.getService(RoleManager.class);
  32.         RoleCategoryManager roleCategoryMgr = oimClient.getService(RoleCategoryManager.class);        
  33.                     
  34.         RoleManagerResult roleResult = null;
  35.         HashMap<String, Object> createAttributes = new HashMap<String, Object>();
  36.                            
  37.         createAttributes.put(RoleManagerConstants.ROLE_NAME, roleName);
  38.         createAttributes.put(RoleManagerConstants.ROLE_DISPLAY_NAME, roleName);
  39.         createAttributes.put(RoleManagerConstants.ROLE_DESCRIPTION, roleName);
  40.         createAttributes.put(RoleManagerConstants.ROLE_CATEGORY_NAME, categoryName);
  41.         createAttributes.put(RoleManagerConstants.ROLE_CATEGORY_DESCRIPTION, categoryName + " Description");
  42.                 
  43.         RoleCategory roleCategory = new RoleCategory(createAttributes);
  44.         
  45.         roleResult = roleCategoryMgr.create(roleCategory);
  46.                             
  47.         Role role = new Role(createAttributes);
  48.         roleResult = roleMgr.create(role);
  49.         String entityId = roleResult.getEntityId();
  50.         System.out.println("Successfully Created role with key = " + entityId);
  51.     }
  52. }


No comments:

Post a Comment

Other Posts