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);
}
}
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.");
}
}
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);
}
}
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;
}
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;
}
Aggregations