use of uk.gov.di.ipv.cri.passport.library.exceptions.SqsException in project di-ipv-cri-uk-passport-back by alphagov.
the class AuditService method sendAuditEvent.
public void sendAuditEvent(AuditEventTypes eventType) throws SqsException {
try {
SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(generateMessageBody(eventType));
sqs.sendMessage(sendMessageRequest);
} catch (JsonProcessingException e) {
throw new SqsException(e);
}
}
use of uk.gov.di.ipv.cri.passport.library.exceptions.SqsException in project di-ipv-cri-uk-passport-back by alphagov.
the class AuthorizationCodeHandler method handleRequest.
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
Map<String, List<String>> queryStringParameters = getQueryStringParametersAsMap(input);
String userId = RequestHelper.getHeaderByKey(input.getHeaders(), "user_id");
try {
var validationResult = authRequestValidator.validateRequest(queryStringParameters, userId);
if (validationResult.isPresent()) {
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_BAD_REQUEST, validationResult.get());
}
AuthenticationRequest authenticationRequest = AuthenticationRequest.parse(queryStringParameters);
PassportAttributes passportAttributes = parsePassportFormRequest(input.getBody());
JWSObject preparedDcsPayload = preparePayload(passportAttributes);
DcsSignedEncryptedResponse dcsResponse = doPassportCheck(preparedDcsPayload);
auditService.sendAuditEvent(AuditEventTypes.PASSPORT_REQUEST_SENT_TO_DCS);
DcsResponse unwrappedDcsResponse = unwrapDcsResponse(dcsResponse);
passportAttributes.setDcsResponse(unwrappedDcsResponse);
validateDcsResponse(unwrappedDcsResponse);
PassportCheckDao passportCheckDao = new PassportCheckDao(UUID.randomUUID().toString(), passportAttributes, generateGpg45Score(unwrappedDcsResponse), userId);
passportService.persistDcsResponse(passportCheckDao);
AuthorizationCode authorizationCode = authorizationCodeService.generateAuthorizationCode();
authorizationCodeService.persistAuthorizationCode(authorizationCode.getValue(), passportCheckDao.getResourceId(), authenticationRequest.getRedirectionURI().toString());
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_OK, Map.of(AUTHORIZATION_CODE, authorizationCode));
} catch (HttpResponseExceptionWithErrorBody e) {
return ApiGatewayResponseGenerator.proxyJsonResponse(e.getStatusCode(), e.getErrorBody());
} catch (ParseException e) {
LOGGER.error("Authentication request could not be parsed", e);
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_BAD_REQUEST, ErrorResponse.FAILED_TO_PARSE_OAUTH_QUERY_STRING_PARAMETERS);
} catch (SqsException e) {
LOGGER.error("Failed to send audit event to SQS queue because: {}", e.getMessage());
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_BAD_REQUEST, ErrorResponse.FAILED_TO_SEND_AUDIT_MESSAGE_TO_SQS_QUEUE);
}
}
use of uk.gov.di.ipv.cri.passport.library.exceptions.SqsException in project di-ipv-cri-uk-passport-back by alphagov.
the class IssueCredentialHandler method handleRequest.
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
try {
String accessTokenString = RequestHelper.getHeaderByKey(input.getHeaders(), AUTHORIZATION_HEADER_KEY);
// Performs validation on header value and throws a ParseException if invalid
AccessToken.parse(accessTokenString);
String resourceId = accessTokenService.getResourceIdByAccessToken(accessTokenString);
if (StringUtils.isBlank(resourceId)) {
LOGGER.error("User credential could not be retrieved. The supplied access token was not found in the database.");
return ApiGatewayResponseGenerator.proxyJsonResponse(OAuth2Error.ACCESS_DENIED.getHTTPStatusCode(), OAuth2Error.ACCESS_DENIED.appendDescription(" - The supplied access token was not found in the database").toJSONObject());
}
PassportCheckDao passportCheck = dcsPassportCheckService.getDcsPassportCheck(resourceId);
VerifiableCredential verifiableCredential = VerifiableCredential.fromPassportCheckDao(passportCheck);
SignedJWT signedJWT = generateAndSignVerifiableCredentialJwt(verifiableCredential, passportCheck.getUserId());
auditService.sendAuditEvent(AuditEventTypes.PASSPORT_CREDENTIAL_ISSUED);
return ApiGatewayResponseGenerator.proxyJwtResponse(HttpStatus.SC_OK, signedJWT.serialize());
} catch (ParseException e) {
LOGGER.error("Failed to parse access token");
return ApiGatewayResponseGenerator.proxyJsonResponse(e.getErrorObject().getHTTPStatusCode(), e.getErrorObject().toJSONObject());
} catch (JOSEException e) {
LOGGER.error("Failed to sign verifiable credential: '{}'", e.getMessage());
return ApiGatewayResponseGenerator.proxyJsonResponse(OAuth2Error.SERVER_ERROR.getHTTPStatusCode(), OAuth2Error.SERVER_ERROR.appendDescription(" " + e.getMessage()).toJSONObject());
} catch (SqsException e) {
LOGGER.error("Failed to send audit event to SQS queue because: {}", e.getMessage());
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_BAD_REQUEST, ErrorResponse.FAILED_TO_SEND_AUDIT_MESSAGE_TO_SQS_QUEUE);
}
}
Aggregations