Search in sources :

Example 6 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpsApiController method domesticVrpPost.

@Override
public /**
 *         @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true)
 *             @RequestHeader(value = "Authorization", required = true) String authorization,
 *
 *             @ApiParam(value = "A detached JWS signature of the body of the payload.", required = true)
 *             @RequestHeader(value = "x-jws-signature", required = true) String xJwsSignature,
 *
 *             @ApiParam(value = "Default", required = true)
 *             @Valid
 *             @RequestBody OBDomesticVRPRequest obDomesticVRPRequest,
 *
 *             @ApiParam(value = "The time when the PSU last logged in with the TPP.  All dates in the HTTP headers are represented as RFC 7231 Full Dates. An example is below:  Sun, 10 Sep 2017 19:43:31 UTC")
 *             @RequestHeader(value = "x-fapi-auth-date", required = false) String xFapiAuthDate,
 *
 *             @ApiParam(value = "The PSU's IP address if the PSU is currently logged in with the TPP.")
 *             @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress,
 *
 *             @ApiParam(value = "An RFC4122 UID used as a correlation id.")
 *             @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId,
 *
 *             @ApiParam(value = "Indicates the user-agent that the PSU is using.")
 *             @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent,
 */
ResponseEntity<OBDomesticVRPResponse> domesticVrpPost(String authorization, String xJwsSignature, OBDomesticVRPRequest obDomesticVRPRequest, String xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("domesticVrpPost() Recieved OBDomesticVrpRequest {}", obDomesticVRPRequest);
    @NotNull @Valid OBDomesticVRPInitiation initiation = obDomesticVRPRequest.getData().getInitiation();
    String consentId = obDomesticVRPRequest.getData().getConsentId();
    log.debug("domesticVrpPost() consentId is {}", consentId);
    FRDomesticVRPConsent consent = vrpPaymentConsentService.getVrpPaymentConsent(consentId);
    DomesticVrpPaymentsEndpointWrapper vrpPaymentsEndpointWrapper = rsEndpointWrapperService.vrpPaymentEndpoint();
    vrpPaymentsEndpointWrapper.authorization(authorization);
    vrpPaymentsEndpointWrapper.obVersion(OBVersion.v3_1_8);
    vrpPaymentsEndpointWrapper.xFapiFinancialId(rsEndpointWrapperService.getRsConfiguration().financialId);
    vrpPaymentsEndpointWrapper.principal(principal);
    vrpPaymentsEndpointWrapper.payment(consent);
    vrpPaymentsEndpointWrapper.isAuthorizationCodeGrantType(true);
    vrpPaymentsEndpointWrapper.filters(f -> {
        f.verifyJwsDetachedSignature(xJwsSignature, request);
        f.validateRisk(obDomesticVRPRequest.getRisk());
        f.checkRequestAndConsentInitiationMatch(initiation, consent);
        f.checkRequestAndConsentRiskMatch(obDomesticVRPRequest, consent);
        f.checkControlParameters(obDomesticVRPRequest, consent);
        f.checkCreditorAccountIsInInstructionIfNotInConsent(obDomesticVRPRequest, consent);
    });
    ResponseEntity responseEntity = vrpPaymentsEndpointWrapper.execute((String tppId) -> {
        HttpHeaders additionalHeaders = new HttpHeaders();
        additionalHeaders.add("x-ob-client-id", tppId);
        return rsStoreGateway.toRsStore(request, additionalHeaders, Collections.emptyMap(), OBDomesticVRPResponse.class, obDomesticVRPRequest);
    });
    return responseEntity;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Valid(javax.validation.Valid) DomesticVrpPaymentsEndpointWrapper(com.forgerock.openbanking.aspsp.rs.wrappper.endpoints.DomesticVrpPaymentsEndpointWrapper) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) NotNull(javax.validation.constraints.NotNull)

Example 7 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpConsentsApiController method domesticVrpConsentsFundsConfirmation.

