use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class CallbackUrlsApiController method createCallbackUrls.
@Override
public ResponseEntity createCallbackUrls(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBCallbackUrl1 obCallbackUrl1Param, @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 = "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, @ApiParam(value = "The PISP Client ID") @RequestHeader(value = "x-ob-client-id", required = true) String clientId, HttpServletRequest request, Principal principal) {
log.debug("Create new callback URL: {} for client: {}", obCallbackUrl1Param, clientId);
// Check if callback URL already exists for TPP
// https://openbanking.atlassian.net/wiki/spaces/DZ/pages/645367055/Event+Notification+API+Specification+-+v3.0#EventNotificationAPISpecification-v3.0-POST/callback-urls
// A TPP must only create a callback-url on one version
final Optional<Tpp> isTpp = Optional.ofNullable(tppRepository.findByClientId(clientId));
if (!isTpp.isPresent()) {
log.warn("No TPP found for client id '{}'", clientId);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("TPP not found");
}
final Collection<FRCallbackUrl> byClientId = callbackUrlsRepository.findByTppId(isTpp.get().getId());
final boolean urlExists = byClientId.stream().anyMatch(existingCallbackUrl -> obCallbackUrl1Param.getData().getUrl().equals(existingCallbackUrl.getCallbackUrl().getUrl()));
if (urlExists) {
log.debug("This callback URL: '{}' already exists for this TPP client id: '{}'", obCallbackUrl1Param.getData().getUrl(), clientId);
return ResponseEntity.status(HttpStatus.CONFLICT).body("Callback URL already exists");
}
FRCallbackUrl frCallbackUrl = FRCallbackUrl.builder().id(UUID.randomUUID().toString()).tppId(isTpp.get().getId()).callbackUrl(toFRCallbackUrlData(obCallbackUrl1Param)).build();
callbackUrlsRepository.save(frCallbackUrl);
return ResponseEntity.status(HttpStatus.CREATED).body(eventResponseUtil.packageResponse(frCallbackUrl));
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class EventSubscriptionApiController method createEventSubscription.
public ResponseEntity createEventSubscription(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBEventSubscription1 obEventSubscription, @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, @ApiParam(value = "The PISP Client ID") @RequestHeader(value = "x-ob-client-id", required = true) String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("Create new event subscriptions: {} for client: {}", obEventSubscription, clientId);
// Get the TPP from the header
final Optional<Tpp> isTpp = Optional.ofNullable(tppRepository.findByClientId(clientId));
if (isTpp.isEmpty()) {
log.warn("No TPP found for client id '{}'", clientId);
throw new OBErrorResponseException(HttpStatus.NOT_FOUND, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.TPP_NOT_FOUND.toOBError1(clientId));
}
// Check if an event already exists for this TPP
final Collection<FREventSubscription> byClientId = eventSubscriptionsRepository.findByTppId(isTpp.get().getId());
if (!byClientId.isEmpty()) {
log.debug("An event subscription already exists for this TPP client id: '{}' for the version: {}", clientId, byClientId.stream().findFirst().get());
throw new OBErrorResponseException(HttpStatus.CONFLICT, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.EVENT_SUBSCRIPTION_ALREADY_EXISTS.toOBError1());
}
// Persist the event subscription
FREventSubscription frEventSubscription = FREventSubscription.builder().id(UUID.randomUUID().toString()).tppId(isTpp.get().getId()).eventSubscription(toFREventSubscriptionData(obEventSubscription)).build();
eventSubscriptionsRepository.save(frEventSubscription);
return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(frEventSubscription));
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class CallbackUrlsApiControllerIT method setUp.
@Before
public void setUp() {
tpp = new Tpp();
tpp.setId(UUID.randomUUID().toString());
given(tppRepository.findByClientId(any())).willReturn(tpp);
clientId = UUID.randomUUID().toString();
Unirest.config().setObjectMapper(new JacksonObjectMapper(objectMapper)).verifySsl(false);
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class EventSubscriptionApiControllerIT method setUp.
@Before
public void setUp() {
tpp = new Tpp();
tpp.setId(UUID.randomUUID().toString());
given(tppRepository.findByClientId(any())).willReturn(tpp);
clientId = UUID.randomUUID().toString();
Unirest.config().setObjectMapper(new JacksonObjectMapper(objectMapper)).verifySsl(false);
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class AggregatedPollingApiControllerIT method setUp.
@Before
public void setUp() {
tpp = new Tpp();
tpp.setId(UUID.randomUUID().toString());
given(tppRepository.findByClientId(any())).willReturn(tpp);
clientId = UUID.randomUUID().toString();
Unirest.config().setObjectMapper(new JacksonObjectMapper(objectMapper)).verifySsl(false);
springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
}
Aggregations