use of com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry in project openbanking-aspsp by OpenBankingToolkit.
the class FilePaymentConsentsApiController method createFilePaymentConsents.
public ResponseEntity<OBWriteFileConsentResponse3> createFilePaymentConsents(OBWriteFileConsent3 obWriteFileConsent3, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("Received: '{}'", obWriteFileConsent3);
FRWriteFileConsent frWriteFileConsent = toFRWriteFileConsent(obWriteFileConsent3);
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()).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.analytics.model.entries.ConsentStatusEntry in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalPaymentConsentsApiController method createInternationalPaymentConsents.
public ResponseEntity<OBWriteInternationalConsentResponse4> createInternationalPaymentConsents(OBWriteInternationalConsent4 obWriteInternationalConsent4, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("Received: '{}'", obWriteInternationalConsent4);
FRWriteInternationalConsent frWriteInternationalConsent = toFRWriteInternationalConsent(obWriteInternationalConsent4);
log.trace("Converted to: '{}'", frWriteInternationalConsent);
final Tpp tpp = tppRepository.findByClientId(clientId);
log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
Optional<FRInternationalConsent> consentByIdempotencyKey = internationalConsentRepository.findByIdempotencyKeyAndPispId(xIdempotencyKey, tpp.getId());
if (consentByIdempotencyKey.isPresent()) {
validateIdempotencyRequest(xIdempotencyKey, frWriteInternationalConsent, consentByIdempotencyKey.get(), () -> consentByIdempotencyKey.get().getInternationalConsent());
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.");
log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
FRInternationalConsent internationalConsent = FRInternationalConsent.builder().id(IntentType.PAYMENT_INTERNATIONAL_CONSENT.generateIntentId()).status(ConsentStatusCode.AWAITINGAUTHORISATION).internationalConsent(frWriteInternationalConsent).pispId(tpp.getId()).pispName(tpp.getOfficialName()).statusUpdate(DateTime.now()).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
log.debug("Saving consent: '{}'", internationalConsent);
consentMetricService.sendConsentActivity(new ConsentStatusEntry(internationalConsent.getId(), internationalConsent.getStatus().name()));
internationalConsent = internationalConsentRepository.save(internationalConsent);
log.info("Created consent id: '{}'", internationalConsent.getId());
return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(internationalConsent));
}
use of com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry in project openbanking-aspsp by OpenBankingToolkit.
the class AccountAccessConsentApiController method deleteAccountConsent.
@Override
public ResponseEntity deleteAccountConsent(@ApiParam(value = "Unique identification as assigned by the ASPSP to uniquely identify the account request resource.", required = true) @PathVariable("ConsentId") String consentId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @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 = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent) throws OBErrorResponseException {
Optional<FRAccountAccessConsent> accountAccessConsent = frAccountAccessConsentRepository.findByConsentId(consentId);
if (!accountAccessConsent.isPresent()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Account access consent '" + consentId + "' not found");
}
log.debug("Account access consent revoked with id {}", consentId);
FRAccountAccessConsent frAccountAccessConsent = accountAccessConsent.get();
frAccountAccessConsent.getAccountAccessConsent().getData().setStatus(FRExternalRequestStatusCode.REVOKED);
consentMetricService.sendConsentActivity(new ConsentStatusEntry(frAccountAccessConsent.getAccountAccessConsent().getData().getConsentId(), frAccountAccessConsent.getAccountAccessConsent().getData().getStatus().name()));
frAccountAccessConsentRepository.save(frAccountAccessConsent);
log.debug("Account access consent revoked");
return ResponseEntity.ok("Account access consent '" + consentId + "' deleted");
}
use of com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry in project openbanking-aspsp by OpenBankingToolkit.
the class AccountRequestsApiController method deleteAccountRequest.
@Override
public ResponseEntity deleteAccountRequest(@ApiParam(value = "Unique identification as assigned by the ASPSP to uniquely identify the account request resource.", required = true) @PathVariable("AccountRequestId") String accountRequestId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @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 = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent) throws OBErrorResponseException {
Optional<FRAccountRequest> accountRequest = frAccountRequestRepository.findByAccountRequestId(accountRequestId);
if (!accountRequest.isPresent()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Account request '" + accountRequestId + "' not found");
}
LOGGER.debug("Account request revoked with id {}", accountRequestId);
FRAccountRequest frAccountRequest = accountRequest.get();
frAccountRequest.getAccountRequest().getData().setStatus(FRExternalRequestStatusCode.REVOKED);
consentMetricService.sendConsentActivity(new ConsentStatusEntry(frAccountRequest.getAccountRequest().getData().getAccountRequestId(), frAccountRequest.getAccountRequest().getData().getStatus().name()));
frAccountRequestRepository.save(frAccountRequest);
LOGGER.debug("Account request revoked");
return ResponseEntity.ok("Account request '" + accountRequestId + "' deleted");
}
Aggregations