Search in sources :

Example 6 with FRCallbackUrl

use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl in project openbanking-aspsp by OpenBankingToolkit.

the class CallbackUrlsApiControllerIT method createCallbackUrls_urlDoesNotExistForTpp_created.

@Test
public void createCallbackUrls_urlDoesNotExistForTpp_created() throws Exception {
    // Given
    String url = "http://callback" + UUID.randomUUID().toString();
    // mockAuthentication(authenticator, OBRIRole.ROLE_PISP.name());
    OBCallbackUrl1 obCallbackUrl = new OBCallbackUrl1().data(new OBCallbackUrlData1().url(url).version(OBVersion.v3_0.getCanonicalVersion()));
    // When
    HttpResponse<OBCallbackUrlResponse1> 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(OBCallbackUrlResponse1.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(201);
    assertThat(response.getBody().getData().getCallbackUrlId()).isNotNull();
    assertThat(response.getBody().getData().getUrl()).isEqualTo(url);
    assertThat(response.getBody().getData().getVersion()).isEqualTo(OBVersion.v3_0.getCanonicalVersion());
    final Optional<FRCallbackUrl> byId = callbackUrlsRepository.findById(response.getBody().getData().getCallbackUrlId());
    assertThat(byId.orElseThrow(AssertionError::new).getCallbackUrl().getUrl()).isEqualTo(url);
}
Also used : OBCallbackUrlData1(uk.org.openbanking.datamodel.event.OBCallbackUrlData1) FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl) OBCallbackUrlResponse1(uk.org.openbanking.datamodel.event.OBCallbackUrlResponse1) OBCallbackUrl1(uk.org.openbanking.datamodel.event.OBCallbackUrl1) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with FRCallbackUrl

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_1_2.getCanonicalVersion()));
    // When
    HttpResponse response = Unirest.post("https://rs-store:" + port + "/open-banking/" + OBVersion.v3_1_2.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);
}
Also used : OBCallbackUrlData1(uk.org.openbanking.datamodel.event.OBCallbackUrlData1) HttpResponse(kong.unirest.HttpResponse) FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl) OBCallbackUrl1(uk.org.openbanking.datamodel.event.OBCallbackUrl1) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with FRCallbackUrl

use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl in project openbanking-aspsp by OpenBankingToolkit.

the class CallbackUrlsApiControllerIT method createCallbackUrls_urlDoesNotExistForTpp_created.

@Test
public void createCallbackUrls_urlDoesNotExistForTpp_created() throws Exception {
    // Given
    String url = "http://callback" + UUID.randomUUID().toString();
    // mockAuthentication(authenticator, OBRIRole.ROLE_PISP.name());
    OBCallbackUrl1 obCallbackUrl = new OBCallbackUrl1().data(new OBCallbackUrlData1().url(url).version(OBVersion.v3_1_2.getCanonicalVersion()));
    // When
    HttpResponse<OBCallbackUrlResponse1> response = Unirest.post("https://rs-store:" + port + "/open-banking/" + OBVersion.v3_1_2.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(OBCallbackUrlResponse1.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(201);
    assertThat(response.getBody().getData().getCallbackUrlId()).isNotNull();
    assertThat(response.getBody().getData().getUrl()).isEqualTo(url);
    assertThat(response.getBody().getData().getVersion()).isEqualTo(OBVersion.v3_1_2.getCanonicalVersion());
    final Optional<FRCallbackUrl> byId = callbackUrlsRepository.findById(response.getBody().getData().getCallbackUrlId());
    assertThat(byId.orElseThrow(AssertionError::new).getCallbackUrl().getUrl()).isEqualTo(url);
}
Also used : OBCallbackUrlData1(uk.org.openbanking.datamodel.event.OBCallbackUrlData1) FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl) OBCallbackUrlResponse1(uk.org.openbanking.datamodel.event.OBCallbackUrlResponse1) OBCallbackUrl1(uk.org.openbanking.datamodel.event.OBCallbackUrl1) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with FRCallbackUrl

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();
    FRCallbackUrl frCallbackUrl1 = FRCallbackUrl.builder().id(callbackId).callbackUrl(FRCallbackUrlData.builder().url("http://callback-update").version(OBVersion.v3_1_2.getCanonicalVersion()).build()).build();
    callbackUrlsRepository.save(frCallbackUrl1);
    OBCallbackUrl1 obCallbackUrl = new OBCallbackUrl1().data(new OBCallbackUrlData1().url("http://callback-" + callbackId + "-update").version(OBVersion.v3_1_3.getCanonicalVersion()));
    // When
    HttpResponse<OBCallbackUrlResponse1> response = Unirest.put("https://rs-store:" + port + "/open-banking/" + OBVersion.v3_1_2.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_1_3.getCanonicalVersion());
    final Optional<FRCallbackUrl> byId = callbackUrlsRepository.findById(callbackId);
    assertThat(byId.orElseThrow(AssertionError::new).getCallbackUrl().getUrl()).isEqualTo("http://callback-" + callbackId + "-update");
}
Also used : OBCallbackUrlData1(uk.org.openbanking.datamodel.event.OBCallbackUrlData1) FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl) OBCallbackUrlResponse1(uk.org.openbanking.datamodel.event.OBCallbackUrlResponse1) OBCallbackUrl1(uk.org.openbanking.datamodel.event.OBCallbackUrl1) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with FRCallbackUrl

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 = "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));
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl)

Aggregations

FRCallbackUrl (com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl)13 Test (org.junit.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 OBCallbackUrl1 (uk.org.openbanking.datamodel.event.OBCallbackUrl1)6 OBCallbackUrlData1 (uk.org.openbanking.datamodel.event.OBCallbackUrlData1)6 HttpResponse (kong.unirest.HttpResponse)4 OBCallbackUrlResponse1 (uk.org.openbanking.datamodel.event.OBCallbackUrlResponse1)4 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)2 Tpp (com.forgerock.openbanking.model.Tpp)2 URI (java.net.URI)1 Collection (java.util.Collection)1 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1