Search in sources :

Example 1 with IdentityMgtServiceException

use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method getUserList.

private static String[] getUserList(int tenantId, String claim, String value, String profileName) throws IdentityMgtServiceException {
    org.wso2.carbon.user.core.UserStoreManager userStoreManager = null;
    String[] userList = null;
    RealmService realmService = IdentityMgtServiceComponent.getRealmService();
    try {
        if (realmService.getTenantUserRealm(tenantId) != null) {
            userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) realmService.getTenantUserRealm(tenantId).getUserStoreManager();
        }
    } catch (Exception e) {
        String msg = "Error retrieving the user store manager for the tenant";
        throw new IdentityMgtServiceException(msg, e);
    }
    try {
        if (userStoreManager != null) {
            userList = userStoreManager.getUserList(claim, value, profileName);
        }
        return userList;
    } catch (Exception e) {
        String msg = "Unable to retrieve the claim for the given tenant";
        throw new IdentityMgtServiceException(msg, e);
    }
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 2 with IdentityMgtServiceException

use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method getAllUserIdentityClaims.

/**
 * Returns all user claims
 *
 * @param userName
 * @return
 * @throws IdentityMgtServiceException
 */
public static UserIdentityClaimDTO[] getAllUserIdentityClaims(String userName) throws IdentityMgtServiceException {
    int tenantId = 0;
    try {
        tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        UserStoreManager userStoreManager = IdentityMgtServiceComponent.getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
        // read all claims and convert them to UserIdentityClaimDTO
        Claim[] claims = userStoreManager.getUserClaimValues(userName, null);
        List<UserIdentityClaimDTO> allDefaultClaims = new ArrayList<UserIdentityClaimDTO>();
        for (Claim claim : claims) {
            if (claim.getClaimUri().contains(UserCoreConstants.DEFAULT_CARBON_DIALECT)) {
                UserIdentityClaimDTO claimDTO = new UserIdentityClaimDTO();
                claimDTO.setClaimUri(claim.getClaimUri());
                claimDTO.setClaimValue(claim.getValue());
                allDefaultClaims.add(claimDTO);
            }
        }
        UserIdentityClaimDTO[] claimDTOs = new UserIdentityClaimDTO[allDefaultClaims.size()];
        return allDefaultClaims.toArray(claimDTOs);
    } catch (UserStoreException e) {
        throw new IdentityMgtServiceException("Error while getting user identity claims", e);
    }
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) UserIdentityClaimDTO(org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO) Claim(org.wso2.carbon.user.api.Claim)

Example 3 with IdentityMgtServiceException

use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method getUsernameByClaims.

/**
 * @param claims
 * @param tenantId
 * @return
 * @throws IdentityMgtServiceException - If user cannot be retrieved using the provided claims.
 */
