Search in sources :

Example 6 with DirectorySoftwareStatement

use of com.forgerock.openbanking.model.DirectorySoftwareStatement in project openbanking-aspsp by OpenBankingToolkit.

the class TppRegistrationService method updateTppMetrics.

private void updateTppMetrics(Tpp tpp, boolean isDeleted) {
    log.debug("updateTppMetrics() creating metrics for Tpp {}. Is being {}", tpp.getClientId(), isDeleted ? "deleted" : "created");
    TppEntry.TppEntryBuilder tppEntryBuilder = TppEntry.builder().created(new DateTime(tpp.getCreated())).deleted(isDeleted ? DateTime.now() : null).directoryId(tpp.getDirectoryId()).oidcClientId(tpp.getClientId()).logoUri(tpp.getLogo()).name(tpp.getName()).types(tpp.getTypes());
    try {
        DirectorySoftwareStatement ssaClaim = tpp.getDirectorySoftwareStatement();
        tppEntryBuilder.softwareId(ssaClaim.getSoftware_id()).organisationId(ssaClaim.getOrg_id()).organisationName(ssaClaim.getOrg_name());
    } catch (NullPointerException e) {
        log.warn("Couldn't read TPP SSA, skipping SSA claims population to TPP entry for this TPP {}", tpp, e);
    }
    tppEntriesKPIService.pushTppEntry(tppEntryBuilder.build());
}
Also used : TppEntry(com.forgerock.openbanking.analytics.model.entries.TppEntry) DirectorySoftwareStatement(com.forgerock.openbanking.model.DirectorySoftwareStatement) DateTime(org.joda.time.DateTime)

Example 7 with DirectorySoftwareStatement

use of com.forgerock.openbanking.model.DirectorySoftwareStatement 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)

Example 8 with DirectorySoftwareStatement

use of com.forgerock.openbanking.model.DirectorySoftwareStatement in project openbanking-aspsp by OpenBankingToolkit.

the class RegistrationRequestFactory method getRegistrationRequestFromJwt.