@Override
public ResponseEntity domesticVrpConsentsFundsConfirmation(String consentId, String authorization, String xJwsSignature, OBVRPFundsConfirmationRequest obVRPFundsConfirmationRequest, String xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("(store) Request to get a VRP funds confirmation, consentId '{}', mode test '{}'", consentId, StringUtils.hasLength(request.getHeader(OpenBankingHttpHeaders.X_OB_MODE_TEST)));
    boolean areFundsAvailable = false;
    // check header 'x-ob-mode-test' to restrict the behaviour for test purposes
    if (StringUtils.hasLength(request.getHeader(OpenBankingHttpHeaders.X_OB_MODE_TEST))) {
        areFundsAvailable = true;
    } else {
        Optional<FRDomesticVRPConsent> optional = domesticVRPConsentRepository.findById(consentId);
        if (!optional.isPresent()) {
            log.warn("(store) Domestic VRP payment consent '{}' to confirm funds can't be found", consentId);
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Domestic VRP payment consent '" + consentId + "' to confirm funds can't be found");
        }
        FRDomesticVRPConsent domesticVrpConsent = optional.get();
        if (!domesticVrpConsent.getStatus().equals(ConsentStatusCode.AUTHORISED)) {
            log.error("(store) Funds confirmation for VRP payment consent Id '{}, with status '{}' can't be requested" + " because the consent status hasn't '{}'", consentId, domesticVrpConsent.getStatus().getValue(), ConsentStatusCode.AUTHORISED.getValue());
            throw new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.CONSENT_STATUS_NOT_AUTHORISED.toOBError1(consentId));
        }
        // Check if funds are available on the account selected in consent
        String accountIdentification = domesticVrpConsent.getVrpDetails().getData().getInitiation().getDebtorAccount().getIdentification();
        Collection<FRAccount> accountsByUserID = accountRepository.findByUserID(Objects.requireNonNull(domesticVrpConsent.getUserId()));
        Optional<FRAccount> accountOptional = accountsByUserID.stream().filter(account -> account.getAccount().getAccounts().stream().filter(a -> a.getIdentification().equals(accountIdentification)).findFirst().isPresent()).findFirst();
        if (!accountOptional.isPresent()) {
            log.warn("(store) VRP consent '{}', debtor account with identitication '{}' can't be found", consentId, accountIdentification);
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("VRP consent '" + consentId + "', debtor account with identitication '" + accountIdentification + "' to confirm funds can't be found");
        }
        areFundsAvailable = fundsAvailabilityService.isFundsAvailable(accountOptional.get().getId(), obVRPFundsConfirmationRequest.getData().getInstructedAmount().getAmount());
    }
    OBVRPFundsConfirmationRequestData data = obVRPFundsConfirmationRequest.getData();
    return ResponseEntity.status(HttpStatus.OK).body(new OBVRPFundsConfirmationResponse().data(new OBVRPFundsConfirmationResponseData().fundsConfirmationId(UUID.randomUUID().toString()).consentId(consentId).creationDateTime(DateTime.now()).reference(data.getReference()).fundsAvailableResult(new OBPAFundsAvailableResult1().fundsAvailable(areFundsAvailable ? OBPAFundsAvailableResult1.FundsAvailableEnum.AVAILABLE : OBPAFundsAvailableResult1.FundsAvailableEnum.NOTAVAILABLE).fundsAvailableDateTime(DateTime.now())).instructedAmount(data.getInstructedAmount())));
}
Also used : IntentType(com.forgerock.openbanking.common.model.openbanking.IntentType) Tpp(com.forgerock.openbanking.model.Tpp) Controller(org.springframework.stereotype.Controller) ConsentStatusEntry(com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry) FRDomesticVRPConsentConverter.toOBDomesticVRPConsentResponse(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toOBDomesticVRPConsentResponse) TppRepository(com.forgerock.openbanking.repositories.TppRepository) uk.org.openbanking.datamodel.vrp(uk.org.openbanking.datamodel.vrp) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) FRDomesticVRPConsentDetails(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetails) FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails) OBRIErrorResponseCategory(com.forgerock.openbanking.model.error.OBRIErrorResponseCategory) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FundsAvailabilityService(com.forgerock.openbanking.common.services.openbanking.FundsAvailabilityService) DiscoveryConfigurationProperties(com.forgerock.openbanking.common.conf.discovery.DiscoveryConfigurationProperties) IdempotencyService.validateIdempotencyRequest(com.forgerock.openbanking.common.services.openbanking.IdempotencyService.validateIdempotencyRequest) Collection(java.util.Collection) FRAccountRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) VersionPathExtractor(com.forgerock.openbanking.aspsp.rs.store.utils.VersionPathExtractor) OBRIErrorType(com.forgerock.openbanking.model.error.OBRIErrorType) UUID(java.util.UUID) Objects(java.util.Objects) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) OBDiscoveryAPILinksVrpPayment(uk.org.openbanking.datamodel.discovery.OBDiscoveryAPILinksVrpPayment) Principal(java.security.Principal) OpenBankingHttpHeaders(com.forgerock.openbanking.common.constants.OpenBankingHttpHeaders) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) DomesticVRPConsentRepository(com.forgerock.openbanking.aspsp.rs.store.repository.vrp.DomesticVRPConsentRepository) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) ConsentMetricService(com.forgerock.openbanking.analytics.services.ConsentMetricService) ResourceLinkService(com.forgerock.openbanking.common.conf.discovery.ResourceLinkService) StringUtils(org.springframework.util.StringUtils) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException)

