Search in sources :

Example 1 with OBErrorResponseException

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());
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with OBErrorResponseException

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;
}
Also used : OBEventPollingResponse1(uk.org.openbanking.datamodel.event.OBEventPollingResponse1) Tpp(com.forgerock.openbanking.model.Tpp) FREventPollingConverter.toFREventPolling(com.forgerock.openbanking.common.services.openbanking.converter.event.FREventPollingConverter.toFREventPolling) FREventPolling(com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException)

Example 3 with OBErrorResponseException

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)));
}
Also used : PaginationUtil(com.forgerock.openbanking.aspsp.rs.store.utils.PaginationUtil) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) PageRequest(org.springframework.data.domain.PageRequest) Controller(org.springframework.stereotype.Controller) FRTransaction(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) FRTransactionConverter(com.forgerock.openbanking.common.services.openbanking.converter.account.FRTransactionConverter) FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList(com.forgerock.openbanking.common.services.openbanking.converter.account.FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList) Value(org.springframework.beans.factory.annotation.Value) Slf4j(lombok.extern.slf4j.Slf4j) OBTransaction6(uk.org.openbanking.datamodel.account.OBTransaction6) List(java.util.List) AccountDataInternalIdFilter(com.forgerock.openbanking.aspsp.rs.store.utils.AccountDataInternalIdFilter) OBExternalPermissions1Code(uk.org.openbanking.datamodel.account.OBExternalPermissions1Code) OBReadTransaction6(uk.org.openbanking.datamodel.account.OBReadTransaction6) FRTransactionRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.transactions.FRTransactionRepository) OBReadDataTransaction6(uk.org.openbanking.datamodel.account.OBReadDataTransaction6) Sort(org.springframework.data.domain.Sort) ResponseEntity(org.springframework.http.ResponseEntity) FRTransactionConverter(com.forgerock.openbanking.common.services.openbanking.converter.account.FRTransactionConverter) OBTransaction6(uk.org.openbanking.datamodel.account.OBTransaction6) FRTransaction(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction) OBReadTransaction6(uk.org.openbanking.datamodel.account.OBReadTransaction6) OBReadDataTransaction6(uk.org.openbanking.datamodel.account.OBReadDataTransaction6)

Example 4 with OBErrorResponseException

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));
}
Also used : IdempotentRepositoryAdapter(com.forgerock.openbanking.aspsp.rs.store.repository.IdempotentRepositoryAdapter) FRWriteInternational(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternational) FRWriteInternationalConverter.toFRWriteInternational(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalConverter.toFRWriteInternational) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) FRInternationalPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalPaymentSubmission) Date(java.util.Date)

Example 5 with OBErrorResponseException

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));
}
Also used : FRInternationalStandingOrderPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderPaymentSubmission) IdempotentRepositoryAdapter(com.forgerock.openbanking.aspsp.rs.store.repository.IdempotentRepositoryAdapter) FRInternationalStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) FRWriteInternationalStandingOrder(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrder) FRWriteInternationalStandingOrderConverter.toFRWriteInternationalStandingOrder(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalStandingOrderConverter.toFRWriteInternationalStandingOrder) Date(java.util.Date)

Aggregations

OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)213 ResponseEntity (org.springframework.http.ResponseEntity)140 Controller (org.springframework.stereotype.Controller)129 DateTime (org.joda.time.DateTime)121 HttpHeaders (org.springframework.http.HttpHeaders)108 Collections (java.util.Collections)103 Principal (java.security.Principal)102 HttpServletRequest (javax.servlet.http.HttpServletRequest)102 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)101 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)100 ApiParam (io.swagger.annotations.ApiParam)69 PathVariable (org.springframework.web.bind.annotation.PathVariable)69 RequestHeader (org.springframework.web.bind.annotation.RequestHeader)69 DateTimeFormat (org.springframework.format.annotation.DateTimeFormat)63 HTTP_DATE_FORMAT (com.forgerock.openbanking.constants.OpenBankingConstants.HTTP_DATE_FORMAT)59 ApiVersionUtils.getOBVersion (com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion)55 Logger (org.slf4j.Logger)50 LoggerFactory (org.slf4j.LoggerFactory)50 RequestBody (org.springframework.web.bind.annotation.RequestBody)49 Valid (javax.validation.Valid)48