Search in sources :

Example 21 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class ChallengeQuestionManagementAdminService method getChallengeQuestionsForUser.

/**
 * Get all challenge questions applicable for a user based on his locale. If we can't find any question in his
 * locale we return challenge questions from the default en_US locale.
 *
 * @param user
 * @return
 * @throws IdentityRecoveryServerException
 */
public ChallengeQuestion[] getChallengeQuestionsForUser(User user) throws IdentityRecoveryException {
    if (user == null) {
        log.error("User object provided is null.");
        throw new IdentityRecoveryClientException("User object provided is null.");
    }
    String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    List<ChallengeQuestion> challengeQuestionList;
    try {
        challengeQuestionList = questionManager.getAllChallengeQuestionsForUser(tenantDomain, user);
        return challengeQuestionList.toArray(new ChallengeQuestion[challengeQuestionList.size()]);
    } catch (IdentityRecoveryException e) {
        String errorMgs = "Error loading challenge questions for user : %s@%s.";
        log.error(String.format(errorMgs, user.getUserName(), tenantDomain), e);
        throw new IdentityRecoveryException(String.format(errorMgs, user.getUserName(), tenantDomain), e);
    }
}
Also used : IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion)

Example 22 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class ChallengeQuestionManagementAdminService method getUserChallengeAnswers.

/**
 * Get Challenge question answers along with their encrypted answers of a user
 *
 * @param user
 * @return
 * @throws IdentityRecoveryException
 */
public UserChallengeAnswer[] getUserChallengeAnswers(User user) throws IdentityRecoveryException {
    if (user == null) {
        log.error("User object provided is null.");
        throw new IdentityRecoveryClientException("User object provided is null.");
    }
    String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(user.getUserName());
    String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    String loggedInName = CarbonContext.getThreadLocalCarbonContext().getUsername();
    // TODO externalize authorization
    if (tenantAwareUserName != null && !isValidUser(user.getUserStoreDomain(), tenantAwareUserName, loggedInName)) {
        boolean isAuthorized = isUserAuthorized(loggedInName, tenantDomain);
        if (!isAuthorized) {
            throw new IdentityRecoveryClientException("Unauthorized access!! Possible violation of confidentiality. " + "User " + loggedInName + " trying to get challenge questions for user " + tenantAwareUserName);
        }
    } else if (tenantAwareUserName == null) {
        tenantAwareUserName = loggedInName;
    }
    try {
        return questionManager.getChallengeAnswersOfUser(user);
    } catch (IdentityRecoveryException e) {
        String msg = "Error retrieving user challenge answers for " + tenantAwareUserName;
        log.error(msg, e);
        throw new IdentityRecoveryException(msg, e);
    }
}
Also used : IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 23 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class Utils method getUserStoreManager.

private static org.wso2.carbon.user.core.UserStoreManager getUserStoreManager(User user) throws IdentityRecoveryClientException, IdentityRecoveryServerException {
    org.wso2.carbon.user.core.UserStoreManager userStoreManager;
    // Validate method inputs.
    if (user == null) {
        throw handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_USER, "Invalid User Data provided.");
    }
    int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain());
    try {
        RealmService realmService = IdentityRecoveryServiceDataHolder.getInstance().getRealmService();
        if (realmService == null || realmService.getTenantUserRealm(tenantId) == null) {
            throw handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_LOAD_REALM_SERVICE, user.getTenantDomain());
        }
        userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) realmService.getTenantUserRealm(tenantId).getUserStoreManager();
    } catch (UserStoreException e) {
        throw handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_LOAD_REALM_SERVICE, user.getTenantDomain(), e);
    }
    if (userStoreManager == null) {
        throw handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_LOAD_USER_STORE_MANAGER, null);
    }
    return userStoreManager;
}
Also used : RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 24 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class Utils method checkPasswordPatternViolation.

/**
 * Check if the exception contains a password pattern violation message and act accordingly
 *
 * @param exception An UserStoreException
 * @throws IdentityRecoveryClientException If exception's message contains a password pattern violation message
 */