Example 8 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpConsentsApiController method domesticVrpConsentsPost.

@Override
public ResponseEntity<OBDomesticVRPConsentResponse> domesticVrpConsentsPost(String authorization, String xIdempotencyKey, String xJwsSignature, OBDomesticVRPConsentRequest obDomesticVRPConsentRequest, String xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("(store) Received Domestic VRP consent: '{}'", obDomesticVRPConsentRequest);
    log.debug("(store) Request to create a VRP consent received, interactionId '{}'", xFapiInteractionId);
    FRDomesticVRPConsentDetails frDomesticVRPDetails = toFRDomesticVRPConsentDetails(obDomesticVRPConsentRequest);
    log.trace("Converted OB Domestic VRP consent to: '{}'", frDomesticVRPDetails);
    final Tpp tpp = tppRepository.findByClientId(clientId);
    log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
    Optional<FRDomesticVRPConsent> vrpConsentByIdempotencyKey = domesticVRPConsentRepository.findByIdempotencyKeyAndPispId(xIdempotencyKey, tpp.getId());
    if (vrpConsentByIdempotencyKey.isPresent()) {
        validateIdempotencyRequest(xIdempotencyKey, frDomesticVRPDetails, vrpConsentByIdempotencyKey.get(), () -> vrpConsentByIdempotencyKey.get().getVrpDetails());
        log.info("Idempotent request for VRP payment consent is valid. Returning [201 CREATED] but take no further action.");
        return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(vrpConsentByIdempotencyKey.get()));
    }
    log.debug("No Domestic VRP payment consent with matching idempotency key has been found. Creating new consent.");
    FRDomesticVRPConsent domesticVrpConsent = FRDomesticVRPConsent.builder().id(IntentType.DOMESTIC_VRP_PAYMENT_CONSENT.generateIntentId()).status(ConsentStatusCode.AWAITINGAUTHORISATION).vrpDetails(frDomesticVRPDetails).pispId(tpp.getId()).pispName(tpp.getOfficialName()).statusUpdate(DateTime.now()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    log.debug("Saving Domestic VRP payment consent: '{}'", domesticVrpConsent);
    consentMetricService.sendConsentActivity(new ConsentStatusEntry(domesticVrpConsent.getId(), domesticVrpConsent.getStatus().name()));
    domesticVRPConsentRepository.save(domesticVrpConsent);
    log.info("Created domestic VRP payment consent id: '{}'", domesticVrpConsent.getId());
    return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(domesticVrpConsent));
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) FRDomesticVRPConsentDetails(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetails) FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) ConsentStatusEntry(com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)

Example 9 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class RCSVrpPaymentDetailsApi method consentDetails.

