Search in sources :

Example 51 with UserDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO 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)

Example 52 with UserDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project carbon-identity-framework by wso2.

the class UserIdentityManagementService method getChallengeQuestionsForUser.

/**
 * get challenges of user
 *
 * @return array of challenges  if null, return empty array
 * @throws IdentityException if fails
 */
public UserChallengesDTO[] getChallengeQuestionsForUser(String userName, String confirmation) throws IdentityMgtServiceException {
    UserDTO userDTO = null;
    try {
        userDTO = Utils.processUserId(userName);
    } catch (IdentityException e) {
        throw new IdentityMgtServiceException("Invalid user name.", e);
    }
    RecoveryProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor();
    VerificationBean bean = processor.verifyConfirmationKey(confirmation);
    if (bean.isVerified()) {
        try {
            processor.createConfirmationCode(userDTO, confirmation);
        } catch (IdentityException e) {
            log.error("Error in creating confirmation code.", e);
        }
        return processor.getQuestionProcessor().getChallengeQuestionsOfUser(userDTO.getUserId(), userDTO.getTenantId(), false);
    }
    return new UserChallengesDTO[0];
}
Also used : VerificationBean(org.wso2.carbon.identity.mgt.beans.VerificationBean) IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserChallengesDTO(org.wso2.carbon.identity.mgt.dto.UserChallengesDTO) UserDTO(org.wso2.carbon.identity.mgt.dto.UserDTO) RecoveryProcessor(org.wso2.carbon.identity.mgt.RecoveryProcessor) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 53 with UserDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project carbon-identity-framework by wso2.

the class Utils method processUserId.

public static UserDTO processUserId(String userId) throws IdentityException {
    if (userId == null || userId.trim().length() < 1) {
        throw IdentityException.error("Can not proceed with out a user id");
    }
    UserDTO userDTO = new UserDTO(userId);
    if (!IdentityMgtConfig.getInstance().isSaasEnabled()) {
        validateTenant(userDTO);
    }
    userDTO.setTenantId(getTenantId(userDTO.getTenantDomain()));
    return userDTO;
}
Also used : UserDTO(org.wso2.carbon.identity.mgt.dto.UserDTO)

Example 54 with UserDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project identity-governance by wso2-extensions.

the class UsernameUpdateServiceImplTest method testExceptionWhileRetrievingTenantID.

@Test(expectedExceptions = UsernameUpdateException.class)
public void testExceptionWhileRetrievingTenantID() throws Exception {
    UserDTO userDTO = buildUserDTO("testuser1", "testuser11", UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    RealmService realmService = mock(RealmService.class);
    TenantManager tenantManager = mock(TenantManager.class);
    when(realmService.getTenantManager()).thenReturn(tenantManager);
    when(tenantManager.getTenantId(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenThrow(new UserStoreException("Error while retrieving tenant id"));
    UsernameUpdateServiceImpl usernameUpdateServiceImpl = new UsernameUpdateServiceImpl();
    usernameUpdateServiceImpl.setRealmService(realmService);
    usernameUpdateServiceImpl.updateUsername(userDTO);
}
Also used : RealmService(org.wso2.carbon.user.core.service.RealmService) UserDTO(org.wso2.carbon.identity.user.rename.core.dto.UserDTO) UserStoreException(org.wso2.carbon.user.api.UserStoreException) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Test(org.testng.annotations.Test)

Example 55 with UserDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project identity-governance by wso2-extensions.

the class UsernameUpdateServiceImplTest method testExceptionAtInvalidParameters.

@Test(dataProvider = "getInvalidUsers", expectedExceptions = UsernameUpdateException.class)
public void testExceptionAtInvalidParameters(String existingUsername, String newUsername, String userStoreDomain, String tenantDomain) throws Exception {
    UserDTO userDTO = buildUserDTO(existingUsername, newUsername, userStoreDomain, tenantDomain);
    UsernameUpdateServiceImpl usernameUpdateServiceImpl = new UsernameUpdateServiceImpl();
    usernameUpdateServiceImpl.updateUsername(userDTO);
}
Also used : UserDTO(org.wso2.carbon.identity.user.rename.core.dto.UserDTO) Test(org.testng.annotations.Test)

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