Search in sources :

Example 1 with ManualRegistrationRequest

use of com.forgerock.openbanking.common.model.onboarding.ManualRegistrationRequest in project openbanking-aspsp by OpenBankingToolkit.

the class ManualOnboardingService method registerApplication.

public OIDCRegistrationResponse registerApplication(JwtAuthentication authentication, String aspspManualOnboardingEndpoint, ManualRegistrationRequest manualRegistrationRequest) {
    log.debug("registerApplication() called. aspspManualOnboardingEndpoint is '{}'", aspspManualOnboardingEndpoint);
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("userId", ((UserDetails) authentication.getPrincipal()).getUsername());
    try {
        String directoryID = authentication.getJwtClaimsSet().getStringClaim("directoryID");
        httpHeaders.set("directoryID", directoryID);
        if (directoryID == "EIDAS") {
            manualRegistrationRequest.setAppId(authentication.getJwtClaimsSet().getStringClaim("app_id"));
            manualRegistrationRequest.setOrganisationId(authentication.getJwtClaimsSet().getStringClaim("org_id"));
            manualRegistrationRequest.setPsd2Roles(authentication.getJwtClaimsSet().getStringClaim("psd2_roles"));
        }
    } catch (ParseException e) {
        log.error("Couldn't read claims from user context", e);
    }
    HttpEntity<ManualRegistrationRequest> request = new HttpEntity<>(manualRegistrationRequest, httpHeaders);
    return restTemplate.exchange(aspspManualOnboardingEndpoint, HttpMethod.POST, request, OIDCRegistrationResponse.class).getBody();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ManualRegistrationRequest(com.forgerock.openbanking.common.model.onboarding.ManualRegistrationRequest) HttpEntity(org.springframework.http.HttpEntity) OIDCRegistrationResponse(com.forgerock.openbanking.model.oidc.OIDCRegistrationResponse) ParseException(java.text.ParseException)

Example 2 with ManualRegistrationRequest

use of com.forgerock.openbanking.common.model.onboarding.ManualRegistrationRequest in project openbanking-aspsp by OpenBankingToolkit.

the class ManualRegistrationApiController method registerApplication.

@Override
public ResponseEntity<ManualRegistrationApplication> registerApplication(@ApiParam(value = "Registration request", required = true) @Valid @RequestBody ManualRegistrationRequest manualRegistrationRequest, @CookieValue(value = "obri-session", required = true) String obriSession, Principal principal) throws OAuth2InvalidClientException {
    log.debug("registerApplication called. manualRegistrationRequest is '{}'", manualRegistrationRequest);
    ApiClientIdentity apiClientIdentity = null;
    try {
        String userNameOfSessionHolder = this.getUserNameFromSession(obriSession);
        apiClientIdentity = identityFactory.getApiClientIdentity(principal);
        log.debug("ApiClientIdentity is '{}'", apiClientIdentity);
        // Prepare the request
        String registrationRequestDefaultJsonClaims = getRegistrationRequestDefaultJsonClaims();
        RegistrationRequest registrationRequest = registrationRequestFactory.getRegistrationRequestFromManualRegistrationJson(registrationRequestDefaultJsonClaims, manualRegistrationRequest, objectMapper);
        registrationRequest.overwriteRegistrationRequestFieldsFromSSAClaims(apiClientIdentity);
        log.debug("The OIDC registration request we are going to send to AM {}", registrationRequest);
        // Register the TPP
        String tppIdentifier = registrationRequest.getSoftwareIdFromSSA();
        Tpp tpp = tppRegistrationService.registerTpp(apiClientIdentity, registrationRequest);
        log.debug("Successfully performed manual onboarding! the tpp resulting: {}", tpp);
        ManualRegistrationApplication manualRegistrationApplication = ManualRegistrationApplication.builder().userId(userNameOfSessionHolder).manualRegistrationRequest(manualRegistrationRequest).description(manualRegistrationRequest.getApplicationDescription()).softwareClientId(tpp.getClientId()).oidcRegistrationResponse(tpp.getRegistrationResponse()).build();
        return ResponseEntity.status(HttpStatus.CREATED).body(manualRegistrationApplicationService.createApplication(manualRegistrationApplication));
    } catch (ApiClientException e) {
        log.info("registerApplication() caught ApiClientException; ", e);
        throw new OAuth2InvalidClientException(e.getMessage());
    } catch (DynamicClientRegistrationException e) {
        log.info("registerApplication() caught DynamicClientRegistrationException; ", e);
        throw new OAuth2InvalidClientException(e.getMessage());
    }
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) ApiClientException(com.forgerock.openbanking.common.services.onboarding.apiclient.ApiClientException) DynamicClientRegistrationException(com.forgerock.openbanking.common.error.exception.dynamicclientregistration.DynamicClientRegistrationException) OAuth2InvalidClientException(com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException) ApiClientIdentity(com.forgerock.openbanking.common.services.onboarding.apiclient.ApiClientIdentity) ManualRegistrationRequest(com.forgerock.openbanking.common.model.onboarding.ManualRegistrationRequest) RegistrationRequest(com.forgerock.openbanking.common.services.onboarding.registrationrequest.RegistrationRequest) ManualRegistrationApplication(com.forgerock.openbanking.common.model.onboarding.ManualRegistrationApplication)

Example 3 with ManualRegistrationRequest

use of com.forgerock.openbanking.common.model.onboarding.ManualRegistrationRequest in project openbanking-aspsp by OpenBankingToolkit.

the class RegistrationRequestFactory method getRegistrationRequestFromManualRegistrationJson.

public RegistrationRequest getRegistrationRequestFromManualRegistrationJson(String registrationRequestJson, ManualRegistrationRequest manualRegistrationRequest, ObjectMapper objectMapper) throws DynamicClientRegistrationException {
    String methodName = "getRegistrationRequestFromManualRegistrationJson()";
    log.debug("{} called with regisratrationRequestJson; '{}', manualRegistrationRequest; '{}'", methodName, registrationRequestJson, manualRegistrationRequest);
    try {
        RegistrationRequest request = objectMapper.readValue(registrationRequestJson, RegistrationRequest.class);
        request.setRedirectUris(manualRegistrationRequest.getRedirectUris());
        String softwareStatementAssertion = manualRegistrationRequest.getSoftwareStatementAssertion();
        if (StringUtils.isEmpty(softwareStatementAssertion)) {
            String errorMessage = "Manual Request did not contain a valid software statement";
            log.info("{} {}. registrationRequestJson is '{}'", methodName, errorMessage, registrationRequestJson);
            throw new DynamicClientRegistrationException(errorMessage, DynamicClientRegistrationErrorType.INVALID_SOFTWARE_STATEMENT);
        }
        request.setSoftwareStatement(softwareStatementAssertion);
        request.setJson(registrationRequestJson);
        String ssaJwtSerialised = request.getSoftwareStatement();
        RegistrationRequestJWTClaims softwareStatementClaims = getJwtClaimsSet(ssaJwtSerialised, JWTClaimsOrigin.SOFTWARE_STATEMENT_ASSERTION);
        String issuer = softwareStatementClaims.getRequiredStringClaim(OpenBankingConstants.SSAClaims.ISSUER);
        tppRegistrationService.validateSsaAgainstIssuingDirectoryJwksUri(ssaJwtSerialised, issuer);
        DirectorySoftwareStatement regRequestSoftwareStatement = softwareStatementFactory.getSoftwareStatement(softwareStatementClaims);
        request.setDirectorySoftwareStatement(regRequestSoftwareStatement);
        log.debug("{}, returning registrationRequest; '{}'", methodName, request);
        return request;
    } catch (IOException | ParseException ioe) {
        String errorMessage = "Could not map Manual Registration Request JWT fields to internal object";
        log.info("{} {}", methodName, errorMessage, ioe);
        throw new DynamicClientRegistrationException("Could not map registration request jwt fields to " + "internal object " + ioe.getMessage(), DynamicClientRegistrationErrorType.INVALID_CLIENT_METADATA);
    }
}
Also used : DynamicClientRegistrationException(com.forgerock.openbanking.common.error.exception.dynamicclientregistration.DynamicClientRegistrationException) DirectorySoftwareStatement(com.forgerock.openbanking.model.DirectorySoftwareStatement) IOException(java.io.IOException) ParseException(java.text.ParseException) ManualRegistrationRequest(com.forgerock.openbanking.common.model.onboarding.ManualRegistrationRequest)

Aggregations

ManualRegistrationRequest (com.forgerock.openbanking.common.model.onboarding.ManualRegistrationRequest)3 DynamicClientRegistrationException (com.forgerock.openbanking.common.error.exception.dynamicclientregistration.DynamicClientRegistrationException)2 ParseException (java.text.ParseException)2 OAuth2InvalidClientException (com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException)1 ManualRegistrationApplication (com.forgerock.openbanking.common.model.onboarding.ManualRegistrationApplication)1 ApiClientException (com.forgerock.openbanking.common.services.onboarding.apiclient.ApiClientException)1 ApiClientIdentity (com.forgerock.openbanking.common.services.onboarding.apiclient.ApiClientIdentity)1 RegistrationRequest (com.forgerock.openbanking.common.services.onboarding.registrationrequest.RegistrationRequest)1 DirectorySoftwareStatement (com.forgerock.openbanking.model.DirectorySoftwareStatement)1 Tpp (com.forgerock.openbanking.model.Tpp)1 OIDCRegistrationResponse (com.forgerock.openbanking.model.oidc.OIDCRegistrationResponse)1 IOException (java.io.IOException)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1