use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalStandingOrderConsentsApiController method createInternationalStandingOrderConsents.
public ResponseEntity<OBWriteInternationalStandingOrderConsentResponse5> createInternationalStandingOrderConsents(OBWriteInternationalStandingOrderConsent5 obWriteInternationalStandingOrderConsent5, 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: '{}'", obWriteInternationalStandingOrderConsent5);
FRWriteInternationalStandingOrderConsent frStandingOrderConsent = toFRWriteInternationalStandingOrderConsent(obWriteInternationalStandingOrderConsent5);
log.trace("Converted to: '{}'", frStandingOrderConsent);
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, frStandingOrderConsent, 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(frStandingOrderConsent).pispId(tpp.getId()).pispName(tpp.getOfficialName()).statusUpdate(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<OBWriteDomesticConsentResponse4> createDomesticPaymentConsents(OBWriteDomesticConsent4 obWriteDomesticConsent4, 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: '{}'", obWriteDomesticConsent4);
FRWriteDomesticConsent frWriteDomesticConsent = toFRWriteDomesticConsent(obWriteDomesticConsent4);
log.trace("Converted to: '{}'", frWriteDomesticConsent);
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(responseEntity(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(responseEntity(domesticConsent));
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class TppRegistrationService method updateTpp.
public Tpp updateTpp(ApiClientIdentity clientIdentity, Tpp tpp, String token, RegistrationRequest oidcRegistrationRequest) throws DynamicClientRegistrationException {
log.debug("updateTpp() Updating tpp '{}'", tpp.getClientId());
log.debug("updateTpp() Sending the OAuth2 dynamic registration request to AM");
OIDCRegistrationResponse oidcRegistrationResponse = amoidcRegistrationService.updateOIDCClient(token, oidcRegistrationRequest, tpp.getClientId());
log.debug("updateTpp() Response from AM: {}", oidcRegistrationResponse);
String ssaIssuer = oidcRegistrationRequest.getSsaIssuer();
String directoryId = this.getDirectoryIdFromSsaIssuer(ssaIssuer);
removeSecretIfNeeded(oidcRegistrationResponse);
String officialName = getOrgSoftwareCombinedTppName(oidcRegistrationRequest, oidcRegistrationResponse);
Tpp updatedTpp = Tpp.builder().created(tpp.getCreated()).id(tpp.getId()).certificateCn(tpp.getCertificateCn()).name(oidcRegistrationResponse.getClientName()).officialName(officialName).clientId(oidcRegistrationResponse.getClientId()).types(oidcRegistrationRequest.getSoftwareStatementRoles()).softwareId(oidcRegistrationRequest.getDirectorySoftwareStatement().getSoftware_id()).authorisationNumber(clientIdentity.getAuthorisationNumber().orElse(null)).directorySoftwareStatement(oidcRegistrationRequest.getDirectorySoftwareStatement()).tppRequest(oidcRegistrationRequest.toJson()).registrationResponse(oidcRegistrationResponse).directoryId(directoryId).build();
updateTppMetrics(tpp, false);
return tppStoreService.save(updatedTpp);
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class TppRegistrationService method getTpp.
/**
* getTpp returns the tpp associated with the principal. If not tpp can be found will throw.
* @param clientId the principal as obtained from the client MATLS certificate used to make the request
* @return a Tpp object belonging to the principal. If no tpp can be found then will throw
* OAuth2InvalidClientException
* @throws OAuth2InvalidClientException
*/
@NotNull
public Tpp getTpp(@NotNull String clientId) throws OAuth2InvalidClientException {
Optional<Tpp> optionalTpp = tppStoreService.findByClientId(clientId);
if (optionalTpp.isEmpty()) {
String errorMessage = "No registration exists for the clientId in the request path. clientId was '" + clientId + "'";
log.info("getTpp() {}", errorMessage);
throw new OAuth2InvalidClientException(errorMessage);
}
Tpp tpp = optionalTpp.get();
log.debug("getTpp(): Tpp is {}", tpp);
return tpp;
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class ManualRegistrationApiController method ensurePrincipalOwnsTppRegistrations.
private void ensurePrincipalOwnsTppRegistrations(Collection<ManualRegistrationApplication> applications, Principal principal) throws OAuth2InvalidClientException {
log.debug("ensurePrincipalOwnsTppRegistrations() checking that '{}' applications are owned by '{}'", applications.size(), principal.getName());
for (ManualRegistrationApplication application : applications) {
OIDCRegistrationResponse regResponse = application.getOidcRegistrationResponse();
if (regResponse == null) {
String errorString = "Failed to determine if MATLS client cert belongs to the TPP that owns the " + "application with id ";
log.info("principalOwnsTppRegistration() {}'{}'", errorString, application.getId());
throw new OAuth2InvalidClientException(errorString + application.getId() + "'");
}
String oauth2ClientId = regResponse.getClientId();
Tpp tpp = tppRegistrationService.getTpp(oauth2ClientId);
tppRegistrationService.ensureTppOwnsOidcRegistration(tpp, principal.getName());
}
log.debug("ensurePrincipalOwnsTppRegistrations() all application's OAuth2 clients owned by '{}'", principal.getName());
}
Aggregations