use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementAdminService method getAllChallengeQuestions.
/**
* get all challenge questions
*
* @return array of questions
* @throws IdentityMgtServiceException if fails
*/
public ChallengeQuestionDTO[] getAllChallengeQuestions() throws IdentityMgtServiceException {
ChallengeQuestionProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor();
List<ChallengeQuestionDTO> questionDTOs = null;
try {
questionDTOs = processor.getAllChallengeQuestions();
} catch (IdentityException e) {
String errorMessage = "Error while loading user challenge questions";
log.error(errorMessage, e);
throw new IdentityMgtServiceException(errorMessage);
}
return questionDTOs.toArray(new ChallengeQuestionDTO[questionDTOs.size()]);
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementService method recoverUserIdentityWithEmail.
/**
* Recovers the account with user email
* TODO : what if the user name is invalid, send the error code over mail. TODO : store the temp in metadata, DONOT update.
*
* @param userName
* @throws IdentityMgtServiceException
*/
public void recoverUserIdentityWithEmail(String userName) throws IdentityMgtServiceException {
int tenantId;
try {
tenantId = Utils.getTenantId(MultitenantUtils.getTenantDomain(userName));
UserStoreManager userStoreManager = IdentityMgtServiceComponent.getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
// reset the password with a random value
char[] tempPassword = UserIdentityManagementUtil.generateTemporaryPassword();
userStoreManager.updateCredentialByAdmin(userName, new String(tempPassword));
// sending email
UserIdentityMgtBean bean = new UserIdentityMgtBean();
String email = userStoreManager.getUserClaimValue(userName, IdentityMgtConfig.getInstance().getAccountRecoveryClaim(), null);
log.debug("Sending email to " + email);
bean.setUserId(userName).setUserTemporaryPassword(new String(tempPassword)).setEmail(email);
UserIdentityManagementUtil.notifyViaEmail(bean);
} catch (UserStoreException e) {
log.error("Error while recovering user identity", e);
throw new IdentityMgtServiceException("Error while recovering user identity");
} catch (IdentityException e) {
log.error("Error while recovering user identity", e);
throw new IdentityMgtServiceException("Error while recovering user identity");
}
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException 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.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class UserIdentityManagementUtil method getUserSecurityQuestions.
/**
* Returns security questions of the logged in user
*
* @param userStoreManager
* @return
* @throws IdentityMgtServiceException
*/
public static UserIdentityClaimDTO[] getUserSecurityQuestions(String userName, UserStoreManager userStoreManager) throws IdentityMgtServiceException {
UserIdentityDataStore store = IdentityMgtConfig.getInstance().getIdentityDataStore();
UserIdentityClaimsDO userIdentityDO;
userIdentityDO = store.load(userName, userStoreManager);
if (userIdentityDO != null) {
return userIdentityDO.getUserSequeiryQuestions();
} else {
throw new IdentityMgtServiceException("No user account found for user " + userName);
}
}
use of org.wso2.carbon.identity.mgt.IdentityMgtServiceException in project carbon-identity-framework by wso2.
the class NotificationBuilder method createNotification.
public static Notification createNotification(String notificationType, String template, NotificationData data) throws IdentityMgtServiceException {
String subject = null;
String body = null;
String footer = null;
Notification notificatoin = null;
if ("EMAIL".equals(notificationType)) {
String[] contents = template.split("\\|");
if (contents.length > 3) {
throw new IdentityMgtServiceException("Contents must be 3 or less");
}
subject = contents[0];
body = contents[1];
footer = contents[2];
// Replace all the tags in the NotificationData.
Map<String, String> tagsData = data.getTagsData();
try {
subject = replaceTags(tagsData, subject);
body = replaceTags(tagsData, body);
footer = replaceTags(tagsData, footer);
} catch (UnsupportedEncodingException e) {
throw new IdentityMgtServiceException("Unsupported encoding while creating notification", e);
}
notificatoin = new EmailNotification();
notificatoin.setSubject(subject);
notificatoin.setBody(body);
notificatoin.setFooter(footer);
notificatoin.setSendFrom(data.getSendFrom());
notificatoin.setSendTo(data.getSendTo());
}
return notificatoin;
}
Aggregations