Search in sources :

Example 11 with UserRecoveryDTO

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

the class UserInformationRecoveryService method verifyAccount.

/**
 * Verifies the user against the provided claims and captcha information.
 *
 * @param claims
 * @param captcha
 * @param tenantDomain
 * @return
 * @throws IdentityMgtServiceException
 */
public VerificationBean verifyAccount(UserIdentityClaimDTO[] claims, CaptchaInfoBean captcha, String tenantDomain) throws IdentityMgtServiceException {
    VerificationBean vBean = new VerificationBean();
    if (IdentityMgtConfig.getInstance().isCaptchaVerificationInternallyManaged()) {
        try {
            CaptchaUtil.processCaptchaInfoBean(captcha);
        } catch (Exception e) {
            vBean = handleError(VerificationBean.ERROR_CODE_INVALID_CAPTCHA + " Error processing captcha", e);
            return vBean;
        }
    }
    if (!IdentityMgtConfig.getInstance().isSaasEnabled()) {
        String loggedInTenant = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        if (tenantDomain != null && !tenantDomain.isEmpty() && !loggedInTenant.equals(tenantDomain)) {
            String msg = "Trying to verify account unauthorized tenant space";
            log.error(msg);
            throw new IdentityMgtServiceException(msg);
        }
        if (tenantDomain == null || tenantDomain.isEmpty()) {
            tenantDomain = loggedInTenant;
        }
    }
    try {
        int tenantId = Utils.getTenantId(tenantDomain);
        String userName = UserIdentityManagementUtil.getUsernameByClaims(claims, tenantId);
        if (userName != null) {
            UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
            userDTO.setTenantId(tenantId);
            UserRecoveryDTO dto = new UserRecoveryDTO(userDTO);
            dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_ID_RECOVERY);
            dto.setNotificationType("EMAIL");
            RecoveryProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor();
            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.setError("User not found");
            vBean.setVerified(false);
        }
    } catch (Exception e) {
        vBean = handleError(VerificationBean.ERROR_CODE_INVALID_USER + " Error verifying user account", e);
        return vBean;
    }
    return vBean;
}
Also used : VerificationBean(org.wso2.carbon.identity.mgt.beans.VerificationBean) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserDTO(org.wso2.carbon.identity.mgt.dto.UserDTO) NotificationDataDTO(org.wso2.carbon.identity.mgt.dto.NotificationDataDTO) RecoveryProcessor(org.wso2.carbon.identity.mgt.RecoveryProcessor) UserRecoveryDTO(org.wso2.carbon.identity.mgt.dto.UserRecoveryDTO) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 12 with UserRecoveryDTO

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

the class UserIdentityManagementAdminService method enableUserAccount.

/**
 * Admin enables the user account.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void enableUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.enableUserAccount(userNameWithoutDomain, userStoreManager);
        audit.info(String.format(AUDIT_MESSAGE, getUser(), "Enable user account", userName, "Notification type :" + notificationType, SUCCESS));
        int tenantID = userStoreManager.getTenantId();
        String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
        boolean isNotificationSending = IdentityMgtConfig.getInstance().isAccountEnableNotificationSending();
        if (notificationType != null && isNotificationSending) {
            UserRecoveryDTO dto;
            if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
                dto = new UserRecoveryDTO(userName);
            } else {
                UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
                userDTO.setTenantId(tenantID);
                dto = new UserRecoveryDTO(userDTO);
            }
            dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_ENABLE);
            dto.setNotificationType(notificationType);
            IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
            if (log.isDebugEnabled()) {
                log.debug("Account enabled notification is sent in " + notificationType);
            }
        }
    } catch (UserStoreException | IdentityException e) {
        String message = "Error occurred while enabling account for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserDTO(org.wso2.carbon.identity.mgt.dto.UserDTO) UserStoreException(org.wso2.carbon.user.api.UserStoreException) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) UserRecoveryDTO(org.wso2.carbon.identity.mgt.dto.UserRecoveryDTO) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Aggregations

IdentityException (org.wso2.carbon.identity.base.IdentityException)12 UserRecoveryDTO (org.wso2.carbon.identity.mgt.dto.UserRecoveryDTO)10 UserDTO (org.wso2.carbon.identity.mgt.dto.UserDTO)9 NotificationDataDTO (org.wso2.carbon.identity.mgt.dto.NotificationDataDTO)8 IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)7 UserStoreException (org.wso2.carbon.user.api.UserStoreException)7 RecoveryProcessor (org.wso2.carbon.identity.mgt.RecoveryProcessor)5 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)5 HashMap (java.util.HashMap)3 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)3 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)3 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Map (java.util.Map)2 IdentityEventListenerConfig (org.wso2.carbon.identity.core.model.IdentityEventListenerConfig)2 IdentityMgtConfig (org.wso2.carbon.identity.mgt.IdentityMgtConfig)2 IdentityMgtEventListener (org.wso2.carbon.identity.mgt.IdentityMgtEventListener)2 Config (org.wso2.carbon.identity.mgt.config.Config)2 ConfigBuilder (org.wso2.carbon.identity.mgt.config.ConfigBuilder)2 UserRecoveryDataDO (org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO)2