Skip to content

Commit

Permalink
fix: properly check if application type is defined with using DCR
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetanmaisse committed Oct 26, 2023
1 parent a6bd519 commit 2f6e29d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public ApplicationEntity create(final ExecutionContext executionContext, NewAppl
if (!isApplicationTypeAllowed(executionContext, appType, executionContext.getEnvironmentId())) {
throw new IllegalStateException("Application type '" + appType + "' is not allowed");
}
checkClientSettings(newApplicationEntity.getSettings().getoAuthClient(), newApplicationEntity.getType());
checkAndSanitizeOAuthClientSettings(newApplicationEntity.getSettings().getoAuthClient());

// Create an OAuth client
ClientRegistrationResponse registrationResponse = clientRegistrationService.register(executionContext, newApplicationEntity);
Expand Down Expand Up @@ -462,12 +462,16 @@ private ApplicationEntity createApplicationForEnvironment(
}
}

private void checkClientSettings(OAuthClientSettings oAuthClientSettings, String applicationType) {
private void checkAndSanitizeOAuthClientSettings(OAuthClientSettings oAuthClientSettings) {
if (oAuthClientSettings.getGrantTypes() == null || oAuthClientSettings.getGrantTypes().isEmpty()) {
throw new ApplicationGrantTypesNotFoundException();
}

ApplicationTypeEntity applicationTypeEntity = applicationTypeService.getApplicationType(applicationType);
if (oAuthClientSettings.getApplicationType() == null || oAuthClientSettings.getApplicationType().isEmpty()) {
throw new ApplicationTypeNotFoundException(null);
}

ApplicationTypeEntity applicationTypeEntity = applicationTypeService.getApplicationType(oAuthClientSettings.getApplicationType());

List<String> targetGrantTypes = oAuthClientSettings.getGrantTypes();
List<String> allowedGrantTypes = applicationTypeEntity
Expand Down Expand Up @@ -559,7 +563,7 @@ public ApplicationEntity update(
} else {
// Check that client registration is enabled
checkClientRegistrationEnabled(executionContext, executionContext.getEnvironmentId());
checkClientSettings(updateApplicationEntity.getSettings().getoAuthClient(), applicationToUpdate.getType().name());
checkAndSanitizeOAuthClientSettings(updateApplicationEntity.getSettings().getoAuthClient());

// Update an OAuth client
final String registrationPayload = applicationToUpdate.getMetadata().get(METADATA_REGISTRATION_PAYLOAD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,13 @@ public void shouldCreateOauthApp() throws TechnicalException {
when(parameterService.findAsBoolean(any(), eq(Key.APPLICATION_TYPE_BROWSER_ENABLED), any(), eq(ParameterReferenceType.ENVIRONMENT)))
.thenReturn(true);

// oauth app settings contains everything required
// oauth app setting contains everything required
ApplicationSettings settings = new ApplicationSettings();
OAuthClientSettings oAuthClientSettings = new OAuthClientSettings();
oAuthClientSettings.setGrantTypes(List.of("application-grant-type"));
oAuthClientSettings.setApplicationType("BROWSER");
settings.setoAuthClient(oAuthClientSettings);
when(newApplication.getSettings()).thenReturn(settings);
when(newApplication.getType()).thenReturn(ApplicationType.BROWSER.name());

// mock application type service
ApplicationTypeEntity applicationTypeEntity = new ApplicationTypeEntity();
Expand Down

0 comments on commit 2f6e29d

Please sign in to comment.