OIM API To Search User , get User Memberships and Get Role Category Details


package com.users;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.connection.Platform;

import oracle.iam.identity.rolemgmt.api.RoleCategoryManager;
import oracle.iam.identity.rolemgmt.api.RoleManager;
import oracle.iam.identity.rolemgmt.api.RoleManagerConstants;
import oracle.iam.identity.rolemgmt.vo.Role;
import oracle.iam.identity.rolemgmt.vo.RoleCategory;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;

public class GetUserMembershipsAndRoleCategory {
 public static void main(String[] args) throws Exception {
  
  
  RoleManager roleMgr = Platform.getService(RoleManager.class);
        UserManager usrMgr = Platform.getService(UserManager.class);
        RoleCategoryManager roleCategoryMgr = Platform.getService(RoleCategoryManager.class);
        
        String usrLogin = "TUSER";
        String roleCategoryPattern = "roleCat";
        Set<Role> matchingRoles = new HashSet<Role>();

        SearchCriteria criteria = new SearchCriteria("User Login",
            usrLogin, SearchCriteria.Operator.BEGINS_WITH);
        Set retSet = new HashSet();
        retSet.add("usr_key");
        retSet.add("User Login");
        retSet.add("First Name");
        retSet.add("Last Name");

        List<User> users = usrMgr.search(criteria, retSet, null);
        User user = users.get(0);
  
  List<Role> userRoles = roleMgr.getUserMemberships(user.getEntityId(), false);
  
  for (Role role : userRoles) {
   Long catKey = (Long)role.getAttributes().get(RoleManagerConstants.ROLE_CATEGORY_KEY);
   RoleCategory roleCat = roleCategoryMgr.getDetails(catKey.toString(), new HashSet<String>());
   if (roleCat.getName().startsWith(roleCategoryPattern)) {
    matchingRoles.add(role);
   }
  }
  
  Iterator<Role> it = matchingRoles.iterator();
  while (it.hasNext()) {
   Role r = it.next();
   System.out.println(r.getName());
  }
 }
}

No comments:

Post a Comment

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts