Skip to content

Commit

Permalink
Merge pull request #261 from adorsys/client-default-client-scopes
Browse files Browse the repository at this point in the history
fix import defaultClientScopes and optionalClientScopes on clients
  • Loading branch information
jkroepke authored Nov 18, 2020
2 parents e91343b + 77b260d commit c510354
Show file tree
Hide file tree
Showing 8 changed files with 487 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

### Changed

### Fixed
- On client import`defaultClientScopes` and `optionalClientScopes` are ignore if referenced scope does not exist before import.

## [2.6.1] - 2020-11-17

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,12 @@ public ClientScopeImportService(ClientScopeRepository clientScopeRepository, Imp
this.importConfigProperties = importConfigProperties;
}

public void importClientScopes(RealmImport realmImport) {
public void doImport(RealmImport realmImport) {
List<ClientScopeRepresentation> clientScopes = realmImport.getClientScopes();
String realmName = realmImport.getRealm();

if (clientScopes == null) return;

importClientScopes(realmName, clientScopes);
}

private void importClientScopes(String realmName, List<ClientScopeRepresentation> clientScopes) {
List<ClientScopeRepresentation> existingClientScopes = clientScopeRepository.getAll(realmName);
List<ClientScopeRepresentation> existingDefaultClientScopes = clientScopeRepository.getDefaultClientScopes(realmName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ private void updateRealm(RealmImport realmImport) {
private void configureRealm(RealmImport realmImport) {
stateService.loadState(realmImport);

clientScopeImportService.doImport(realmImport);
clientImportService.doImport(realmImport);
roleImportService.doImport(realmImport);
groupImportService.importGroups(realmImport);
clientScopeImportService.importClientScopes(realmImport);
userImportService.doImport(realmImport);
requiredActionsImportService.doImport(realmImport);
authenticationFlowsImportService.doImport(realmImport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,32 @@ void shouldRemoveAuthenticationFlowBindingOverrides() {
assertThat(client.getAuthenticationFlowBindingOverrides(), equalTo(Collections.emptyMap()));
}

@Test
@Order(20)
void shouldCreateClientWithDefaultClientScope() {
doImport("20_update_realm__client_client_with_default_scope.json");

RealmRepresentation realm = keycloakProvider.getInstance().realm(REALM_NAME).partialExport(true, true);
assertThat(realm.getRealm(), is(REALM_NAME));
assertThat(realm.isEnabled(), is(true));

assertThat(getClientByName(realm, "auth-moped-client"), notNullValue());
assertThat(getClientByName(realm, "moped-client"), notNullValue());

ClientRepresentation client = getClientByName(realm, "default-client-scope-client");
assertThat(client.getName(), is("default-client-scope-client"));
assertThat(client.getClientId(), is("default-client-scope-client"));
assertThat(client.getDescription(), is("Default-Client-Another-Client"));
assertThat(client.isEnabled(), is(true));
assertThat(client.getClientAuthenticatorType(), is("client-secret"));
assertThat(client.getRedirectUris(), is(containsInAnyOrder("*")));
assertThat(client.getWebOrigins(), is(containsInAnyOrder("*")));
assertThat(client.isServiceAccountsEnabled(), is(false));
assertThat(client.getDefaultClientScopes(), is(containsInAnyOrder("custom-address", "address")));
assertThat(client.getOptionalClientScopes(), is(containsInAnyOrder("custom-email", "email")));

}

@Test
@Order(70)
void shouldCreateRealmWithClientWithAuthenticationFlowBindingOverrides() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@
@SetSystemProperty(key = "kcc.junit.not-before", value = "1200")
@SetSystemProperty(key = "kcc.junit.browser-security-headers", value = "{\"xRobotsTag\":\"noindex\"}")
class ImportRealmSubstitutionExtendedIT extends AbstractImportTest {
private static final String REALM_NAME = "realm-substitution";
private static final String REALM_NAME = "realm-substitution-extended";

ImportRealmSubstitutionExtendedIT() {
this.resourcePath = "import-files/realm-substitution";
this.resourcePath = "import-files/realm-substitution-extended";
}

@Test
@Order(1)
@Order(0)
void shouldCreateRealm() {
assertThat(System.getProperty("kcc.junit.display-name"), is("<div class=\\\"kc-logo-text\\\"><span>Keycloak</span></div>"));

doImport("3_update_realm.json");
doImport("0_update_realm.json");

RealmRepresentation realm = keycloakProvider.getInstance().realm(REALM_NAME).toRepresentation();

Expand Down
Loading

0 comments on commit c510354

Please sign in to comment.