Search in sources :

Example 6 with UserDTO

use of org.wso2.carbon.identity.user.rename.core.dto.UserDTO in project carbon-identity-framework by wso2.

the class UserIdentityManagementAdminService method unlockUserAccount.

/**
 * Admin unlocks the user account.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void unlockUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.unlockUserAccount(userNameWithoutDomain, userStoreManager);
        int tenantID = userStoreManager.getTenantId();
        String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
        boolean isNotificationSending = IdentityMgtConfig.getInstance().isNotificationSending();
        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_UNLOCK);
            dto.setNotificationType(notificationType);
            IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
        }
        log.info("Account unlocked for: " + userName);
    } catch (UserStoreException | IdentityException e) {
        String message = "Error occurred while unlocking 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)

Example 7 with UserDTO

use of org.wso2.carbon.identity.user.rename.core.dto.UserDTO in project carbon-identity-framework by wso2.

the class UserIdentityManagementAdminService method disableUserAccount.

/**
 * Admin disables the user account. Only the admin can enable the account using
 * the {@literal enableUserAccount} method.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void disableUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.disableUserAccount(userNameWithoutDomain, userStoreManager);
        audit.info(String.format(AUDIT_MESSAGE, getUser(), "Disable user account", userName, "Notification type :" + notificationType, SUCCESS));
        int tenantID = userStoreManager.getTenantId();
        String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
        boolean isNotificationSending = IdentityMgtConfig.getInstance().isAccountDisableNotificationSending();
        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_DISABLE);
            dto.setNotificationType(notificationType);
            IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
            if (log.isDebugEnabled()) {
                log.debug("Account enabled notification is sent in " + notificationType);
            }
        }
    } catch (UserStoreException | IdentityException e) {
        log.error("Error occurred while trying to disable the account " + userName, e);
        throw new IdentityMgtServiceException("Error occurred while trying to disable the account " + userName, 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)

Example 8 with UserDTO

use of org.wso2.carbon.identity.user.rename.core.dto.UserDTO in project carbon-identity-framework by wso2.

the class UserIdentityManagementService method updateCredential.

/**
 * proceed updating credentials of user
 *
 * @param captchaInfoBean bean class that contains captcha information
 * @return True, if successful in verifying and hence updating the credentials.
 */
public VerificationBean updateCredential(String userName, String confirmation, String password, CaptchaInfoBean captchaInfoBean) {
    RecoveryProcessor recoveryProcessor = IdentityMgtServiceComponent.getRecoveryProcessor();
    if (IdentityMgtConfig.getInstance().isCaptchaVerificationInternallyManaged()) {
        try {
            CaptchaUtil.processCaptchaInfoBean(captchaInfoBean);
        } catch (Exception e) {
            log.error("Error while processing captcha bean.", e);
            return new VerificationBean(VerificationBean.ERROR_CODE_INVALID_CAPTCHA);
        }
    }
    try {
        UserDTO userDTO = Utils.processUserId(userName);
        if (recoveryProcessor.verifyConfirmationKey(confirmation).isVerified()) {
            Utils.updatePassword(userDTO.getUserId(), userDTO.getTenantId(), password);
            log.info("Credential is updated for user : " + userDTO.getUserId() + " and tenant domain : " + userDTO.getTenantDomain());
            return new VerificationBean(true);
        } else {
            log.warn("Invalid user tried to update credential with user Id : " + userDTO.getUserId() + " and tenant domain : " + userDTO.getTenantDomain());
        }
    } catch (Exception e) {
        log.error("Error while updating credential for user : " + userName, e);
    }
    return new VerificationBean(VerificationBean.ERROR_CODE_UNEXPECTED);
}
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) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 9 with UserDTO

use of org.wso2.carbon.identity.user.rename.core.dto.UserDTO in project carbon-identity-framework by wso2.

the class IdentityMgtEventListener method sendEmail.

private void sendEmail(String userName, int tenantId, String notification) {
    UserRecoveryDTO dto;
    String tenantDomain = IdentityTenantUtil.getTenantDomain(tenantId);
    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(notification);
    dto.setNotificationType(EMAIL_NOTIFICATION_TYPE);
    try {
        IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
    } catch (IdentityException e) {
        // proceed with the rest of the flow even if the email is not sent
        log.error("Email notification sending failed for user:" + userName + " for " + notification);
    }
}
Also used : UserDTO(org.wso2.carbon.identity.mgt.dto.UserDTO) UserRecoveryDTO(org.wso2.carbon.identity.mgt.dto.UserRecoveryDTO) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 10 with UserDTO

use of org.wso2.carbon.identity.user.rename.core.dto.UserDTO in project carbon-identity-framework by wso2.

the class RecoveryProcessor method createConfirmationCode.

public void createConfirmationCode(UserDTO userDTO, String code) throws IdentityException {
    String key = UUID.randomUUID().toString();
    UserRecoveryDataDO dataDO = new UserRecoveryDataDO(userDTO.getUserId(), userDTO.getTenantId(), key, code);
    dataStore.invalidate(userDTO.getUserId(), userDTO.getTenantId());
    dataStore.store(dataDO);
}
Also used : UserRecoveryDataDO(org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO)

Aggregations

IdentityException (org.wso2.carbon.identity.base.IdentityException)23 UserDTO (org.wso2.carbon.identity.mgt.dto.UserDTO)22 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)19 RecoveryProcessor (org.wso2.carbon.identity.mgt.RecoveryProcessor)17 UserStoreException (org.wso2.carbon.user.api.UserStoreException)17 IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)14 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)12 Test (org.testng.annotations.Test)10 UserDTO (org.wso2.carbon.identity.user.rename.core.dto.UserDTO)10 UserRecoveryDTO (org.wso2.carbon.identity.mgt.dto.UserRecoveryDTO)9 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)9 RealmService (org.wso2.carbon.user.core.service.RealmService)9 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)8 UserDTO (org.wso2.carbon.identity.test.integration.service.stub.UserDTO)7 UserDTO (org.wso2.carbon.identity.user.endpoint.dto.UserDTO)6 NotificationDataDTO (org.wso2.carbon.identity.mgt.dto.NotificationDataDTO)5 UserChallengesDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesDTO)4 User (org.wso2.carbon.apimgt.core.models.User)3 User (org.wso2.carbon.identity.application.common.model.User)3 ChallengeQuestionProcessor (org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor)3