use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementAdminService method getAllPromotedUserChallenge.
/**
* get all promoted user challenges
*
* @return array of user challenges
* @throws IdentityMgtServiceException if fails
*/
public UserChallengesSetDTO[] getAllPromotedUserChallenge() throws IdentityMgtServiceException {
ChallengeQuestionProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor();
List<UserChallengesSetDTO> challengeQuestionSetDTOs = new ArrayList<UserChallengesSetDTO>();
List<ChallengeQuestionDTO> questionDTOs = null;
try {
questionDTOs = processor.getAllChallengeQuestions();
} catch (IdentityException e) {
log.error("Error while loading user challenges", e);
throw new IdentityMgtServiceException("Error while loading user challenges");
}
Map<String, List<UserChallengesDTO>> listMap = new HashMap<String, List<UserChallengesDTO>>();
for (ChallengeQuestionDTO dto : questionDTOs) {
List<UserChallengesDTO> dtoList = listMap.get(dto.getQuestionSetId());
if (dtoList == null) {
dtoList = new ArrayList<UserChallengesDTO>();
}
UserChallengesDTO userChallengesDTO = new UserChallengesDTO();
userChallengesDTO.setId(dto.getQuestionSetId());
userChallengesDTO.setQuestion(dto.getQuestion());
userChallengesDTO.setOrder(dto.getOrder());
dtoList.add(userChallengesDTO);
listMap.put(dto.getQuestionSetId(), dtoList);
}
for (Map.Entry<String, List<UserChallengesDTO>> listEntry : listMap.entrySet()) {
UserChallengesSetDTO dto = new UserChallengesSetDTO();
dto.setId(listEntry.getKey());
List<UserChallengesDTO> dtoList = listEntry.getValue();
dto.setChallengesDTOs(dtoList.toArray(new UserChallengesDTO[dtoList.size()]));
challengeQuestionSetDTOs.add(dto);
}
return challengeQuestionSetDTOs.toArray(new UserChallengesSetDTO[challengeQuestionSetDTOs.size()]);
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException 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);
}
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementAdminService method resetUserPassword.
/**
* Admin resets the password of the user.
*
* @param userName
* @param newPassword
* @throws IdentityMgtServiceException
*/
public void resetUserPassword(String userName, String newPassword) throws IdentityMgtServiceException {
try {
UserStoreManager userStoreManager = getUserStore(userName);
String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
userStoreManager.updateCredentialByAdmin(userNameWithoutDomain, newPassword);
log.info("User password reset for: " + userName);
} catch (UserStoreException e) {
String message = "Error occurred while resetting password for: " + userName;
log.error(message, e);
throw new IdentityMgtServiceException(message, e);
}
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementService method verifyChallengeQuestion.
/**
* verify challenge questions
*
* @return verification results as been
* @throws IdentityException if any error occurs
*/
public VerificationBean verifyChallengeQuestion(String userName, String confirmation, UserChallengesDTO[] userChallengesDTOs) throws IdentityMgtServiceException {
VerificationBean bean = new VerificationBean();
bean.setVerified(false);
RecoveryProcessor recoveryProcessor = IdentityMgtServiceComponent.getRecoveryProcessor();
if (userChallengesDTOs == null || userChallengesDTOs.length < 1) {
log.error("no challenges provided by user for verifications.");
bean.setError("no challenges provided by user for verifications.");
return bean;
}
UserDTO userDTO = null;
try {
userDTO = Utils.processUserId(userName);
} catch (IdentityException e) {
throw new IdentityMgtServiceException("Invalid user name.", e);
}
if (recoveryProcessor.verifyConfirmationKey(confirmation).isVerified()) {
log.warn("Invalid user is trying to verify user challenges.");
bean.setError("Invalid user is trying to verify user challenges.");
return bean;
}
ChallengeQuestionProcessor processor = recoveryProcessor.getQuestionProcessor();
boolean verification = processor.verifyChallengeQuestion(userDTO.getUserId(), userDTO.getTenantId(), userChallengesDTOs);
if (verification) {
String code = UUID.randomUUID().toString();
try {
recoveryProcessor.createConfirmationCode(userDTO, code);
} catch (IdentityException e) {
log.error("Error while creating confirmation code.", e);
}
bean = new VerificationBean(userName, code);
}
return bean;
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementService method processPasswordRecovery.
/**
* process password recovery for given user
*
* @return recovery process success or not
* @throws IdentityException if fails
*/
public boolean processPasswordRecovery(String userId, String confirmationCode, String notificationType) throws IdentityMgtServiceException {
UserDTO userDTO = null;
try {
userDTO = Utils.processUserId(userId);
} catch (IdentityException e) {
throw new IdentityMgtServiceException("invalid user name", e);
}
RecoveryProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor();
VerificationBean bean = processor.verifyConfirmationKey(confirmationCode);
if (!bean.isVerified()) {
log.warn("Invalid user is trying to recover the password : " + userId);
return false;
}
UserRecoveryDTO dto = new UserRecoveryDTO(userDTO);
dto.setNotification(IdentityMgtConstants.Notification.PASSWORD_RESET_RECOVERY);
dto.setNotificationType(notificationType);
NotificationDataDTO dataDTO = null;
try {
dataDTO = processor.recoverWithNotification(dto);
} catch (IdentityException e) {
throw new IdentityMgtServiceException("Error while password recovery.", e);
}
return dataDTO.isNotificationSent();
}
Aggregations