public static String getUsernameByClaims(UserIdentityClaimDTO[] claims, int tenantId) throws IdentityMgtServiceException {
    if (claims == null || claims.length < 1) {
        throw new IdentityMgtServiceException("No fields found for user search");
    }
    String userName = null;
    String[] tempUserList = null;
    // passed array.
    for (int i = 0; i < claims.length; i++) {
        UserIdentityClaimDTO claim = claims[i];
        if (claim.getClaimUri() != null && claim.getClaimValue() != null) {
            String[] userList = getUserList(tenantId, claim.getClaimUri(), claim.getClaimValue(), null);
            if (userList != null && userList.length > 0) {
                if (userList.length == 1) {
                    return userList[0];
                } else {
                    // If more than one user find the first matching user. Hence need to define unique claims
                    if (tempUserList != null) {
                        for (int j = 0; j < tempUserList.length; j++) {
                            for (int x = 0; x < userList.length; x++) {
                                if (tempUserList[j].equals(userList[x])) {
                                    return userList[x];
                                }
                            }
                        }
                    }
                    tempUserList = userList;
                    continue;
                }
            } else {
                throw new IdentityMgtServiceException("No associated user is found for given claim values");
            }
        }
    }
    return userName;
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserIdentityClaimDTO(org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO)

Example 4 with IdentityMgtServiceException

use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.

the class UserInformationRecoveryService method getUserChallengeQuestion.

/**
 * To get the challenge question for the user.
 *
 * @param userName
 * @param confirmation
 * @param questionId   - Question id returned from the getUserChanllegneQuestionIds
 *                     method.
 * @return Populated question bean with the question details and the key.
 * @throws IdentityMgtServiceException
 */
public UserChallengesDTO getUserChallengeQuestion(String userName, String confirmation, String questionId) throws IdentityMgtServiceException {
    UserDTO userDTO = null;
    UserChallengesDTO userChallengesDTO = new UserChallengesDTO();
    if (log.isDebugEnabled()) {
        log.debug("User challenge question request received with username :" + userName);
    }
    try {
        userDTO = Utils.processUserId(userName);
    } catch (IdentityException e) {
        return handleChallengesError(VerificationBean.ERROR_CODE_INVALID_USER + " Error validating user : " + userName, null);
    }
    try {
        if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            carbonContext.setTenantId(userDTO.getTenantId());
            carbonContext.setTenantDomain(userDTO.getTenantDomain());
        }
        RecoveryProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor();
        VerificationBean bean;
        try {
            bean = processor.verifyConfirmationCode(20, userDTO.getUserId(), confirmation);
            if (bean.isVerified()) {
                bean = processor.updateConfirmationCode(40, userDTO.getUserId(), userDTO.getTenantId());
            } else if (processor.verifyConfirmationCode(30, userDTO.getUserId(), confirmation).isVerified()) {
                bean = processor.updateConfirmationCode(40, userDTO.getUserId(), userDTO.getTenantId());
            } else {
                bean.setVerified(false);
            }
        } catch (IdentityException e) {
            userChallengesDTO = UserIdentityManagementUtil.getCustomErrorMessagesForChallengQuestions(e, userName);
            if (userChallengesDTO == null) {
                userChallengesDTO = handleChallengesError(VerificationBean.ERROR_CODE_INVALID_CODE + " Invalid confirmation code for user : " + userName, e);
            }
            return userChallengesDTO;
        }
        if (bean.isVerified()) {
            userChallengesDTO = processor.getQuestionProcessor().getUserChallengeQuestion(userDTO.getUserId(), userDTO.getTenantId(), questionId);
            userChallengesDTO.setKey(bean.getKey());
            userChallengesDTO.setVerfied(true);
            if (log.isDebugEnabled()) {
                log.debug("User challenge question retrieved successfully");
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Verification failed for user. Error : " + bean.getError());
            }
            userChallengesDTO.setError(VerificationBean.ERROR_CODE_INVALID_USER + " " + bean.getError());
        }
    } finally {
        if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
    return userChallengesDTO;
}
Also used : VerificationBean(org.wso2.carbon.identity.mgt.beans.VerificationBean) UserChallengesDTO(org.wso2.carbon.identity.mgt.dto.UserChallengesDTO) UserDTO(org.wso2.carbon.identity.mgt.dto.UserDTO) RecoveryProcessor(org.wso2.carbon.identity.mgt.RecoveryProcessor) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 5 with IdentityMgtServiceException

use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.

the class AccountCredentialMgtConfigService method getEmailConfig.

/**
 * This method is used to load the tenant specific Email template configurations.
 *
 * @return an array of templates.
 * @throws IdentityMgtServiceException
 */
public EmailTemplateDTO[] getEmailConfig() throws IdentityMgtServiceException {
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    Config emailConfig = null;
    EmailTemplateDTO[] templates = null;
    ConfigBuilder configBuilder = ConfigBuilder.getInstance();
    try {
        emailConfig = configBuilder.loadConfiguration(ConfigType.EMAIL, StorageType.REGISTRY, tenantId);
        if (emailConfig != null) {
            templates = EmailConfigTransformer.transform(emailConfig.getProperties());
        }
    } catch (Exception e) {
        log.error("Error occurred while loading email configuration", e);
        throw new IdentityMgtServiceException("Error occurred while loading email configuration");
    }
    return templates;
}
Also used : EmailTemplateDTO(org.wso2.carbon.identity.mgt.dto.EmailTemplateDTO) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) Config(org.wso2.carbon.identity.mgt.config.Config) EmailNotificationConfig(org.wso2.carbon.identity.mgt.config.EmailNotificationConfig) ConfigBuilder(org.wso2.carbon.identity.mgt.config.ConfigBuilder) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException)

Aggregations

IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)37 IdentityException (org.wso2.carbon.identity.base.IdentityException)33 UserStoreException (org.wso2.carbon.user.api.UserStoreException)25 UserDTO (org.wso2.carbon.identity.mgt.dto.UserDTO)18 RecoveryProcessor (org.wso2.carbon.identity.mgt.RecoveryProcessor)15 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)15 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)13 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)11 UserChallengesDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesDTO)9 ChallengeQuestionProcessor (org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor)8 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)8 UserRecoveryDTO (org.wso2.carbon.identity.mgt.dto.UserRecoveryDTO)7 UserIdentityClaimDTO (org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO)5 ChallengeQuestionDTO (org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)4 NotificationDataDTO (org.wso2.carbon.identity.mgt.dto.NotificationDataDTO)4 RealmService (org.wso2.carbon.user.core.service.RealmService)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 IdentityEventListenerConfig (org.wso2.carbon.identity.core.model.IdentityEventListenerConfig)2 IdentityMgtConfig (org.wso2.carbon.identity.mgt.IdentityMgtConfig)2