Saturday, 24 March 2018

OIM API - Code Snippet to get User Key by User Login.

public String getUserKeyByUserLogin(String userLogin){
        HashSet<String> attrsToFetch = new HashSet<String>();
        attrsToFetch.add(UserManagerConstants.AttributeName.USER_KEY.getId());

        String usrKey = "";
        try{     
            //get user manager service
            UserManager userService = Platform.getService(UserManager.class);
           
            User user = userService.getDetails(userLogin, attrsToFetch, true);
            usrKey = user.getEntityId();
        }catch(NoSuchUserException e){
            e.printStackTrace();
        }catch(UserLookupException e){
            e.printStackTrace();
        }catch(AccessDeniedException e){
            e.printStackTrace();
        }
        return usrKey;
 }


Happy Learning!!!

No comments:

Post a Comment