Search in sources :

Example 11 with 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 = "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 = false) String clientId, HttpServletRequest request, Principal principal) {
    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 I am implementing option 1.
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Callback URL: '" + callbackUrlId + "' can't be found");
    }
}
Also used : FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl)

Example 12 with FRCallbackUrl

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

the class CallbackUrlsApiControllerIT method deleteCallbackUrl_exists_deleted.

@Test
public void deleteCallbackUrl_exists_deleted() throws Exception {
    // Given
    // mockAuthentication(authenticator, OBRIRole.ROLE_PISP.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);
    // When
    HttpResponse response = Unirest.delete("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").asObject(String.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(204);
    final Optional<FRCallbackUrl> byId = callbackUrlsRepository.findById(callbackId);
    assertThat(byId.isPresent()).isFalse();
}
Also used : HttpResponse(kong.unirest.HttpResponse) FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with FRCallbackUrl

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

the class CallbackUrlsApiControllerIT method deleteCallbackUrl_exists_deleted.

@Test
public void deleteCallbackUrl_exists_deleted() throws Exception {
    // Given
    // mockAuthentication(authenticator, OBRIRole.ROLE_PISP.name());
    String callbackId = UUID.randomUUID().toString();
    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 response = Unirest.delete("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").asObject(String.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(204);
    final Optional<FRCallbackUrl> byId = callbackUrlsRepository.findById(callbackId);
    assertThat(byId.isPresent()).isFalse();
}
Also used : HttpResponse(kong.unirest.HttpResponse) FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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