Search in sources :

Example 1 with FailureReason

use of org.wso2.carbon.user.core.common.FailureReason in project identity-otp-integration-endpoints by wso2-extensions.

the class EmailotpApiServiceImpl method emailotpValidatePost.

/**
 * This method is implemented from org.wso2.carbon.identity.api.otp.service.emailotp.EmailotpApi
 * to validate OTP.
 *
 * @param otpValidationRequest Otp validation request object.
 * @return Response
 */
@Override
public Response emailotpValidatePost(OTPValidationRequest otpValidationRequest) {
    String transactionId = StringUtils.trim(otpValidationRequest.getTransactionId());
    String userId = StringUtils.trim(otpValidationRequest.getUserId());
    String emailOtp = StringUtils.trim(otpValidationRequest.getEmailOtp());
    try {
        ValidationResponseDTO responseDTO = EndpointUtils.getEmailOTPService().validateEmailOTP(transactionId, userId, emailOtp);
        FailureReasonDTO failureReasonDTO = responseDTO.getFailureReason();
        OTPValidationFailureReason failureReason = null;
        if (failureReasonDTO != null) {
            failureReason = new OTPValidationFailureReason().code(failureReasonDTO.getCode()).message(failureReasonDTO.getMessage()).description(failureReasonDTO.getDescription());
        }
        OTPValidationResponse response = new OTPValidationResponse().isValid(responseDTO.isValid()).userId(responseDTO.getUserId()).failureReason(failureReason);
        return Response.ok(response).build();
    } catch (EmailOtpClientException e) {
        return EndpointUtils.handleBadRequestResponse(e, log);
    } catch (EmailOtpException e) {
        return EndpointUtils.handleServerErrorResponse(e, log);
    } catch (Throwable e) {
        return EndpointUtils.handleUnexpectedServerError(e, log);
    }
}
Also used : FailureReasonDTO(org.wso2.carbon.extension.identity.emailotp.common.dto.FailureReasonDTO) EmailOtpClientException(org.wso2.carbon.extension.identity.emailotp.common.exception.EmailOtpClientException) OTPValidationFailureReason(org.wso2.carbon.identity.api.otp.service.emailotp.dto.OTPValidationFailureReason) ValidationResponseDTO(org.wso2.carbon.extension.identity.emailotp.common.dto.ValidationResponseDTO) OTPValidationResponse(org.wso2.carbon.identity.api.otp.service.emailotp.dto.OTPValidationResponse) EmailOtpException(org.wso2.carbon.extension.identity.emailotp.common.exception.EmailOtpException)

Example 2 with FailureReason

use of org.wso2.carbon.user.core.common.FailureReason in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticator method redirectToMobileNoReqPage.

/**
 * Redirect the user to mobile number request page.
 *
 * @param response    the HttpServletResponse
 * @param context     the AuthenticationContext
 * @param queryParams the queryParams
 * @throws AuthenticationFailedException
 */