public static void checkPasswordPatternViolation(UserStoreException exception, User user) throws IdentityRecoveryClientException {
    if (StringUtils.isBlank(exception.getMessage())) {
        return;
    }
    RealmConfiguration realmConfig = getRealmConfiguration(user);
    String passwordErrorMessage = realmConfig.getUserStoreProperty(PROPERTY_PASSWORD_ERROR_MSG);
    String exceptionMessage = exception.getMessage();
    if (((StringUtils.indexOfAny(exceptionMessage, pwdPatternViolations) >= 0) && StringUtils.containsIgnoreCase(exceptionMessage, passwordErrorMessage)) || exceptionMessage.contains(UserCoreErrorConstants.ErrorMessages.ERROR_CODE_INVALID_PASSWORD.getCode())) {
        if (StringUtils.isNotEmpty(passwordErrorMessage)) {
            throw IdentityException.error(IdentityRecoveryClientException.class, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_POLICY_VIOLATION.getCode(), passwordErrorMessage, exception);
        } else {
            String errorMessage = String.format(UserCoreErrorConstants.ErrorMessages.ERROR_CODE_INVALID_PASSWORD.getMessage(), realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_JAVA_REG_EX));
            throw IdentityException.error(IdentityRecoveryClientException.class, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_POLICY_VIOLATION.getCode(), errorMessage, exception);
        }
    }
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration)

Example 25 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class UserSelfRegistrationManager method isPreferredChannelVerified.

/**
 * Checks whether the notification channel is already verified for the user.
 *
 * @param username            Username
 * @param notificationChannel Notification channel
 * @param claimsMap           Properties related to the event
 * @return True if the channel is already verified
 * @throws IdentityRecoveryClientException Error while getting the notification channel
 */
private boolean isPreferredChannelVerified(String username, String notificationChannel, Map<String, String> claimsMap) throws IdentityRecoveryClientException {
    boolean isEnableAccountLockForVerifiedPreferredChannelEnabled = Boolean.parseBoolean(IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.ENABLE_ACCOUNT_LOCK_FOR_VERIFIED_PREFERRED_CHANNEL));
    if (!isEnableAccountLockForVerifiedPreferredChannelEnabled) {
        NotificationChannels channel = getNotificationChannel(username, notificationChannel);
        // Get the matching claim uri for the channel.
        String verifiedClaimUri = channel.getVerifiedClaimUrl();
        // Get the verified status for given channel.
        String verifiedStatus = claimsMap.get(verifiedClaimUri);
        return StringUtils.isNotEmpty(verifiedStatus) && Boolean.parseBoolean(verifiedStatus);
    }
    return false;
}
Also used : NotificationChannels(org.wso2.carbon.identity.governance.service.notification.NotificationChannels)

Aggregations

IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)29 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)17 User (org.wso2.carbon.identity.application.common.model.User)11 Test (org.testng.annotations.Test)6 UserSelfRegistrationManager (org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager)5 UserStoreException (org.wso2.carbon.user.api.UserStoreException)5 NotificationPasswordRecoveryManager (org.wso2.carbon.identity.recovery.password.NotificationPasswordRecoveryManager)4 HashMap (java.util.HashMap)3 NotificationChannels (org.wso2.carbon.identity.governance.service.notification.NotificationChannels)3 IdentityRecoveryServerException (org.wso2.carbon.identity.recovery.IdentityRecoveryServerException)3 ChallengeQuestionResponse (org.wso2.carbon.identity.recovery.bean.ChallengeQuestionResponse)3 NotificationResponseBean (org.wso2.carbon.identity.recovery.bean.NotificationResponseBean)3 ChallengeQuestion (org.wso2.carbon.identity.recovery.model.ChallengeQuestion)3 UserChallengeAnswer (org.wso2.carbon.identity.recovery.model.UserChallengeAnswer)3 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)3 SecurityQuestionPasswordRecoveryManager (org.wso2.carbon.identity.recovery.password.SecurityQuestionPasswordRecoveryManager)3 IdentityEventClientException (org.wso2.carbon.identity.event.IdentityEventClientException)2 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)2 IdentityEventServerException (org.wso2.carbon.identity.event.IdentityEventServerException)2 RetryErrorDTO (org.wso2.carbon.identity.recovery.endpoint.dto.RetryErrorDTO)2