Skip to content

Commit

Permalink
fix: enforce sanitizeTemplate method
Browse files Browse the repository at this point in the history
fixes AM-3069

gravtee-io/issues#9687
  • Loading branch information
leleueri committed Apr 19, 2024
1 parent 59e5c04 commit 361f78d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ private Single<Client> sanitizeTemplate(Client template) {
template.setDomain(domain.getId());
template.setId(null);
template.setClientSecret(null);
template.setSecretSettings(new ArrayList<>());
template.setClientSecrets(new ArrayList<>());
template.setClientName(ClientServiceImpl.DEFAULT_CLIENT_NAME);
template.setRedirectUris(null);
template.setSectorIdentifierUri(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import io.gravitee.am.model.Domain;
import io.gravitee.am.model.IdentityProvider;
import io.gravitee.am.model.application.ApplicationScopeSettings;
import io.gravitee.am.model.application.ApplicationSecretSettings;
import io.gravitee.am.model.application.ClientSecret;
import io.gravitee.am.model.oidc.Client;
import io.gravitee.am.model.oidc.JWKSet;
import io.gravitee.am.model.oidc.OIDCSettings;
Expand Down Expand Up @@ -898,6 +900,8 @@ public void createFromTemplate() {
template.setClientName("shouldBeRemoved");
template.setClientId("shouldBeReplaced");
template.setClientSecret("shouldBeRemoved");
template.setSecretSettings(List.of(new ApplicationSecretSettings()));
template.setClientSecrets(List.of(new ClientSecret()));
template.setRedirectUris(Arrays.asList("shouldBeRemoved"));
template.setSectorIdentifierUri("shouldBeRemoved");
template.setJwks(new JWKSet());
Expand Down Expand Up @@ -925,7 +929,7 @@ public void createFromTemplate() {
client.getJwks() == null &&
client.getSectorIdentifierUri() == null
);
verify(clientService, times(1)).create(any());
verify(clientService, times(1)).create(argThat(duplicateClient -> duplicateClient.getClientSecrets().isEmpty() && duplicateClient.getSecretSettings().isEmpty()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ private Single<Application> create0(String domain, Application application, User
var applicationSettings = application.getSettings();
final var rawSecret = applicationSettings.getOauth().getClientSecret();
if (rawSecret != null) {
// PUBLIC client doesn't need to have secret, so wa have to test it before generated the hash
// PUBLIC client doesn't need to have secret, so we have to test it before generated the hash
applicationSettings.getOauth().setClientSecret(null);
var clientSecret = this.clientSecretService.generateClientSecret(rawSecret, secretSettings);
application.setSecrets(List.of(clientSecret));
Expand Down

0 comments on commit 361f78d

Please sign in to comment.