private void redirectToMobileNoReqPage(HttpServletResponse response, AuthenticationContext context, String queryParams) throws AuthenticationFailedException {
    boolean isEnableMobileNoUpdate = SMSOTPUtils.isEnableMobileNoUpdate(context);
    if (isEnableMobileNoUpdate) {
        String loginPage = SMSOTPUtils.getMobileNumberRequestPage(context);
        try {
            String url = getURL(loginPage, queryParams);
            if (log.isDebugEnabled()) {
                log.debug("Redirecting to mobile number request page : " + url);
            }
            String mobileNumberPatternViolationError = SMSOTPConstants.MOBILE_NUMBER_PATTERN_POLICY_VIOLATED;
            String mobileNumberPattern = context.getAuthenticatorProperties().get(SMSOTPConstants.MOBILE_NUMBER_REGEX);
            if (isMobileNumberUpdateFailed(context)) {
                url = FrameworkUtils.appendQueryParamsStringToUrl(url, SMSOTPConstants.RETRY_PARAMS);
                if (context.getProperty(SMSOTPConstants.PROFILE_UPDATE_FAILURE_REASON) != null) {
                    String failureReason = String.valueOf(context.getProperty(SMSOTPConstants.PROFILE_UPDATE_FAILURE_REASON));
                    String urlEncodedFailureReason = URLEncoder.encode(failureReason, CHAR_SET_UTF_8);
                    String failureQueryParam = SMSOTPConstants.ERROR_MESSAGE_DETAILS + urlEncodedFailureReason;
                    url = FrameworkUtils.appendQueryParamsStringToUrl(url, failureQueryParam);
                }
            }
            if (StringUtils.isNotEmpty(mobileNumberPattern)) {
                // Check for regex is violation error message configured in idp configuration.
                if (StringUtils.isNotEmpty(context.getAuthenticatorProperties().get(SMSOTPConstants.MOBILE_NUMBER_PATTERN_FAILURE_ERROR_MESSAGE))) {
                    mobileNumberPatternViolationError = context.getAuthenticatorProperties().get(SMSOTPConstants.MOBILE_NUMBER_PATTERN_FAILURE_ERROR_MESSAGE);
                }
                // Send the response with encoded regex pattern and error message.
                response.sendRedirect(FrameworkUtils.appendQueryParamsStringToUrl(url, SMSOTPConstants.MOBILE_NUMBER_REGEX_PATTERN_QUERY + getEncoder().encodeToString(context.getAuthenticatorProperties().get(SMSOTPConstants.MOBILE_NUMBER_REGEX).getBytes()) + SMSOTPConstants.MOBILE_NUMBER_PATTERN_POLICY_FAILURE_ERROR_MESSAGE_QUERY + getEncoder().encodeToString(mobileNumberPatternViolationError.getBytes())));
            } else {
                response.sendRedirect(url);
            }
        } catch (IOException e) {
            throw new AuthenticationFailedException("Authentication failed!. An IOException was caught. ", e);
        }
    } else {
        throw new AuthenticationFailedException("Authentication failed!. Update mobile no in your profile.");
    }
}
Also used : AuthenticationFailedException(org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException) IOException(java.io.IOException)

Example 3 with FailureReason

use of org.wso2.carbon.user.core.common.FailureReason in project identity-otp-integration-endpoints by wso2-extensions.

the class SmsotpApiServiceImpl method smsotpValidatePost.

@Override
public Response smsotpValidatePost(OTPValidationRequest otpValidationRequest) {
    String transactionId = StringUtils.trim(otpValidationRequest.getTransactionId());
    String userId = StringUtils.trim(otpValidationRequest.getUserId());
    String smsOtp = StringUtils.trim(otpValidationRequest.getSmsOTP());
    try {
        ValidationResponseDTO responseDTO = EndpointUtils.getSMSOTPService().validateSMSOTP(transactionId, userId, smsOtp);
        FailureReasonDTO failureReasonDTO = responseDTO.getFailureReason();
        OTPValidationFailureReason failureReason = null;
        if (failureReasonDTO != null) {
            failureReason = new OTPValidationFailureReason().code(failureReasonDTO.getCode()).message(failureReasonDTO.getMessage()).description(failureReasonDTO.getDescription());
        }
        OTPValidationResponse response = new OTPValidationResponse().isValid(responseDTO.isValid()).userId(responseDTO.getUserId()).failureReason(failureReason);
        return Response.ok(response).build();
    } catch (SMSOTPClientException e) {
        return EndpointUtils.handleBadRequestResponse(e, log);
    } catch (SMSOTPException e) {
        return EndpointUtils.handleServerErrorResponse(e, log);
    } catch (Throwable e) {
        return EndpointUtils.handleUnexpectedServerError(e, log);
    }
}
Also used : FailureReasonDTO(org.wso2.carbon.identity.smsotp.common.dto.FailureReasonDTO) OTPValidationFailureReason(org.wso2.carbon.identity.api.otp.service.smsotp.dto.OTPValidationFailureReason) ValidationResponseDTO(org.wso2.carbon.identity.smsotp.common.dto.ValidationResponseDTO) SMSOTPClientException(org.wso2.carbon.identity.smsotp.common.exception.SMSOTPClientException) SMSOTPException(org.wso2.carbon.identity.smsotp.common.exception.SMSOTPException) OTPValidationResponse(org.wso2.carbon.identity.api.otp.service.smsotp.dto.OTPValidationResponse)

