use of org.wso2.carbon.identity.user.endpoint.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);
}
}
use of org.wso2.carbon.identity.user.endpoint.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];
}
use of org.wso2.carbon.identity.user.endpoint.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;
}
use of org.wso2.carbon.identity.user.endpoint.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);
}
use of org.wso2.carbon.identity.user.endpoint.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);
}
Aggregations