Search in sources :

Example 41 with IdentityMgtServiceException

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()]);
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) ChallengeQuestionProcessor(org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor) IdentityException(org.wso2.carbon.identity.base.IdentityException) ChallengeQuestionDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)

Example 42 with IdentityMgtServiceException

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");
    }
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserIdentityMgtBean(org.wso2.carbon.identity.mgt.beans.UserIdentityMgtBean) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 43 with IdentityMgtServiceException

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];
}
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 44 with IdentityMgtServiceException

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);
    }
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserIdentityDataStore(org.wso2.carbon.identity.mgt.store.UserIdentityDataStore) UserIdentityClaimsDO(org.wso2.carbon.identity.mgt.dto.UserIdentityClaimsDO)

Example 45 with IdentityMgtServiceException

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;
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)37 IdentityException (org.wso2.carbon.identity.base.IdentityException)33 UserStoreException (org.wso2.carbon.user.api.UserStoreException)25 UserDTO (org.wso2.carbon.identity.mgt.dto.UserDTO)18 RecoveryProcessor (org.wso2.carbon.identity.mgt.RecoveryProcessor)15 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)15 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)13 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)11 UserChallengesDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesDTO)9 ChallengeQuestionProcessor (org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor)8 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)8 UserRecoveryDTO (org.wso2.carbon.identity.mgt.dto.UserRecoveryDTO)7 UserIdentityClaimDTO (org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO)5 ChallengeQuestionDTO (org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)4 NotificationDataDTO (org.wso2.carbon.identity.mgt.dto.NotificationDataDTO)4 RealmService (org.wso2.carbon.user.core.service.RealmService)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 IdentityEventListenerConfig (org.wso2.carbon.identity.core.model.IdentityEventListenerConfig)2 IdentityMgtConfig (org.wso2.carbon.identity.mgt.IdentityMgtConfig)2