Search in sources :

Example 16 with IdentityMgtServiceException

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

the class UserInformationRecoveryService method resendSignUpConfiramtionCode.

/**
 * This method is used to resend selef sign up confiration code when user is not recieved email properly
 *
 * @param userName
 * @param code
 * @param profileName
 * @param tenantDomain
 * @return
 * @throws IdentityMgtServiceException
 */
public VerificationBean resendSignUpConfiramtionCode(String userName, String code, String profileName, String tenantDomain) throws IdentityMgtServiceException {
    VerificationBean vBean = new VerificationBean();
    RecoveryProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor();
    if (!IdentityMgtConfig.getInstance().isSaasEnabled()) {
        String loggedInTenant = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        if (tenantDomain != null && !tenantDomain.isEmpty() && !loggedInTenant.equals(tenantDomain)) {
            String msg = "Trying to resend self sign up code  in unauthorized tenant space";
            log.error(msg);
            throw new IdentityMgtServiceException(msg);
        }
        if (tenantDomain == null || tenantDomain.isEmpty()) {
            tenantDomain = loggedInTenant;
        }
    }
    int tenantId;
    try {
        tenantId = Utils.getTenantId(tenantDomain);
    } catch (IdentityException e) {
        vBean = handleError(VerificationBean.ERROR_CODE_UNEXPECTED + " Error while resending confirmation code", e);
        return vBean;
    }
    try {
        if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            carbonContext.setTenantId(tenantId);
            carbonContext.setTenantDomain(tenantDomain);
        }
        try {
            vBean = processor.verifyConfirmationCode(1, userName, code);
            if (!vBean.isVerified()) {
                vBean.setError(VerificationBean.ERROR_CODE_INVALID_CODE);
                return vBean;
            }
        } catch (IdentityException e) {
            vBean = handleError("Error while validating confirmation code for user : " + userName, e);
            return vBean;
        }
        try {
            String listenerClassName = IdentityMgtConfig.getInstance().getProperty(IdentityMgtConstants.PropertyConfig.IDENTITY_MGT_LISTENER_CLASS);
            if (StringUtils.isBlank(listenerClassName)) {
                listenerClassName = IdentityMgtEventListener.class.getName();
            }
            IdentityEventListenerConfig identityEventListenerConfig = IdentityUtil.readEventListenerProperty(UserOperationEventListener.class.getName(), listenerClassName);
            boolean isListenerEnable = true;
            if (identityEventListenerConfig != null) {
                if (StringUtils.isNotBlank(identityEventListenerConfig.getEnable())) {
                    isListenerEnable = Boolean.parseBoolean(identityEventListenerConfig.getEnable());
                }
            }
            IdentityMgtConfig config = IdentityMgtConfig.getInstance();
            if (isListenerEnable && config.isAuthPolicyAccountLockOnCreation()) {
                UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
                userDTO.setTenantId(tenantId);
                UserRecoveryDTO dto = new UserRecoveryDTO(userDTO);
                dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_CONFORM);
                dto.setNotificationType("EMAIL");
                vBean = processor.updateConfirmationCode(1, userName, tenantId);
                dto.setConfirmationCode(vBean.getKey());
                NotificationDataDTO notificationDto = processor.notifyWithEmail(dto);
                vBean.setVerified(notificationDto.isNotificationSent());
                // Send email data only if not internally managed.
                if (!(IdentityMgtConfig.getInstance().isNotificationInternallyManaged())) {
                    vBean.setNotificationData(notificationDto);
                }
            } else {
                vBean.setVerified(true);
            }
        } catch (IdentityException e) {
            vBean = UserIdentityManagementUtil.getCustomErrorMessagesWhenRegistering(e, userName);
            return vBean;
        }
    } finally {
        if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
    return vBean;
}
Also used : VerificationBean(org.wso2.carbon.identity.mgt.beans.VerificationBean) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) UserDTO(org.wso2.carbon.identity.mgt.dto.UserDTO) NotificationDataDTO(org.wso2.carbon.identity.mgt.dto.NotificationDataDTO) RecoveryProcessor(org.wso2.carbon.identity.mgt.RecoveryProcessor) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) UserRecoveryDTO(org.wso2.carbon.identity.mgt.dto.UserRecoveryDTO) IdentityException(org.wso2.carbon.identity.base.IdentityException) IdentityMgtEventListener(org.wso2.carbon.identity.mgt.IdentityMgtEventListener) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) IdentityMgtConfig(org.wso2.carbon.identity.mgt.IdentityMgtConfig)

Example 17 with IdentityMgtServiceException

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

the class UserInformationRecoveryService method getCaptcha.

public CaptchaInfoBean getCaptcha() throws IdentityMgtServiceException {
    if (log.isDebugEnabled()) {
        log.debug("User get captcha image request received");
    }
    try {
        CaptchaUtil.cleanOldCaptchas();
        CaptchaInfoBean bean = CaptchaUtil.generateCaptchaImage();
        if (log.isDebugEnabled()) {
            log.debug("Captcha stored: " + bean.getImagePath());
            log.debug("Captcha generated successfully");
        }
        return bean;
    } catch (Exception e) {
        String errorMessage = "Error while generating captcha";
        log.error(errorMessage, e);
        throw new IdentityMgtServiceException(errorMessage);
    }
}
Also used : CaptchaInfoBean(org.wso2.carbon.captcha.mgt.beans.CaptchaInfoBean) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 18 with IdentityMgtServiceException

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

