use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalStandingOrderConsentsApiController method createInternationalStandingOrderConsents.
@Override
public ResponseEntity<OBWriteInternationalStandingOrderConsentResponse1> createInternationalStandingOrderConsents(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteInternationalStandingOrderConsent1 obWriteInternationalStandingOrderConsent1, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "Every request will be processed only once per x-idempotency-key. The Idempotency Key will be valid for 24 hours.", required = true) @RequestHeader(value = "x-idempotency-key", required = true) String xIdempotencyKey, @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 = "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-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @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, @ApiParam(value = "The PISP ID") @RequestHeader(value = "x-ob-client-id", required = false) String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("Received: '{}'", obWriteInternationalStandingOrderConsent1);
FRWriteInternationalStandingOrderConsent frInternationalStandingOrderConsent = toFRWriteInternationalStandingOrderConsent(obWriteInternationalStandingOrderConsent1);
log.trace("Converted to: '{}'", frInternationalStandingOrderConsent);
final Tpp tpp = tppRepository.findByClientId(clientId);
log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
Optional<FRInternationalStandingOrderConsent> consentByIdempotencyKey = internationalStandingOrderConsentRepository.findByIdempotencyKeyAndPispId(xIdempotencyKey, tpp.getId());
if (consentByIdempotencyKey.isPresent()) {
validateIdempotencyRequest(xIdempotencyKey, frInternationalStandingOrderConsent, consentByIdempotencyKey.get(), () -> consentByIdempotencyKey.get().getInternationalStandingOrderConsent());
log.info("Idempotent request is valid. Returning [201 CREATED] but take no further action.");
return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(consentByIdempotencyKey.get()));
}
log.debug("No consent with matching idempotency key has been found. Creating new consent.");
FRInternationalStandingOrderConsent internationalStandingOrderConsent = FRInternationalStandingOrderConsent.builder().id(IntentType.PAYMENT_INTERNATIONAL_STANDING_ORDERS_CONSENT.generateIntentId()).status(ConsentStatusCode.AWAITINGAUTHORISATION).internationalStandingOrderConsent(frInternationalStandingOrderConsent).pispId(tpp.getId()).pispName(tpp.getOfficialName()).statusUpdate(DateTime.now()).created(DateTime.now()).idempotencyKey(xIdempotencyKey).version(VersionPathExtractor.getVersionFromPath(request)).build();
log.debug("Saving consent: '{}'", internationalStandingOrderConsent);
consentMetricService.sendConsentActivity(new ConsentStatusEntry(internationalStandingOrderConsent.getId(), internationalStandingOrderConsent.getStatus().name()));
internationalStandingOrderConsent = internationalStandingOrderConsentRepository.save(internationalStandingOrderConsent);
log.info("Created consent id: '{}'", internationalStandingOrderConsent.getId());
return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(internationalStandingOrderConsent));
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticPaymentConsentsApiController method createDomesticPaymentConsents.
@Override
public ResponseEntity<OBWriteDomesticConsentResponse2> createDomesticPaymentConsents(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteDomesticConsent2 obWriteDomesticConsent2, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "Every request will be processed only once per x-idempotency-key. The Idempotency Key will be valid for 24 hours.", required = true) @RequestHeader(value = "x-idempotency-key", required = true) String xIdempotencyKey, @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 = "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-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @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, @ApiParam(value = "The PISP ID") @RequestHeader(value = "x-ob-client-id", required = false) String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("Received: '{}'", obWriteDomesticConsent2);
FRWriteDomesticConsent frWriteDomesticConsent = toFRWriteDomesticConsent(obWriteDomesticConsent2);
log.trace("Converted to: '{}'", frWriteDomesticConsent);
final Tpp tpp = tppRepository.findByClientId(clientId);
log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
Optional<FRDomesticConsent> consentByIdempotencyKey = domesticConsentRepository.findByIdempotencyKeyAndPispId(xIdempotencyKey, tpp.getId());
if (consentByIdempotencyKey.isPresent()) {
validateIdempotencyRequest(xIdempotencyKey, frWriteDomesticConsent, consentByIdempotencyKey.get(), () -> consentByIdempotencyKey.get().getDomesticConsent());
log.info("Idempotent request is valid. Returning [201 CREATED] but take no further action.");
return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(consentByIdempotencyKey.get()));
}
log.debug("No consent with matching idempotency key has been found. Creating new consent.");
FRDomesticConsent domesticConsent = FRDomesticConsent.builder().id(IntentType.PAYMENT_DOMESTIC_CONSENT.generateIntentId()).status(ConsentStatusCode.AWAITINGAUTHORISATION).domesticConsent(frWriteDomesticConsent).pispId(tpp.getId()).pispName(tpp.getOfficialName()).statusUpdate(DateTime.now()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
log.debug("Saving consent: '{}'", domesticConsent);
consentMetricService.sendConsentActivity(new ConsentStatusEntry(domesticConsent.getId(), domesticConsent.getStatus().name()));
domesticConsent = domesticConsentRepository.save(domesticConsent);
log.info("Created consent id: '{}'", domesticConsent.getId());
return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(domesticConsent));
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class FilePaymentConsentsApiController method createFilePaymentConsents.
@Override
public ResponseEntity<OBWriteFileConsentResponse1> createFilePaymentConsents(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteFileConsent1 obWriteFileConsent1, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "Every request will be processed only once per x-idempotency-key. The Idempotency Key will be valid for 24 hours.", required = true) @RequestHeader(value = "x-idempotency-key", required = true) String xIdempotencyKey, @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 = "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-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @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, @ApiParam(value = "The PISP Client ID") @RequestHeader(value = "x-ob-client-id", required = true) String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("Received: '{}'", obWriteFileConsent1);
FRWriteFileConsent frWriteFileConsent = toFRWriteFileConsent(obWriteFileConsent1);
log.trace("Converted to: '{}'", frWriteFileConsent);
final Tpp tpp = Optional.ofNullable(tppRepository.findByClientId(clientId)).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, "TPP not found for client id", Collections.singletonList(OBRIErrorType.REQUEST_INVALID_HEADER.toOBError1("x-ob-client-id"))));
log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
Optional<FRFileConsent> consentByIdempotencyKey = fileConsentRepository.findByIdempotencyKeyAndPispId(xIdempotencyKey, tpp.getId());
if (consentByIdempotencyKey.isPresent()) {
validateIdempotencyRequest(xIdempotencyKey, frWriteFileConsent, consentByIdempotencyKey.get(), () -> consentByIdempotencyKey.get().getWriteFileConsent());
log.info("Idempotent request is valid. Returning [201 CREATED] but take no further action.");
return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(consentByIdempotencyKey.get()));
}
log.debug("No consent with matching idempotency key has been found. Creating new consent.");
FRFileConsent fileConsent = FRFileConsent.builder().id(IntentType.PAYMENT_FILE_CONSENT.generateIntentId()).status(ConsentStatusCode.AWAITINGUPLOAD).writeFileConsent(frWriteFileConsent).pispId(tpp.getId()).pispName(tpp.getOfficialName()).created(DateTime.now()).statusUpdate(DateTime.now()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
log.debug("Saving consent: '{}'", fileConsent);
consentMetricService.sendConsentActivity(new ConsentStatusEntry(fileConsent.getId(), fileConsent.getStatus().name()));
fileConsent = fileConsentRepository.save(fileConsent);
log.info("Created consent id: '{}'", fileConsent.getId());
return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(fileConsent));
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticVrpsApiControllerIT method createVrpPayment.
@Test
public void createVrpPayment() throws Exception {
// Given
String jws = jws("payments", OIDCConstants.GrantType.AUTHORIZATION_CODE);
springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
given(amResourceServerService.verifyAccessToken("Bearer " + jws)).willReturn(SignedJWT.parse(jws));
FRDomesticVRPConsent frDomesticVRPConsent = aValidFRDomesticVRPConsent(IntentType.DOMESTIC_VRP_PAYMENT_CONSENT.generateIntentId(), ConsentStatusCode.AUTHORISED);
OBDomesticVRPConsentResponse consentResponse = FRDomesticVRPConsentConverter.toOBDomesticVRPConsentResponse(frDomesticVRPConsent);
OBDomesticVRPRequest request = buildAValidOBDomesticVRPRequest(consentResponse);
OBDomesticVRPResponse rsStoreResponse = aValidOBDomesticVRPResponse(request);
given(rsStoreGateway.toRsStore(any(), any(), any(), any(), any())).willReturn(ResponseEntity.status(HttpStatus.CREATED).body(rsStoreResponse));
Tpp tpp = new Tpp();
tpp.setAuthorisationNumber("test-tpp");
given(tppStoreService.findByClientId(any())).willReturn(Optional.of(tpp));
given(vrpPaymentConsentService.getVrpPaymentConsent(request.getData().getConsentId())).willReturn(frDomesticVRPConsent);
// When
HttpResponse<OBDomesticVRPResponse> response = Unirest.post(HOST + port + VRP_CONTXT_PATH).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.X_IDEMPOTENCY_KEY, IDEMPOTENCY_KEY).header(OBHeaders.X_JWS_SIGNATURE, jws).header(OBHeaders.AUTHORIZATION, "Bearer " + jws).header(OBHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()).body(request).asObject(OBDomesticVRPResponse.class);
// Then
assertThat(response.getStatus()).isEqualTo(HttpStatus.CREATED.value());
assertThat(response.getBody()).isEqualTo(rsStoreResponse);
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class CallbackUrlApiControllerIT method getCallbackUrls.
@Test
public void getCallbackUrls() throws Exception {
// Given
String jws = jws(OpenBankingConstants.Scope.ACCOUNTS, OIDCConstants.GrantType.CLIENT_CREDENTIAL);
springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_AISP);
mockAccessTokenVerification(jws);
OBCallbackUrlsResponse1 obCallbackUrlsResponse = new OBCallbackUrlsResponse1();
obCallbackUrlsResponse.data(new OBCallbackUrlsResponseData1().callbackUrl(Collections.singletonList(new OBCallbackUrlResponseData1().callbackUrlId("123").url("https://localhost").version(OBVersion.v3_0.getCanonicalVersion()))));
given(rsStoreGateway.toRsStore(any(), any(), any())).willReturn(ResponseEntity.ok(obCallbackUrlsResponse));
Tpp tpp = new Tpp();
tpp.setAuthorisationNumber("test-tpp");
given(tppStoreService.findByClientId(any())).willReturn(Optional.of(tpp));
// When
HttpResponse<OBCallbackUrlsResponse1> response = Unirest.get("https://rs-api:" + port + "/open-banking/v3.0/callback-urls").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "Bearer " + jws).asObject(OBCallbackUrlsResponse1.class);
// Then
assertThat(response.getStatus()).isEqualTo(200);
}
Aggregations