public RegistrationRequest getRegistrationRequestFromJwt(String registrationRequestJwtSerialised) throws DynamicClientRegistrationException {
    String methodName = "getRegistrationRequestFromJwt()";
    try {
        log.debug("{} called", methodName);
        RegistrationRequestJWTClaims registrationRequestJWTClaims = getJwtClaimsSet(registrationRequestJwtSerialised, JWTClaimsOrigin.REGISTRATION_REQUEST_JWT);
        String ssaJwtSerialised = registrationRequestJWTClaims.getRequiredStringClaim(RegistrationTppRequestClaims.SOFTWARE_STATEMENT);
        RegistrationRequestJWTClaims ssaJwtClaims = getJwtClaimsSet(ssaJwtSerialised, JWTClaimsOrigin.SOFTWARE_STATEMENT_ASSERTION);
        String issuer = ssaJwtClaims.getRequiredStringClaim(OpenBankingConstants.SSAClaims.ISSUER);
        log.debug("{}, SSA issuer is '{}'", methodName, issuer);
        tppRegistrationService.validateSsaAgainstIssuingDirectoryJwksUri(ssaJwtSerialised, issuer);
        log.info("{}. SSA is valid and was issued by '{}'", methodName, issuer);
        DirectorySoftwareStatement softwareStatement = softwareStatementFactory.getSoftwareStatement(ssaJwtClaims);
        String softwareJwkUri = softwareStatement.getSoftware_jwks_endpoint();
        String softwareClientId = ssaJwtClaims.getRequiredStringClaim(OpenBankingConstants.SSAClaims.SOFTWARE_CLIENT_ID);
        tppRegistrationService.verifyTPPRegistrationRequestSignature(registrationRequestJwtSerialised, softwareClientId, softwareJwkUri);
        Map<String, Object> registrationRequestClaimsAsJson = registrationRequestJWTClaims.toJSONObject();
        String registrationRequestJson = JSONObjectUtils.toJSONString(registrationRequestClaimsAsJson);
        try {
            RegistrationRequest request = objectMapper.readValue(registrationRequestJson, RegistrationRequest.class);
            request.setJson(registrationRequestJson);
            request.setDirectorySoftwareStatement(softwareStatement);
            return request;
        } catch (IOException ioe) {
            String errorMessage = "Could not map registration request jwt fields to internal object; " + ioe.getMessage();
            log.info("{}; {} registrationRequestJson; '{}'", methodName, errorMessage, registrationRequestJson);
            throw new DynamicClientRegistrationException(errorMessage, DynamicClientRegistrationErrorType.INVALID_CLIENT_METADATA);
        }
    } catch (ParseException pe) {
        String errorMessage = "Could not parse the provided registration JWT";
        log.info("{}; {} {}", methodName, errorMessage, registrationRequestJwtSerialised, pe);
        throw new DynamicClientRegistrationException(errorMessage, 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)

Example 9 with DirectorySoftwareStatement

use of com.forgerock.openbanking.model.DirectorySoftwareStatement in project openbanking-aspsp by OpenBankingToolkit.

the class TppRegistrationServiceTest method shouldSucceedWhenSoftwareIdsMatch_verifyTPPRegistrationRequestAgainstSSA.

@Test
public void shouldSucceedWhenSoftwareIdsMatch_verifyTPPRegistrationRequestAgainstSSA() throws OBErrorException, OIDCException, DynamicClientRegistrationException {
    // Given
    DirectorySoftwareStatement directorySoftwareStatement = TestHelperFunctions.getValidFRDirectorySoftwareStatement();
    RegistrationRequest regRequest = new RegistrationRequest();
    regRequest.setSoftwareId(directorySoftwareStatement.getSoftware_client_id());
    regRequest.setDirectorySoftwareStatement(directorySoftwareStatement);
    // When
    tppRegistrationService.verifyTPPRegistrationRequestAgainstSSA(regRequest);
// Then
}
Also used : DirectorySoftwareStatement(com.forgerock.openbanking.model.DirectorySoftwareStatement) RegistrationRequest(com.forgerock.openbanking.common.services.onboarding.registrationrequest.RegistrationRequest) Test(org.junit.Test)

Example 10 with DirectorySoftwareStatement

use of com.forgerock.openbanking.model.DirectorySoftwareStatement in project openbanking-aspsp by OpenBankingToolkit.

the class TppRegistrationServiceTest method shouldSucceedWhenRequestRedirectUriInSsa_verifyTppRegistrationRequestAgainstSSA.

@Test
public void shouldSucceedWhenRequestRedirectUriInSsa_verifyTppRegistrationRequestAgainstSSA() throws OBErrorException, OIDCException, DynamicClientRegistrationException {
    // Given
    DirectorySoftwareStatement directorySoftwareStatement = TestHelperFunctions.getValidFRDirectorySoftwareStatement();
    RegistrationRequest regRequest = new RegistrationRequest();
    regRequest.setSoftwareId(directorySoftwareStatement.getSoftware_client_id());
    regRequest.setRedirectUris(directorySoftwareStatement.getSoftware_redirect_uris());
    regRequest.setSoftwareStatement(TestHelperFunctions.getValidSsaSerialised());
    regRequest.setDirectorySoftwareStatement(directorySoftwareStatement);
    // When
    tppRegistrationService.verifyTPPRegistrationRequestAgainstSSA(regRequest);
// then
}
Also used : DirectorySoftwareStatement(com.forgerock.openbanking.model.DirectorySoftwareStatement) RegistrationRequest(com.forgerock.openbanking.common.services.onboarding.registrationrequest.RegistrationRequest) Test(org.junit.Test)

Aggregations

DirectorySoftwareStatement (com.forgerock.openbanking.model.DirectorySoftwareStatement)11 Test (org.junit.Test)5 DynamicClientRegistrationException (com.forgerock.openbanking.common.error.exception.dynamicclientregistration.DynamicClientRegistrationException)3 RegistrationRequest (com.forgerock.openbanking.common.services.onboarding.registrationrequest.RegistrationRequest)3 Tpp (com.forgerock.openbanking.model.Tpp)3 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 ManualRegistrationRequest (com.forgerock.openbanking.common.model.onboarding.ManualRegistrationRequest)2 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)2 SignedJWT (com.nimbusds.jwt.SignedJWT)2 TppEntry (com.forgerock.openbanking.analytics.model.entries.TppEntry)1 MultiReadHttpServletRequest (com.forgerock.openbanking.aspsp.rs.filter.MultiReadHttpServletRequest)1 OpenBankingDirectoryConfiguration (com.forgerock.openbanking.common.services.onboarding.configuration.OpenBankingDirectoryConfiguration)1 DirectorySoftwareStatementFactory (com.forgerock.openbanking.common.services.onboarding.registrationrequest.DirectorySoftwareStatementFactory)1 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)1 InvalidTokenException (com.forgerock.openbanking.jwt.exceptions.InvalidTokenException)1 OIDCRegistrationResponse (com.forgerock.openbanking.model.oidc.OIDCRegistrationResponse)1 ChangeSet (com.github.mongobee.changeset.ChangeSet)1 DateTime (org.joda.time.DateTime)1 Ignore (org.junit.Ignore)1