Example 4 with FailureReason

use of org.wso2.carbon.user.core.common.FailureReason in project product-is by wso2.

the class UUIDUserStoreManagerService method getAuthenticationResultDTOFromAuthenticationResult.

private AuthenticationResultDTO getAuthenticationResultDTOFromAuthenticationResult(AuthenticationResult authenticationResult) {
    AuthenticationResultDTO authenticationResultDTO = new AuthenticationResultDTO();
    authenticationResultDTO.setAuthenticatedSubjectIdentifier(authenticationResult.getAuthenticatedSubjectIdentifier());
    authenticationResultDTO.setAuthenticatedUser(getUserDTO(authenticationResult.getAuthenticatedUser().orElse(new User())));
    authenticationResultDTO.setAuthenticationStatus(getAuthenticationStatusDTOFromAuthenticationStatus(authenticationResult.getAuthenticationStatus()));
    authenticationResultDTO.setFailureReason(getFailureReasonDTOFromFailureReason(authenticationResult.getFailureReason().orElse(new FailureReason())));
    return authenticationResultDTO;
}
Also used : User(org.wso2.carbon.user.core.common.User) AuthenticationResultDTO(org.wso2.carbon.identity.test.integration.service.dao.AuthenticationResultDTO) FailureReason(org.wso2.carbon.user.core.common.FailureReason)

Example 5 with FailureReason

use of org.wso2.carbon.user.core.common.FailureReason in project product-is by wso2.

the class UUIDUserStoreManagerService method getFailureReasonDTOFromFailureReason.

private FailureReasonDTO getFailureReasonDTOFromFailureReason(FailureReason failureReason) {
    FailureReasonDTO failureReasonDTO = new FailureReasonDTO();
    failureReasonDTO.setFailureReason(failureReason.getFailureReason());
    failureReasonDTO.setId(failureReason.getId());
    return failureReasonDTO;
}
Also used : FailureReasonDTO(org.wso2.carbon.identity.test.integration.service.dao.FailureReasonDTO)

Aggregations

IOException (java.io.IOException)1 FailureReasonDTO (org.wso2.carbon.extension.identity.emailotp.common.dto.FailureReasonDTO)1 ValidationResponseDTO (org.wso2.carbon.extension.identity.emailotp.common.dto.ValidationResponseDTO)1 EmailOtpClientException (org.wso2.carbon.extension.identity.emailotp.common.exception.EmailOtpClientException)1 EmailOtpException (org.wso2.carbon.extension.identity.emailotp.common.exception.EmailOtpException)1 OTPValidationFailureReason (org.wso2.carbon.identity.api.otp.service.emailotp.dto.OTPValidationFailureReason)1 OTPValidationResponse (org.wso2.carbon.identity.api.otp.service.emailotp.dto.OTPValidationResponse)1 OTPValidationFailureReason (org.wso2.carbon.identity.api.otp.service.smsotp.dto.OTPValidationFailureReason)1 OTPValidationResponse (org.wso2.carbon.identity.api.otp.service.smsotp.dto.OTPValidationResponse)1 AuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException)1 FailureReasonDTO (org.wso2.carbon.identity.smsotp.common.dto.FailureReasonDTO)1 ValidationResponseDTO (org.wso2.carbon.identity.smsotp.common.dto.ValidationResponseDTO)1 SMSOTPClientException (org.wso2.carbon.identity.smsotp.common.exception.SMSOTPClientException)1 SMSOTPException (org.wso2.carbon.identity.smsotp.common.exception.SMSOTPException)1 AuthenticationResultDTO (org.wso2.carbon.identity.test.integration.service.dao.AuthenticationResultDTO)1 FailureReasonDTO (org.wso2.carbon.identity.test.integration.service.dao.FailureReasonDTO)1 FailureReason (org.wso2.carbon.user.core.common.FailureReason)1 User (org.wso2.carbon.user.core.common.User)1