@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
    log.debug("Received a VRP consent request with consent_request='{}'", remoteConsentRequest);
    log.debug("=> The VRP payment consent id '{}'", consentId);
    log.debug("Populate the model with the VRP payment and consent data");
    FRDomesticVRPConsent vrpConsent = consentService.getVrpPaymentConsent(consentId);
    if (vrpConsent == null) {
        log.error("VRP Consent ID '{}' not found", consentId);
        return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_INVALID, String.format("Consent ID '%s' not found.", consentId));
    }
    Optional<Tpp> isTpp = tppStoreService.findById(vrpConsent.getPispId());
    if (isTpp.isEmpty()) {
        log.error("The TPP '{}' (Client ID {}) that created this vrp consent id '{}' doesn't exist anymore.", vrpConsent.getPispId(), clientId, consentId);
        return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
    }
    Tpp tpp = isTpp.get();
    // Verify the pisp is the same than the one that created this payment ^
    verifyTppCreatedPayment(clientId, tpp.getClientId(), consentId);
    // Associate the vrp payment to this user
    vrpConsent.setUserId(username);
    consentService.updateVrpPaymentConsent(vrpConsent);
    FRDomesticVRPConsentDetailsData data = vrpConsent.getVrpDetails().getData();
    return ResponseEntity.ok(DomesticVrpPaymentConsentDetails.builder().username(username).pispName(tpp.getOfficialName()).aspspName(platformConfiguration.getAspspName()).merchantName(vrpConsent.getPispName()).logo(tpp.getLogo()).clientId(clientId).creditorAccount(Optional.ofNullable(data.getInitiation().getCreditorAccount()).orElse(null)).debtorAccount(Optional.ofNullable(data.getInitiation().getDebtorAccount()).orElse(null)).controlParameters(Optional.ofNullable(data.getControlParameters()).orElse(null)).paymentReference(Optional.ofNullable(data.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse(null)).debtorReference(Optional.ofNullable(data.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getUnstructured).orElse(null)).build());
}
Also used : FRDomesticVRPConsentDetailsData(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetailsData) FRRemittanceInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation) Tpp(com.forgerock.openbanking.model.Tpp) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent)

Example 10 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpConsentsApiControllerIT method getDomesticVrpPaymentConsent.

@Test
public void getDomesticVrpPaymentConsent() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRDomesticVRPConsent consent = saveFRConsent(IntentType.DOMESTIC_VRP_PAYMENT_CONSENT.generateIntentId(), FRReadRefundAccount.NO, ConsentStatusCode.EXPIRED);
    // When
    HttpResponse<OBDomesticVRPConsentResponse> response = Unirest.get(RS_STORE_URL + port + CONTEXT_PATH + consent.getId()).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").asObject(OBDomesticVRPConsentResponse.class);
    log.debug("Response {}:{}  {}", response.getStatus(), response.getStatusText(), response.getBody());
    if (response.getParsingError().isPresent()) {
        log.error("Parsing error", response.getParsingError().get());
    }
    // Then
    assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
    assertThat(response.getBody().getData().getConsentId()).isEqualTo(consent.getId());
    assertThat(toFRWriteDomesticVRPDataInitiation(response.getBody().getData().getInitiation())).isEqualTo(consent.getInitiation());
    assertThat(response.getBody().getData().getStatus().getValue()).isEqualTo(consent.getStatus().getValue());
}
Also used : FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test)

Aggregations

FRDomesticVRPConsent (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent)28 Test (org.junit.Test)20 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 ResponseEntity (org.springframework.http.ResponseEntity)6 OBDomesticVRPRequestTestDataFactory.aValidOBDomesticVRPRequest (uk.org.openbanking.testsupport.vrp.OBDomesticVRPRequestTestDataFactory.aValidOBDomesticVRPRequest)6 FRDomesticVRPConsentDetails (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetails)5 FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails (com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails)5 Tpp (com.forgerock.openbanking.model.Tpp)4 OBDomesticVRPRequest (uk.org.openbanking.datamodel.vrp.OBDomesticVRPRequest)4 FRDomesticVrpPaymentSubmission (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVrpPaymentSubmission)3 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)3 OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest (uk.org.openbanking.testsupport.vrp.OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest)3 ConsentStatusEntry (com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)2 FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier (com.forgerock.openbanking.aspsp.rs.store.api.openbanking.testsupport.domain.FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier)2 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)2 FRDomesticVRPConsentDetailsData (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetailsData)2 FRWriteDomesticVRPDataInitiation (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRWriteDomesticVRPDataInitiation)2 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)2 ConsentMetricService (com.forgerock.openbanking.analytics.services.ConsentMetricService)1