Search in sources :

Example 26 with IdentityRecoveryClientException

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

the class Utils method getRealmConfiguration.

/**
 * Get RealmConfiguration by tenantId
 *
 * @param user User
 * @return realmConfiguration RealmConfiguration of the given tenant
 * @throws IdentityRecoveryClientException If fails
 */
private static RealmConfiguration getRealmConfiguration(User user) throws IdentityRecoveryClientException {
    int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain());
    UserStoreManager userStoreManager;
    try {
        userStoreManager = IdentityRecoveryServiceDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
    } catch (UserStoreException userStoreException) {
        throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED, null, userStoreException);
    }
    return ((org.wso2.carbon.user.core.UserStoreManager) userStoreManager).getSecondaryUserStoreManager(user.getUserStoreDomain()).getRealmConfiguration();
}
Also used : UserStoreException(org.wso2.carbon.user.api.UserStoreException) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager)

Example 27 with IdentityRecoveryClientException

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

the class NotificationUsernameRecoveryManager method initiateUsernameRecovery.

/**
 * Initiate username recovery.
 *
 * @param claims                        User claims
 * @param tenantDomain                  Tenant domain
 * @param manageNotificationsInternally Enable internal notification management
 * @return RecoveryChannelInfoDTO
 * @throws IdentityRecoveryException Error initiating username recovery.
 */
private RecoveryInformationDTO initiateUsernameRecovery(Map<String, String> claims, String tenantDomain, boolean manageNotificationsInternally) throws IdentityRecoveryException {
    try {
        HashMap<String, String> properties = new HashMap<>();
        properties.put(IdentityRecoveryConstants.USE_LEGACY_API_PROPERTY_KEY, Boolean.toString(true));
        properties.put(IdentityRecoveryConstants.MANAGE_NOTIFICATIONS_INTERNALLY_PROPERTY_KEY, Boolean.toString(manageNotificationsInternally));
        return usernameRecoveryManagerImpl.initiate(claims, tenantDomain, properties);
    } catch (IdentityRecoveryServerException exception) {
        if (StringUtils.isNotEmpty(exception.getErrorCode())) {
            String errorCode = exception.getErrorCode();
            // Userstore not found error.
            if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_ERROR_GETTING_USERSTORE_MANAGER.getCode().equals(errorCode)) {
                String msg = "Error retrieving the user store manager for the tenant";
                throw new IdentityRecoveryException(msg, exception);
            }
            // Error retrieving claims.
            if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_ERROR_RETRIEVING_USER_CLAIM.getCode().equals(errorCode)) {
                String msg = "Unable to retrieve the claim for the given tenant";
                throw new IdentityRecoveryException(msg, exception);
            }
        }
        throw exception;
    } catch (IdentityRecoveryClientException exception) {
        if (StringUtils.isNotEmpty(exception.getErrorCode())) {
            String errorCode = exception.getErrorCode();
            // Multiple users matched error.
            if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_MULTIPLE_MATCHING_USERS.getCode().equals(errorCode)) {
                if (Boolean.parseBoolean(IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.NOTIFY_USER_EXISTENCE))) {
                    throw exception;
                }
                /* If the notify user is not enabled, return an NULL object so that the user is not notified with
                    an error. */
                return null;
            }
            // Configurations not enabled error.
            if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USERNAME_RECOVERY_NOT_ENABLED.getCode().equals(errorCode)) {
                throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USERNAME_RECOVERY_NOT_ENABLE, null);
            }
        }
        throw exception;
    }
}
Also used : HashMap(java.util.HashMap) IdentityRecoveryServerException(org.wso2.carbon.identity.recovery.IdentityRecoveryServerException) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 28 with IdentityRecoveryClientException

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

the class ValidateCodeApiServiceImpl method validateCodePost.

@Override
public Response validateCodePost(CodeValidationRequestDTO codeValidationRequestDTO) {
    User user = null;
    UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
    try {
        // Get the map of properties in the request.
        HashMap<String, String> propertyMap = Utils.getPropertiesMap(codeValidationRequestDTO.getProperties());
        // Get externally verified channel information.
        VerifiedChannelDTO verifiedChannelDTO = codeValidationRequestDTO.getVerifiedChannel();
        String verifiedChannelType = null;
        String verifiedChannelClaim = null;
        // Handling verified channel details not in the request.
        if (verifiedChannelDTO != null) {
            verifiedChannelClaim = verifiedChannelDTO.getClaim();
            verifiedChannelType = verifiedChannelDTO.getType();
        }
        // Confirm self registration.
        user = userSelfRegistrationManager.getConfirmedSelfRegisteredUser(codeValidationRequestDTO.getCode(), verifiedChannelType, verifiedChannelClaim, propertyMap);
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while confirming self up user ", e);
        }
        Utils.handleBadRequest(e.getMessage(), e.getErrorCode());
    } catch (IdentityRecoveryException e) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return Response.accepted(Utils.getUserDTO(user)).build();
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) VerifiedChannelDTO(org.wso2.carbon.identity.user.endpoint.dto.VerifiedChannelDTO) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 29 with IdentityRecoveryClientException

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

the class MeApiServiceImpl method meValidateCodePost.

@Override
public Response meValidateCodePost(MeCodeValidationRequestDTO meCodeValidationRequestDTO) {
    UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
    try {
        // Get the map of properties in the request.
        HashMap<String, String> propertyMap = Utils.getPropertiesMap(meCodeValidationRequestDTO.getProperties());
        // Confirm verification code.
        userSelfRegistrationManager.confirmVerificationCodeMe(meCodeValidationRequestDTO.getCode(), propertyMap);
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client error while confirming verification code.", e);
        }
        Utils.handleBadRequest(e.getMessage(), e.getErrorCode());
    } catch (IdentityRecoveryException e) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return Response.accepted().build();
}
Also used : UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 30 with IdentityRecoveryClientException

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

the class MeApiServiceImpl method mePost.

@Override
public Response mePost(SelfUserRegistrationRequestDTO selfUserRegistrationRequestDTO) {
    String tenantFromContext = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    if (StringUtils.isNotBlank(tenantFromContext)) {
        selfUserRegistrationRequestDTO.getUser().setTenantDomain(tenantFromContext);
    }
    if (selfUserRegistrationRequestDTO != null && StringUtils.isBlank(selfUserRegistrationRequestDTO.getUser().getRealm())) {
        selfUserRegistrationRequestDTO.getUser().setRealm(IdentityUtil.getPrimaryDomainName());
    }
    UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
    NotificationResponseBean notificationResponseBean = null;
    try {
        notificationResponseBean = userSelfRegistrationManager.registerUser(Utils.getUser(selfUserRegistrationRequestDTO.getUser()), selfUserRegistrationRequestDTO.getUser().getPassword(), Utils.getClaims(selfUserRegistrationRequestDTO.getUser().getClaims()), Utils.getProperties(selfUserRegistrationRequestDTO.getProperties()));
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while registering self up user ", e);
        }
        if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USER_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
            Utils.handleConflict(e.getMessage(), e.getErrorCode());
        } else {
            Utils.handleBadRequest(e.getMessage(), e.getErrorCode());
        }
    } catch (IdentityRecoveryException e) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return buildSuccessfulAPIResponse(notificationResponseBean);
}
Also used : NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

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