Search in sources :

Example 16 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class CallbackUrlApiController method updateCallbackUrl.

@Override
public ResponseEntity updateCallbackUrl(@ApiParam(value = "CallbackUrlId", required = true) @PathVariable("CallbackUrlId") String callbackUrlId, @ApiParam(value = "Default", required = true) @Valid @RequestBody OBCallbackUrl1 obCallbackUrl1Param, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "Header containing a detached JWS signature of the body of the payload.", required = true) @RequestHeader(value = "x-jws-signature", required = false) String xJwsSignature, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    return rsEndpointWrapperService.eventNotificationEndpoint().authorization(authorization).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyJwsDetachedSignature(xJwsSignature, request);
        f.verifyMatcherVersion(obCallbackUrl1Param.getData().getUrl(), obCallbackUrl1Param.getData().getVersion());
    }).execute((String tppId) -> {
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add(OpenBankingHttpHeaders.X_OB_CLIENT_ID, tppId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBCallbackUrlResponse1.class, obCallbackUrl1Param);
    });
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) ApiParam(io.swagger.annotations.ApiParam) Controller(org.springframework.stereotype.Controller) OBCallbackUrlResponse1(uk.org.openbanking.datamodel.event.OBCallbackUrlResponse1) RequestBody(org.springframework.web.bind.annotation.RequestBody) Valid(javax.validation.Valid) Slf4j(lombok.extern.slf4j.Slf4j) OBCallbackUrl1(uk.org.openbanking.datamodel.event.OBCallbackUrl1) HttpServletRequest(javax.servlet.http.HttpServletRequest) Principal(java.security.Principal) OpenBankingHttpHeaders(com.forgerock.openbanking.common.constants.OpenBankingHttpHeaders) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) OBCallbackUrlsResponse1(uk.org.openbanking.datamodel.event.OBCallbackUrlsResponse1) Collections(java.util.Collections) HttpHeaders(org.springframework.http.HttpHeaders) OpenBankingHttpHeaders(com.forgerock.openbanking.common.constants.OpenBankingHttpHeaders)

Example 17 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class EventSubscriptionApiController method updateEventSubscription.

@Override
public ResponseEntity<OBEventSubscriptionResponse1> updateEventSubscription(@ApiParam(value = "EventSubscriptionId", required = true) @PathVariable("EventSubscriptionId") String eventSubscriptionId, @ApiParam(value = "Default", required = true) @Valid @RequestBody OBEventSubscriptionResponse1 obEventSubscriptionsParam, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "Header containing a detached JWS signature of the body of the payload.", required = true) @RequestHeader(value = "x-jws-signature", required = false) String xJwsSignature, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    return rsEndpointWrapperService.eventNotificationEndpoint().authorization(authorization).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyJwsDetachedSignature(xJwsSignature, request);
        EventValidationService.verifyValidCallbackUrl(obEventSubscriptionsParam);
    }).execute((String tppId) -> {
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add(OpenBankingHttpHeaders.X_OB_CLIENT_ID, tppId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBEventSubscriptionResponse1.class, obEventSubscriptionsParam);
    });
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) ApiParam(io.swagger.annotations.ApiParam) Controller(org.springframework.stereotype.Controller) RequestBody(org.springframework.web.bind.annotation.RequestBody) Valid(javax.validation.Valid) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) Principal(java.security.Principal) OpenBankingHttpHeaders(com.forgerock.openbanking.common.constants.OpenBankingHttpHeaders) EventValidationService(com.forgerock.openbanking.common.services.openbanking.event.EventValidationService) OBEventSubscriptionsResponse1(uk.org.openbanking.datamodel.event.OBEventSubscriptionsResponse1) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) OBEventSubscriptionResponse1(uk.org.openbanking.datamodel.event.OBEventSubscriptionResponse1) Collections(java.util.Collections) OBEventSubscription1(uk.org.openbanking.datamodel.event.OBEventSubscription1) HttpHeaders(org.springframework.http.HttpHeaders) OpenBankingHttpHeaders(com.forgerock.openbanking.common.constants.OpenBankingHttpHeaders)

Example 18 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class EventSubscriptionApiController method createEventSubscription.

@Override
public ResponseEntity<OBEventSubscriptionResponse1> createEventSubscription(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBEventSubscription1 obEventSubscription1, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "Header containing a detached JWS signature of the body of the payload.", required = true) @RequestHeader(value = "x-jws-signature", required = false) String xJwsSignature, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    return rsEndpointWrapperService.eventNotificationEndpoint().authorization(authorization).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyJwsDetachedSignature(xJwsSignature, request);
        EventValidationService.verifyValidCallbackUrl(obEventSubscription1);
    }).execute((String tppId) -> {
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add(OpenBankingHttpHeaders.X_OB_CLIENT_ID, tppId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBEventSubscriptionResponse1.class, obEventSubscription1);
    });
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) ApiParam(io.swagger.annotations.ApiParam) Controller(org.springframework.stereotype.Controller) RequestBody(org.springframework.web.bind.annotation.RequestBody) Valid(javax.validation.Valid) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) Principal(java.security.Principal) OpenBankingHttpHeaders(com.forgerock.openbanking.common.constants.OpenBankingHttpHeaders) EventValidationService(com.forgerock.openbanking.common.services.openbanking.event.EventValidationService) OBEventSubscriptionsResponse1(uk.org.openbanking.datamodel.event.OBEventSubscriptionsResponse1) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) OBEventSubscriptionResponse1(uk.org.openbanking.datamodel.event.OBEventSubscriptionResponse1) Collections(java.util.Collections) OBEventSubscription1(uk.org.openbanking.datamodel.event.OBEventSubscription1) HttpHeaders(org.springframework.http.HttpHeaders) OpenBankingHttpHeaders(com.forgerock.openbanking.common.constants.OpenBankingHttpHeaders)