the class UserInformationRecoveryService method getUserChallengeQuestionIds.

public ChallengeQuestionIdsDTO getUserChallengeQuestionIds(String username, String confirmation) throws IdentityMgtServiceException {
    UserDTO userDTO = null;
    ChallengeQuestionIdsDTO idsDTO = new ChallengeQuestionIdsDTO();
    if (log.isDebugEnabled()) {
        log.debug("User challenge questions id request received with username: " + username);
    }
    try {
        userDTO = Utils.processUserId(username);
    } catch (IdentityException e) {
        idsDTO = handleChallengeIdError(VerificationBean.ERROR_CODE_INVALID_USER + " Error validating user : " + username, e);
        return idsDTO;
    }
    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 = null;
        try {
            bean = processor.verifyConfirmationCode(1, userDTO.getUserId(), confirmation);
            if (bean.isVerified()) {
                bean = processor.updateConfirmationCode(20, userDTO.getUserId(), userDTO.getTenantId());
            } else {
                bean.setVerified(false);
            }
        } catch (IdentityException e1) {
            idsDTO = UserIdentityManagementUtil.getCustomErrorMessagesForChallengeQuestionIds(e1, username);
            if (idsDTO == null) {
                idsDTO = handleChallengeIdError(VerificationBean.ERROR_CODE_UNEXPECTED + " Error when validating " + "code", e1);
            }
            return idsDTO;
        }
        if (bean.isVerified()) {
            try {
                idsDTO = processor.getQuestionProcessor().getUserChallengeQuestionIds(userDTO.getUserId(), userDTO.getTenantId());
                idsDTO.setKey(bean.getKey());
                if (log.isDebugEnabled()) {
                    log.debug("User challenge question response successful for user: " + username);
                }
            } catch (Exception e) {
                idsDTO = handleChallengeIdError(VerificationBean.ERROR_CODE_CHALLENGE_QUESTION_NOT_FOUND + " Error when getting user challenge questions for user : " + username, e);
                return idsDTO;
            }
        } else {
            String msg = "Verification failed for user. Error : " + bean.getError();
            log.error(msg);
            idsDTO.setError(VerificationBean.ERROR_CODE_UNEXPECTED + " " + msg);
            idsDTO.setKey("");
        }
    } finally {
        if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
    return idsDTO;
}
Also used : VerificationBean(org.wso2.carbon.identity.mgt.beans.VerificationBean) UserDTO(org.wso2.carbon.identity.mgt.dto.UserDTO) RecoveryProcessor(org.wso2.carbon.identity.mgt.RecoveryProcessor) ChallengeQuestionIdsDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionIdsDTO) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) IdentityException(org.wso2.carbon.identity.base.IdentityException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 19 with IdentityMgtServiceException

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

the class ChallengeQuestionProcessor method getUserChallengeQuestion.

public UserChallengesDTO getUserChallengeQuestion(String userName, int tenantId, String challengesUri) throws IdentityMgtServiceException {
    UserChallengesDTO dto = null;
    try {
        if (log.isDebugEnabled()) {
            log.debug("Retrieving Challenge question from the user profile.");
        }
        String challengeValue = Utils.getClaimFromUserStoreManager(userName, tenantId, challengesUri);
        if (challengeValue != null) {
            String[] challengeValues = challengeValue.split(IdentityMgtConfig.getInstance().getChallengeQuestionSeparator());
            if (challengeValues != null && challengeValues.length == 2) {
                dto = new UserChallengesDTO();
                dto.setId(challengesUri);
                dto.setQuestion(challengeValues[0].trim());
            }
        } else {
            dto = new UserChallengesDTO();
            dto.setError("Challenge questions have not been answered by the user: " + userName);
        }
    } catch (Exception e) {
        String errorMsg = "Error while getting the challenge questions for the user: " + userName;
        if (log.isDebugEnabled()) {
            log.debug(errorMsg, e);
        }
        dto = new UserChallengesDTO();
        dto.setError(errorMsg);
        throw new IdentityMgtServiceException(errorMsg, e);
    }
    return dto;
}
Also used : UserChallengesDTO(org.wso2.carbon.identity.mgt.dto.UserChallengesDTO) UserStoreException(org.wso2.carbon.user.core.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 20 with IdentityMgtServiceException

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

the class ChallengeQuestionProcessor method getUserChallengeQuestionIds.

public ChallengeQuestionIdsDTO getUserChallengeQuestionIds(String userName, int tenantId) throws IdentityMgtServiceException {
    ChallengeQuestionIdsDTO dto = new ChallengeQuestionIdsDTO();
    if (log.isDebugEnabled()) {
        log.debug("Retrieving Challenge question ids from the user profile.");
    }
    List<String> challengesUris = getChallengeQuestionUris(userName, tenantId);
    if (challengesUris.isEmpty()) {
        String msg = "No associated challenge question found for the user";
        if (log.isDebugEnabled()) {
            log.debug(msg);
        }
        throw new IdentityMgtServiceException(msg);
    }
    String[] ids = new String[challengesUris.size()];
    for (int i = 0; i < challengesUris.size(); i++) {
        ids[i] = challengesUris.get(i).trim();
    }
    dto.setIds(ids);
    return dto;
}
Also used : ChallengeQuestionIdsDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionIdsDTO)

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