OIM API - Code Snippet to get all Accounts Provisioned to User.

public List<Long> fetchProvisionedAccountsOfUser(String usrKey){
            final String logp = CN + " :: fetchProvisionedAccountsOfUser - ";
            LOGGER.debug(logp + "START");
            List<Long> appInstanceKeys = new ArrayList<Long>();

            try{               
                ProvisioningService provService = Platform.getService(ProvisioningService.class);
                List<Account> provAccounts = provService.getAccountsProvisionedToUser(usrKey);

                for(Account act : provAccounts){
                    if ((act.getAccountStatus().equalsIgnoreCase("Provisioned"))
                                    || (act.getAccountStatus().equalsIgnoreCase("Enabled"))){     
                        Long appInstanceKey = act.getAppInstance().getApplicationInstanceKey();
                        
                        if (!appInstanceKeys.contains(appInstanceKey)){
                                appInstanceKeys.add(appInstanceKey);
                        }
                    }
                }
            } catch (Exception e) {
                    LOGGER.error("Error while fetching provisioned accounts of User" + e);
            }
            LOGGER.debug(logp + "END");
            return appInstanceKeys;
    }

No comments:

Post a Comment