use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl in project openbanking-aspsp by OpenBankingToolkit.
the class CallbackUrlsService method findByTppId.
public Collection<FRCallbackUrl> findByTppId(String tppId) {
log.debug("Read all the callback URLs");
ParameterizedTypeReference<Collection<FRCallbackUrl>> ptr = new ParameterizedTypeReference<Collection<FRCallbackUrl>>() {
};
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rsStoreRoot + BASE_RESOURCE_PATH + "search/findByTppId");
builder.queryParam("tppId", tppId);
URI uri = builder.build().encode().toUri();
ResponseEntity<Collection<FRCallbackUrl>> entity = restTemplate.exchange(uri, HttpMethod.GET, null, ptr);
return entity.getBody();
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl 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 = "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 callback URL: {} for client: {}", obCallbackUrl1Param, clientId);
// https://openbanking.atlassian.net/wiki/spaces/DZ/pages/645367055/Event+Notification+API+Specification+-+v3.0#EventNotificationAPISpecification-v3.0-POST/callback-urls
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 callback URL already exists for TPP
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);
throw new OBErrorResponseException(HttpStatus.CONFLICT, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.CALLBACK_URL_ALREADY_EXISTS.toOBError1(obCallbackUrl1Param.getData().getUrl()));
}
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.common.model.openbanking.persistence.event.FRCallbackUrl in project openbanking-aspsp by OpenBankingToolkit.
the class CallbackUrlsApiController method updateCallbackUrl.
@Override
public ResponseEntity updateCallbackUrl(@ApiParam(value = "CallbackUrlId", required = true) @PathVariable("CallbackUrlId") String callbackUrlId, @ApiParam(value = "Default", required = true) @Valid @RequestBody OBCallbackUrl1 obCallbackUrl1Param, @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 = false) String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
final Optional<FRCallbackUrl> byId = callbackUrlsRepository.findById(callbackUrlId);
if (byId.isPresent()) {
FRCallbackUrl frCallbackUrl = byId.get();
if (eventResponseUtil.isAccessToResourceAllowedFromApiVersion(frCallbackUrl.getCallbackUrl().getVersion())) {
frCallbackUrl.setCallbackUrl(toFRCallbackUrlData(obCallbackUrl1Param));
callbackUrlsRepository.save(frCallbackUrl);
return ResponseEntity.ok(eventResponseUtil.packageResponse(frCallbackUrl));
} else {
return ResponseEntity.status(HttpStatus.CONFLICT).body("Callback URL: '" + callbackUrlId + "' can't be update via an older API version.");
}
} else {
// Option 2 is more restful but the examples in spec only use PUT for amending urls so currently I am implementing option 1.
throw new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.CALLBACK_URL_NOT_FOUND.toOBError1(callbackUrlId));
}
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl in project openbanking-aspsp by OpenBankingToolkit.
the class CallbackUrlsApiControllerIT method createCallbackUrls_urlAlreadyExistsForTpp_conflict.
@Test
public void createCallbackUrls_urlAlreadyExistsForTpp_conflict() throws Exception {
// Given
// mockAuthentication(authenticator, OBRIRole.ROLE_PISP.name());
String callbackId = UUID.randomUUID().toString();
// Existing URL
callbackUrlsRepository.save(newFRCallbackUrl(callbackId));
OBCallbackUrl1 obCallbackUrl = new OBCallbackUrl1().data(new OBCallbackUrlData1().url(// Already exists
"http://callback-" + callbackId).version(OBVersion.v3_0.getCanonicalVersion()));
// When
HttpResponse response = Unirest.post("https://rs-store:" + port + "/open-banking/" + OBVersion.v3_0.getCanonicalName() + "/callback-urls").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-client-id", clientId).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(obCallbackUrl).asObject(String.class);
// Then
assertThat(response.getStatus()).isEqualTo(HttpStatus.CONFLICT.value());
final Collection<FRCallbackUrl> byClientId = callbackUrlsRepository.findByTppId(tpp.getId());
// Should still be just 1
assertThat(byClientId.size()).isEqualTo(1);
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl in project openbanking-aspsp by OpenBankingToolkit.
the class CallbackUrlsApiControllerIT method updateCallbackUrl_exists_updated.
@Test
public void updateCallbackUrl_exists_updated() throws Exception {
// Given
// mockAuthentication(authenticator, OBRIRole.ROLE_AISP.name());
String callbackId = UUID.randomUUID().toString();
OBCallbackUrl1 obCallbackUrl = new OBCallbackUrl1().data(new OBCallbackUrlData1().url("http://callback-" + callbackId + "-update").version(OBVersion.v3_0.getCanonicalVersion()));
FRCallbackUrl frCallbackUrl = FRCallbackUrl.builder().id(callbackId).callbackUrl(FRCallbackUrlData.builder().url("http://callback-update").version(OBVersion.v3_0.getCanonicalVersion()).build()).build();
callbackUrlsRepository.save(frCallbackUrl);
// When
HttpResponse<OBCallbackUrlResponse1> response = Unirest.put("https://rs-store:" + port + "/open-banking/" + OBVersion.v3_0.getCanonicalName() + "/callback-urls/" + callbackId).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-client-id", clientId).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(obCallbackUrl).asObject(OBCallbackUrlResponse1.class);
// Then
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getBody().getData().getCallbackUrlId()).isNotNull();
assertThat(response.getBody().getData().getUrl()).isEqualTo("http://callback-" + callbackId + "-update");
assertThat(response.getBody().getData().getVersion()).isEqualTo(OBVersion.v3_0.getCanonicalVersion());
final Optional<FRCallbackUrl> byId = callbackUrlsRepository.findById(callbackId);
assertThat(byId.orElseThrow(AssertionError::new).getCallbackUrl().getUrl()).isEqualTo("http://callback-" + callbackId + "-update");
}
Aggregations