Search in sources :

Example 71 with Tpp

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

Example 72 with Tpp

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

Example 73 with Tpp

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);
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) JacksonObjectMapper(kong.unirest.JacksonObjectMapper) Before(org.junit.Before)

Example 74 with Tpp

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);
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) JacksonObjectMapper(kong.unirest.JacksonObjectMapper) Before(org.junit.Before)

Example 75 with Tpp

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);
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) JacksonObjectMapper(kong.unirest.JacksonObjectMapper) Before(org.junit.Before)

Aggregations

Tpp (com.forgerock.openbanking.model.Tpp)131 ConsentStatusEntry (com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)39 Test (org.junit.Test)28 OIDCRegistrationResponse (com.forgerock.openbanking.model.oidc.OIDCRegistrationResponse)19 Before (org.junit.Before)13 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 JacksonObjectMapper (kong.unirest.JacksonObjectMapper)11 OAuth2InvalidClientException (com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException)9 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)9 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)9 AccountWithBalance (com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)8 URI (java.net.URI)8 FRInternationalStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)7 FRWriteInternationalStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderConsent)6 FRDomesticConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)6 FRDomesticScheduledConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticScheduledConsent)6 FRDomesticStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderConsent)6