use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.
the class RSEndpointWrapper method execute.
public ResponseEntity execute(R main) throws OBErrorResponseException {
log.info("execute method");
try {
log.debug("execute() Apply filters");
applyFilters();
if (additionalFilter != null) {
additionalFilter.filter(this);
}
log.debug("execute() Filters applied");
log.info("execute() Call main lambda");
ResponseEntity response = run(main);
String tan = rsEndpointWrapperService.getTan();
// TODO: Does this mean we create jwsSignatures for all responses to RS calls? We don't need to sign
// requests to accounts endpoints, although I guess it doesn't hurt if we do. Just wasteful in terms of
// processing time etc.
String jwsSignature = rsEndpointWrapperService.generateDetachedJws(response, obVersion, tan, xFapiFinancialId);
return ResponseEntity.status(response.getStatusCode()).header("x-jws-signature", jwsSignature).body(response.getBody());
} catch (OBErrorException e) {
log.warn("Verification failed", e);
throw new OBErrorResponseException(e.getObriErrorType().getHttpStatus(), OBRIErrorResponseCategory.REQUEST_FILTER, e.getOBError());
} catch (JsonProcessingException e) {
log.warn("Failed to process JSON response", e);
throw new OBErrorResponseException(HttpStatus.INTERNAL_SERVER_ERROR, OBRIErrorResponseCategory.REQUEST_FILTER, SERVER_ERROR.toOBError1());
}
}
use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.
the class AggregatedPollingApiController method pollEvents.
@Override
public ResponseEntity pollEvents(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBEventPolling1 obEventPolling, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @ApiParam(value = "The PISP Client ID") @RequestHeader(value = "x-ob-client-id", required = true) String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
final Optional<Tpp> isTpp = Optional.ofNullable(tppRepository.findByClientId(clientId));
if (isTpp.isEmpty()) {
log.warn("No TPP found for client id '{}'", clientId);
throw new OBErrorResponseException(HttpStatus.NOT_FOUND, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.TPP_NOT_FOUND.toOBError1(clientId));
}
final String tppId = isTpp.get().getId();
FREventPolling frEventPolling = toFREventPolling(obEventPolling);
log.debug("TPP '{}' sent aggregated polling request: {}", tppId, obEventPolling);
eventPollingService.acknowledgeEvents(frEventPolling, tppId);
eventPollingService.recordTppEventErrors(frEventPolling, tppId);
Map<String, String> allEventNotifications = eventPollingService.fetchNewEvents(frEventPolling, tppId);
// Apply limit on returned events
Map<String, String> truncatedEventNotifications = eventPollingService.truncateEvents(obEventPolling.getMaxEvents(), allEventNotifications, tppId);
boolean moreAvailable = truncatedEventNotifications.size() < allEventNotifications.size();
ResponseEntity<OBEventPollingResponse1> response = ResponseEntity.ok(new OBEventPollingResponse1().sets(truncatedEventNotifications).moreAvailable((truncatedEventNotifications.isEmpty()) ? null : moreAvailable));
log.debug("TPP '{}' aggregated polling response: {}", tppId, response.getBody());
return response;
}
use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiController method getTransactions.
@Override
public ResponseEntity<OBReadTransaction6> getTransactions(int page, String authorization, DateTime xFapiAuthDate, DateTime fromBookingDateTime, DateTime toBookingDateTime, DateTime firstAvailableDate, DateTime lastAvailableDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, List<String> accountIds, List<OBExternalPermissions1Code> permissions, String httpUrl) throws OBErrorResponseException {
log.info("Reading transations from account ids {}, fromBookingDate {} toBookingDate {} minimumPermissions {} pageNumber {} ", accountIds, fromBookingDateTime, toBookingDateTime, permissions, page);
if (toBookingDateTime == null) {
toBookingDateTime = DateTime.now();
}
if (fromBookingDateTime == null) {
fromBookingDateTime = toBookingDateTime.minusYears(100);
}
Page<FRTransaction> body = FRTransactionRepository.byAccountIdInAndBookingDateTimeBetweenWithPermissions(accountIds, fromBookingDateTime, toBookingDateTime, toFRExternalPermissionsCodeList(permissions), PageRequest.of(page, pageLimitTransactions, Sort.Direction.ASC, "bookingDateTime"));
List<OBTransaction6> transactions = body.getContent().stream().map(FRTransaction::getTransaction).map(FRTransactionConverter::toOBTransaction6).map(t -> accountDataInternalIdFilter.apply(t)).collect(Collectors.toList());
// Package the answer
int totalPages = body.getTotalPages();
return ResponseEntity.ok(new OBReadTransaction6().data(new OBReadDataTransaction6().transaction(transactions)).links(PaginationUtil.generateLinks(httpUrl, page, totalPages)).meta(PaginationUtil.generateMetaData(totalPages, firstAvailableDate, lastAvailableDate)));
}
use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalPaymentsApiController method createInternationalPayments.
@Override
public ResponseEntity<OBWriteInternationalResponse4> createInternationalPayments(OBWriteInternational3 obWriteInternational3, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("Received payment submission: '{}'", obWriteInternational3);
FRWriteInternational frWriteInternational = toFRWriteInternational(obWriteInternational3);
log.trace("Converted to: '{}'", frWriteInternational);
String paymentId = obWriteInternational3.getData().getConsentId();
FRInternationalConsent paymentConsent = internationalConsentRepository.findById(paymentId).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_CONSENT_BEHIND_SUBMISSION_NOT_FOUND.toOBError1(paymentId)));
log.debug("Found consent '{}' to match this payment id: {} ", paymentConsent, paymentId);
FRInternationalPaymentSubmission frPaymentSubmission = FRInternationalPaymentSubmission.builder().id(paymentId).internationalPayment(frWriteInternational).created(new Date()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
frPaymentSubmission = new IdempotentRepositoryAdapter<>(internationalPaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(frPaymentSubmission, paymentConsent));
}
use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalStandingOrdersApiController method createInternationalStandingOrders.
@Override
public ResponseEntity<OBWriteInternationalStandingOrderResponse6> createInternationalStandingOrders(OBWriteInternationalStandingOrder4 obWriteInternationalStandingOrder4, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("Received payment submission: '{}'", obWriteInternationalStandingOrder4);
FRWriteInternationalStandingOrder frInternationalStandingOrder = toFRWriteInternationalStandingOrder(obWriteInternationalStandingOrder4);
log.trace("Converted to: '{}'", frInternationalStandingOrder);
String paymentId = obWriteInternationalStandingOrder4.getData().getConsentId();
FRInternationalStandingOrderConsent paymentConsent = internationalStandingOrderConsentRepository.findById(paymentId).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_CONSENT_BEHIND_SUBMISSION_NOT_FOUND.toOBError1(paymentId)));
log.debug("Found consent '{}' to match this payment id: {} ", paymentConsent, paymentId);
FRInternationalStandingOrderPaymentSubmission frPaymentSubmission = FRInternationalStandingOrderPaymentSubmission.builder().id(paymentId).internationalStandingOrder(frInternationalStandingOrder).created(new Date()).updated(new Date()).idempotencyKey(xIdempotencyKey).version(VersionPathExtractor.getVersionFromPath(request)).build();
frPaymentSubmission = new IdempotentRepositoryAdapter<>(internationalStandingOrderPaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(frPaymentSubmission, paymentConsent));
}
Aggregations