Example 19 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class InternationalScheduledPaymentConsentsApiController method createInternationalScheduledPaymentConsents.

@Override
public ResponseEntity<OBWriteInternationalScheduledConsentResponse5> createInternationalScheduledPaymentConsents(OBWriteInternationalScheduledConsent5 obWriteInternationalScheduledConsent5, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    return rsEndpointWrapperService.paymentEndpoint().authorization(authorization).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyIdempotencyKeyLength(xIdempotencyKey);
        f.verifyJwsDetachedSignature(xJwsSignature, request);
        f.validateRisk(obWriteInternationalScheduledConsent5.getRisk());
    }).execute((String tppId) -> {
        exchangeRateVerifier.verify(obWriteInternationalScheduledConsent5.getData().getInitiation().getExchangeRateInformation());
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-client-id", tppId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalScheduledConsentResponse5.class, obWriteInternationalScheduledConsent5);
    });
}
Also used : OBWriteInternationalScheduledConsent5(uk.org.openbanking.datamodel.payment.OBWriteInternationalScheduledConsent5) OBWriteFundsConfirmationResponse1(uk.org.openbanking.datamodel.payment.OBWriteFundsConfirmationResponse1) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) HttpHeaders(org.springframework.http.HttpHeaders) OBWriteInternationalScheduledConsentResponse5(uk.org.openbanking.datamodel.payment.OBWriteInternationalScheduledConsentResponse5) OBWriteInternationalScheduledConsentResponse6(uk.org.openbanking.datamodel.payment.OBWriteInternationalScheduledConsentResponse6) InternationalScheduledPaymentService(com.forgerock.openbanking.common.services.store.payment.InternationalScheduledPaymentService) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) Controller(org.springframework.stereotype.Controller) ExchangeRateVerifier(com.forgerock.openbanking.aspsp.rs.api.payment.verifier.ExchangeRateVerifier) HttpServletRequest(javax.servlet.http.HttpServletRequest) Principal(java.security.Principal) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) FRInternationalScheduledConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) HttpHeaders(org.springframework.http.HttpHeaders)

Example 20 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class InternationalScheduledPaymentsApiController method createInternationalScheduledPayments.

@Override
public ResponseEntity<OBWriteInternationalScheduledResponse5> createInternationalScheduledPayments(OBWriteInternationalScheduled3 obWriteInternationalScheduled3, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    String consentId = obWriteInternationalScheduled3.getData().getConsentId();
    FRInternationalScheduledConsent payment = paymentsService.getPayment(consentId);
    return rsEndpointWrapperService.paymentSubmissionEndpoint().authorization(authorization).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).payment(payment).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyPaymentIdWithAccessToken();
        f.verifyIdempotencyKeyLength(xIdempotencyKey);
        f.verifyPaymentStatus();
        f.verifyRiskAndInitiation(toFRWriteInternationalScheduledDataInitiation(obWriteInternationalScheduled3.getData().getInitiation()), toFRRisk(obWriteInternationalScheduled3.getRisk()));
        f.verifyJwsDetachedSignature(xJwsSignature, request);
    }).execute((String tppId) -> {
        // Modify the status of the payment
        log.info("Switch status of payment {} to 'accepted settlement in process'.", consentId);
        FRWriteInternationalScheduledDataInitiation initiation = payment.getInitiation();
        FRScheduledPaymentData scheduledPayment = FRScheduledPaymentData.builder().accountId(payment.getAccountId()).creditorAccount(initiation.getCreditorAccount()).instructedAmount(initiation.getInstructedAmount()).scheduledType(FRScheduledPaymentData.FRScheduleType.EXECUTION).scheduledPaymentDateTime(initiation.getRequestedExecutionDateTime()).scheduledPaymentId(payment.getId()).build();
        String pispId = tppStoreService.findByClientId(tppId).map(tpp -> tpp.getId()).orElse(null);
        scheduledPaymentService.createSchedulePayment(scheduledPayment, pispId);
        payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
        log.info("Updating payment");
        paymentsService.updatePayment(payment);
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-payment-id", consentId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalScheduledResponse5.class, obWriteInternationalScheduled3);
    });
}
Also used : RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) FRScheduledPaymentData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData) FRWriteInternationalScheduledDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalScheduledDataInitiation) Controller(org.springframework.stereotype.Controller) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) FRInternationalScheduledConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) HttpHeaders(org.springframework.http.HttpHeaders) InternationalScheduledPaymentService(com.forgerock.openbanking.common.services.store.payment.InternationalScheduledPaymentService) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) Principal(java.security.Principal) OBWriteInternationalScheduledResponse5(uk.org.openbanking.datamodel.payment.OBWriteInternationalScheduledResponse5) ScheduledPaymentService(com.forgerock.openbanking.common.services.store.account.scheduledpayment.ScheduledPaymentService) ResponseEntity(org.springframework.http.ResponseEntity) FRPaymentRiskConverter.toFRRisk(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRPaymentRiskConverter.toFRRisk) OBWritePaymentDetailsResponse1(uk.org.openbanking.datamodel.payment.OBWritePaymentDetailsResponse1) Collections(java.util.Collections) TppStoreService(com.forgerock.openbanking.common.services.store.tpp.TppStoreService) OBWriteInternationalScheduled3(uk.org.openbanking.datamodel.payment.OBWriteInternationalScheduled3) FRScheduledPaymentData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData) HttpHeaders(org.springframework.http.HttpHeaders) FRWriteInternationalScheduledDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalScheduledDataInitiation) FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation) FRInternationalScheduledConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent)

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