Java Code Examples for org.keycloak.representations.idm.RealmRepresentation#getScopeMappings()
The following examples show how to use
org.keycloak.representations.idm.RealmRepresentation#getScopeMappings() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 6 votes |
@Test @Order(0) void shouldCreateRealmWithScopeMappings() { doImport("00_create-realm-with-scope-mappings.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, hasSize(1)); ScopeMappingRepresentation scopeMapping = scopeMappings.get(0); assertThat(scopeMapping.getClient(), is(nullValue())); assertThat(scopeMapping.getClientScope(), is(equalTo("offline_access"))); assertThat(scopeMapping.getRoles(), hasSize(1)); assertThat(scopeMapping.getRoles(), contains("offline_access")); }
Example 2
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 6 votes |
@Test @Order(1) void shouldUpdateRealmByAddingScopeMapping() { doImport("01_update-realm__add-scope-mapping.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, hasSize(2)); ScopeMappingRepresentation scopeMapping = findScopeMappingForClient(realm, "scope-mapping-client"); assertThat(scopeMapping.getClient(), is(equalTo("scope-mapping-client"))); Set<String> scopeMappingRoles = scopeMapping.getRoles(); assertThat(scopeMappingRoles, hasSize(1)); assertThat(scopeMappingRoles, contains("scope-mapping-role")); }
Example 3
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 6 votes |
@Test @Order(2) void shouldUpdateRealmByAddingRoleToScopeMapping() { doImport("02_update-realm__add-role-to-scope-mapping.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, hasSize(2)); ScopeMappingRepresentation scopeMapping = findScopeMappingForClient(realm, "scope-mapping-client"); assertThat(scopeMapping.getClient(), is(equalTo("scope-mapping-client"))); Set<String> scopeMappingRoles = scopeMapping.getRoles(); assertThat(scopeMappingRoles, hasSize(2)); assertThat(scopeMappingRoles, contains("scope-mapping-role", "added-scope-mapping-role")); }
Example 4
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 6 votes |
@Test @Order(6) void shouldUpdateRealmByNotChangingScopeMappingsIfOmittedInImport() { doImport("06_update-realm__do-not-change-scope-mappings.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, hasSize(2)); ScopeMappingRepresentation scopeMapping = findScopeMappingForClient(realm, "scope-mapping-client-two"); assertThat(scopeMapping.getClient(), is(equalTo("scope-mapping-client-two"))); Set<String> scopeMappingRoles = scopeMapping.getRoles(); assertThat(scopeMappingRoles, hasSize(1)); assertThat(scopeMappingRoles, contains("added-scope-mapping-role")); }
Example 5
Source File: ScopeMappingImportService.java From keycloak-config-cli with Apache License 2.0 | 5 votes |
private void createOrUpdateScopeMappings(RealmImport realmImport) { List<ScopeMappingRepresentation> scopeMappingsToImport = realmImport.getScopeMappings(); if (scopeMappingsToImport == null) return; String realm = realmImport.getRealm(); RealmRepresentation existingRealm = realmRepository.partialExport(realm, true, true); List<ScopeMappingRepresentation> existingScopeMappings = existingRealm.getScopeMappings(); createOrUpdateRolesInScopeMappings(realm, scopeMappingsToImport, existingScopeMappings); if (importConfigProperties.getManaged().getScopeMapping() == ImportManagedPropertiesValues.FULL) { cleanupRolesInScopeMappingsIfNecessary(realm, scopeMappingsToImport, existingScopeMappings); } }
Example 6
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 5 votes |
@Test @Order(3) void shouldUpdateRealmByAddingAnotherScopeMapping() { doImport("03_update-realm__add-scope-mapping.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, hasSize(3)); // check scope-mapping for client 'scope-mapping-client' ScopeMappingRepresentation scopeMapping = findScopeMappingForClient(realm, "scope-mapping-client"); assertThat(scopeMapping.getClient(), is(equalTo("scope-mapping-client"))); Set<String> scopeMappingRoles = scopeMapping.getRoles(); assertThat(scopeMappingRoles, hasSize(2)); assertThat(scopeMappingRoles, contains("scope-mapping-role", "added-scope-mapping-role")); // check scope-mapping for client 'scope-mapping-client-two' scopeMapping = findScopeMappingForClient(realm, "scope-mapping-client-two"); assertThat(scopeMapping.getClient(), is(equalTo("scope-mapping-client-two"))); scopeMappingRoles = scopeMapping.getRoles(); assertThat(scopeMappingRoles, hasSize(2)); assertThat(scopeMappingRoles, contains("scope-mapping-role", "added-scope-mapping-role")); }
Example 7
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 5 votes |
@Test @Order(4) void shouldUpdateRealmByRemovingRoleFromScopeMapping() { doImport("04_update-realm__delete-role-from-scope-mapping.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, hasSize(3)); // check scope-mapping for client 'scope-mapping-client' ScopeMappingRepresentation scopeMapping = findScopeMappingForClient(realm, "scope-mapping-client"); assertThat(scopeMapping.getClient(), is(equalTo("scope-mapping-client"))); Set<String> scopeMappingRoles = scopeMapping.getRoles(); assertThat(scopeMappingRoles, hasSize(2)); assertThat(scopeMappingRoles, contains("scope-mapping-role", "added-scope-mapping-role")); // check scope-mapping for client 'scope-mapping-client-two' scopeMapping = findScopeMappingForClient(realm, "scope-mapping-client-two"); assertThat(scopeMapping.getClient(), is(equalTo("scope-mapping-client-two"))); scopeMappingRoles = scopeMapping.getRoles(); assertThat(scopeMappingRoles, hasSize(1)); assertThat(scopeMappingRoles, contains("added-scope-mapping-role")); }
Example 8
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 5 votes |
@Test @Order(5) void shouldUpdateRealmByDeletingScopeMappingForClient() { doImport("05_update-realm__delete-scope-mapping-for-client.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, hasSize(2)); // check scope-mapping for client 'scope-mapping-client-two' ScopeMappingRepresentation scopeMapping = findScopeMappingForClient(realm, "scope-mapping-client-two"); assertThat(scopeMapping.getClient(), is(equalTo("scope-mapping-client-two"))); Set<String> scopeMappingRoles = scopeMapping.getRoles(); assertThat(scopeMappingRoles, hasSize(1)); assertThat(scopeMappingRoles, contains("added-scope-mapping-role")); // check scope-mapping for client 'scope-mapping-client' -> should not exist Optional<ScopeMappingRepresentation> maybeNotExistingScopeMapping = tryToFindScopeMappingForClient(realm, "scope-mapping-client"); assertThat(maybeNotExistingScopeMapping.isPresent(), is(false)); }
Example 9
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 5 votes |
@Test @Order(7) void shouldUpdateRealmByDeletingAllExistingScopeMappings() { doImport("07_update-realm__delete-all-scope-mappings.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, is(nullValue())); }
Example 10
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 5 votes |
@Test @Order(8) void shouldUpdateRealmByAddingScopeMappingsForClientScope() { doImport("08_update-realm__add-scope-mappings-for-client-scope.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, hasSize(2)); ScopeMappingRepresentation scopeMappingClientScope = scopeMappings .stream() .filter(scopeMapping -> scopeMapping.getClientScope() != null) .findFirst() .orElse(null); assertThat(scopeMappingClientScope, notNullValue()); assertThat(scopeMappingClientScope.getClient(), is(nullValue())); assertThat(scopeMappingClientScope.getClientScope(), is(equalTo("offline_access"))); assertThat(scopeMappingClientScope.getRoles(), hasSize(2)); assertThat(scopeMappingClientScope.getRoles(), contains("scope-mapping-role", "added-scope-mapping-role")); ScopeMappingRepresentation scopeMappingClient = scopeMappings .stream() .filter(scopeMapping -> scopeMapping.getClient() != null) .findFirst() .orElse(null); assertThat(scopeMappingClient, notNullValue()); assertThat(scopeMappingClient.getClient(), is(equalTo("scope-mapping-client"))); assertThat(scopeMappingClient.getClientScope(), is(nullValue())); assertThat(scopeMappingClient.getRoles(), hasSize(1)); assertThat(scopeMappingClient.getRoles(), contains("user")); }
Example 11
Source File: ImportScopeMappingsIT.java From keycloak-config-cli with Apache License 2.0 | 5 votes |
@Test @Order(9) void shouldUpdateRealmByAddingRolesForClient() { doImport("09_update-realm__update-role-for-client.json"); RealmRepresentation realm = keycloakProvider.get().realm(REALM_NAME).partialExport(true, true); assertThat(realm.getRealm(), is(REALM_NAME)); assertThat(realm.isEnabled(), is(true)); List<ScopeMappingRepresentation> scopeMappings = realm.getScopeMappings(); assertThat(scopeMappings, hasSize(2)); ScopeMappingRepresentation scopeMappingClientScope = scopeMappings .stream() .filter(scopeMapping -> scopeMapping.getClientScope() != null) .findFirst() .orElse(null); assertThat(scopeMappingClientScope, notNullValue()); assertThat(scopeMappingClientScope.getClient(), is(nullValue())); assertThat(scopeMappingClientScope.getClientScope(), is(equalTo("offline_access"))); assertThat(scopeMappingClientScope.getRoles(), hasSize(2)); assertThat(scopeMappingClientScope.getRoles(), contains("offline_access", "added-scope-mapping-role")); ScopeMappingRepresentation scopeMappingClient = scopeMappings .stream() .filter(scopeMapping -> scopeMapping.getClient() != null) .findFirst() .orElse(null); assertThat(scopeMappingClient, notNullValue()); assertThat(scopeMappingClient.getClient(), is(equalTo("scope-mapping-client"))); assertThat(scopeMappingClient.getClientScope(), is(nullValue())); assertThat(scopeMappingClient.getRoles(), hasSize(1)); assertThat(scopeMappingClient.getRoles(), contains("admin")); }