Search in sources :

Example 1 with UserSelfRegistrationManager

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

the class IntrospectCodeApiServiceImpl method introspectCodePost.

@Override
public Response introspectCodePost(CodeValidationRequestDTO codeValidationRequestDTO) {
    UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
    CodeValidateInfoResponseDTO codeDetails = null;
    UserRecoveryData recoveryData = null;
    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 code.
        recoveryData = userSelfRegistrationManager.introspectUserSelfRegistration(true, codeValidationRequestDTO.getCode(), verifiedChannelType, verifiedChannelClaim, propertyMap);
        if (recoveryData != null && recoveryData.getUser() != null && recoveryData.getUser().getUserName() != null) {
            codeDetails = getCodeIntrospectResponse(recoveryData);
        } else {
            Utils.handleNotFound(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_CODE.getMessage(), IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_CODE.getCode());
        }
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while confirming sent in 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(codeDetails).build();
}
Also used : UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) CodeValidateInfoResponseDTO(org.wso2.carbon.identity.user.endpoint.dto.CodeValidateInfoResponseDTO) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 2 with UserSelfRegistrationManager

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

the class LiteApiServiceImpl method litePost.

@Override
public Response litePost(LiteUserRegistrationRequestDTO liteUserRegistrationRequestDTO) {
    // reject if username is not present.
    if (liteUserRegistrationRequestDTO == null || (StringUtils.isBlank(liteUserRegistrationRequestDTO.getEmail()) && StringUtils.isBlank(liteUserRegistrationRequestDTO.getMobile()))) {
        Utils.handleBadRequest(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_BAD_LITE_REGISTER_REQUEST.getMessage(), IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_BAD_LITE_REGISTER_REQUEST.getCode());
    }
    String tenantFromContext = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    List<PropertyDTO> properties = new ArrayList<>();
    User user = new User();
    user.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    user.setUserStoreDomain(IdentityUtil.getPrimaryDomainName());
    user.setUserName(liteUserRegistrationRequestDTO.getEmail());
    PropertyDTO propertyDTO = new PropertyDTO();
    propertyDTO.setKey(IdentityRecoveryConstants.IS_LITE_SIGN_UP);
    propertyDTO.setValue("true");
    properties.add(propertyDTO);
    if (StringUtils.isNotBlank(liteUserRegistrationRequestDTO.getRealm())) {
        user.setUserStoreDomain(liteUserRegistrationRequestDTO.getRealm());
    }
    if (StringUtils.isNotBlank(tenantFromContext)) {
        user.setTenantDomain(tenantFromContext);
    }
    UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
    NotificationResponseBean notificationResponseBean = null;
    properties.addAll(liteUserRegistrationRequestDTO.getProperties());
    try {
        notificationResponseBean = userSelfRegistrationManager.registerLiteUser(user, Utils.getClaims(liteUserRegistrationRequestDTO.getClaims()), Utils.getProperties(properties));
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while self registering lite 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 : User(org.wso2.carbon.identity.application.common.model.User) NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) ArrayList(java.util.ArrayList) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 3 with UserSelfRegistrationManager

use of org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager 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 4 with UserSelfRegistrationManager

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

the class ValidateUsernameApiServiceImpl method validateUsernamePost.

@Override
public Response validateUsernamePost(UsernameValidationRequestDTO user) {
    if (StringUtils.isEmpty(user.getUsername())) {
        ErrorDTO errorDTO = new ErrorDTO();
        errorDTO.setRef(Utils.getCorrelation());
        errorDTO.setMessage("Username cannot be empty.");
        return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
    }
    try {
        String tenantDomain = MultitenantUtils.getTenantDomain(user.getUsername());
        List<PropertyDTO> propertyDTOList = user.getProperties();
        boolean skipSelfSignUpEnabledCheck = false;
        if (CollectionUtils.isNotEmpty(propertyDTOList)) {
            for (PropertyDTO propertyDTO : propertyDTOList) {
                if (SKIP_SIGN_UP_ENABLE_CHECK_KEY.equalsIgnoreCase(propertyDTO.getKey())) {
                    skipSelfSignUpEnabledCheck = Boolean.parseBoolean(propertyDTO.getValue());
                } else if (IdentityManagementEndpointConstants.TENANT_DOMAIN.equals(propertyDTO.getKey())) {
                    tenantDomain = propertyDTO.getValue();
                }
            }
        }
        UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Validating username for user %s", user.getUsername()));
        }
        UsernameValidateInfoResponseDTO responseDTO = new UsernameValidateInfoResponseDTO();
        ErrorDTO errorDTO = new ErrorDTO();
        if (!userSelfRegistrationManager.isValidTenantDomain(tenantDomain)) {
            logDebug(String.format("%s is an invalid tenant domain. Hence returning code %s: ", tenantDomain, SelfRegistrationStatusCodes.ERROR_CODE_INVALID_TENANT));
            errorDTO.setCode(SelfRegistrationStatusCodes.ERROR_CODE_INVALID_TENANT);
            errorDTO.setRef(Utils.getCorrelation());
            return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
        } else if (!skipSelfSignUpEnabledCheck && !userSelfRegistrationManager.isSelfRegistrationEnabled(tenantDomain)) {
            logDebug(String.format("Self registration is not enabled for tenant domain: %s. Hence returning code:" + " %s", tenantDomain, SelfRegistrationStatusCodes.ERROR_CODE_SELF_REGISTRATION_DISABLED));
            errorDTO.setCode(SelfRegistrationStatusCodes.ERROR_CODE_SELF_REGISTRATION_DISABLED);
            errorDTO.setRef(Utils.getCorrelation());
            return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
        } else if (userSelfRegistrationManager.isUsernameAlreadyTaken(user.getUsername(), tenantDomain)) {
            logDebug(String.format("username : %s is an already taken. Hence returning code %s: ", user.getUsername(), SelfRegistrationStatusCodes.ERROR_CODE_USER_ALREADY_EXISTS));
            errorDTO.setCode(SelfRegistrationStatusCodes.ERROR_CODE_USER_ALREADY_EXISTS);
            errorDTO.setRef(Utils.getCorrelation());
            return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
        } else if (!userSelfRegistrationManager.isMatchUserNameRegex(tenantDomain, user.getUsername())) {
            logDebug(String.format("%s is an invalid user name. Hence returning code %s: ", user.getUsername(), SelfRegistrationStatusCodes.CODE_USER_NAME_INVALID));
            errorDTO.setCode(SelfRegistrationStatusCodes.CODE_USER_NAME_INVALID);
            errorDTO.setMessage(getRegexViolationErrorMsg(user, tenantDomain));
            errorDTO.setRef(Utils.getCorrelation());
            return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
        } else {
            logDebug(String.format("username : %s is available for self registration. Hence returning code %s: ", user.getUsername(), SelfRegistrationStatusCodes.CODE_USER_NAME_AVAILABLE));
            responseDTO.setStatusCode(Integer.parseInt(SelfRegistrationStatusCodes.CODE_USER_NAME_AVAILABLE));
            return Response.ok().entity(responseDTO).build();
        }
    } catch (IdentityRecoveryException | CarbonException | UserStoreException e) {
        ErrorDTO errorDTO = new ErrorDTO();
        errorDTO.setRef(Utils.getCorrelation());
        errorDTO.setMessage("Error while checking user existence");
        if (LOG.isDebugEnabled()) {
            LOG.debug("Error while checking username validity for user " + user.getUsername(), e);
        }
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
    }
}
Also used : UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) ErrorDTO(org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO) CarbonException(org.wso2.carbon.CarbonException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) PropertyDTO(org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO) UsernameValidateInfoResponseDTO(org.wso2.carbon.identity.user.endpoint.dto.UsernameValidateInfoResponseDTO)

Example 5 with UserSelfRegistrationManager

use of org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager 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)

Aggregations

IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)6 UserSelfRegistrationManager (org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager)6 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)5 User (org.wso2.carbon.identity.application.common.model.User)2 NotificationResponseBean (org.wso2.carbon.identity.recovery.bean.NotificationResponseBean)2 ArrayList (java.util.ArrayList)1 CarbonException (org.wso2.carbon.CarbonException)1 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)1 CodeValidateInfoResponseDTO (org.wso2.carbon.identity.user.endpoint.dto.CodeValidateInfoResponseDTO)1 ErrorDTO (org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO)1 PropertyDTO (org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO)1 UsernameValidateInfoResponseDTO (org.wso2.carbon.identity.user.endpoint.dto.UsernameValidateInfoResponseDTO)1 VerifiedChannelDTO (org.wso2.carbon.identity.user.endpoint.dto.VerifiedChannelDTO)1 UserStoreException (org.wso2.carbon.user.core.UserStoreException)1