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();
}
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());
}
}
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);
}
}
Aggregations