diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java index 6a61851683..690d2fe429 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java @@ -587,20 +587,6 @@ public class RealmAdapter implements RealmModel { updated.updateDefaultRoles(defaultRoles); } - @Override - public Map getClientNameMap() { - if (updated != null) return updated.getClientNameMap(); - Map map = new HashMap(); - for (String id : cached.getClients().values()) { - ClientModel model = cacheSession.getClientById(id, this); - if (model == null) { - throw new IllegalStateException("Cached application not found: " + id); - } - map.put(model.getClientId(), model); - } - return Collections.unmodifiableMap(map); - } - @Override public List getClients() { if (updated != null) return updated.getClients(); diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index d99dedc28f..65d3b1b854 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -721,17 +721,6 @@ public class RealmAdapter implements RealmModel { } - @Override - public Map getClientNameMap() { - List clients = getClients(); - if (clients.isEmpty()) return Collections.EMPTY_MAP; - Map map = new HashMap(); - for (ClientModel app : clients) { - map.put(app.getClientId(), app); - } - return Collections.unmodifiableMap(map); - } - @Override public List getClients() { TypedQuery query = em.createNamedQuery("getClientsByRealm", ClientEntity.class); diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java index 9ceec417a6..48978ffe12 100755 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java @@ -813,17 +813,6 @@ public class RealmAdapter extends AbstractMongoAdapter impleme return session.realms().getClientByClientId(clientId, this); } - @Override - public Map getClientNameMap() { - List clients = getClients(); - if (clients.isEmpty()) return Collections.EMPTY_MAP; - Map resourceMap = new HashMap(); - for (ClientModel resource : clients) { - resourceMap.put(resource.getClientId(), resource); - } - return Collections.unmodifiableMap(resourceMap); - } - @Override public List getClients() { DBObject query = new QueryBuilder() diff --git a/server-spi/src/main/java/org/keycloak/migration/migrators/MigrationTo1_2_0_CR1.java b/server-spi/src/main/java/org/keycloak/migration/migrators/MigrationTo1_2_0_CR1.java index be0a9f3fe3..f2a86ce466 100755 --- a/server-spi/src/main/java/org/keycloak/migration/migrators/MigrationTo1_2_0_CR1.java +++ b/server-spi/src/main/java/org/keycloak/migration/migrators/MigrationTo1_2_0_CR1.java @@ -36,7 +36,7 @@ public class MigrationTo1_2_0_CR1 { public static final ModelVersion VERSION = new ModelVersion("1.2.0.CR1"); public void setupBrokerService(RealmModel realm) { - ClientModel client = realm.getClientNameMap().get(Constants.BROKER_SERVICE_CLIENT_ID); + ClientModel client = realm.getClientByClientId(Constants.BROKER_SERVICE_CLIENT_ID); if (client == null) { client = KeycloakModelUtils.createClient(realm, Constants.BROKER_SERVICE_CLIENT_ID); client.setEnabled(true); @@ -52,16 +52,13 @@ public class MigrationTo1_2_0_CR1 { } private void setupClientNames(RealmModel realm) { - Map clients = realm.getClientNameMap(); - - setupClientName(clients, Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); - setupClientName(clients, Constants.ADMIN_CONSOLE_CLIENT_ID); - setupClientName(clients, Constants.REALM_MANAGEMENT_CLIENT_ID); + setupClientName(realm.getClientByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID)); + setupClientName(realm.getClientByClientId(Constants.ADMIN_CONSOLE_CLIENT_ID)); + setupClientName(realm.getClientByClientId(Constants.REALM_MANAGEMENT_CLIENT_ID)); } - private void setupClientName(Map clients, String clientId) { - ClientModel client = clients.get(clientId); - if (client != null && client.getName() == null) client.setName("${client_" + clientId + "}"); + private void setupClientName(ClientModel client) { + if (client != null && client.getName() == null) client.setName("${client_" + client.getClientId() + "}"); } public void migrate(KeycloakSession session) { diff --git a/server-spi/src/main/java/org/keycloak/models/RealmModel.java b/server-spi/src/main/java/org/keycloak/models/RealmModel.java index 87a929990c..bc7dec5960 100755 --- a/server-spi/src/main/java/org/keycloak/models/RealmModel.java +++ b/server-spi/src/main/java/org/keycloak/models/RealmModel.java @@ -193,9 +193,6 @@ public interface RealmModel extends RoleContainerModel { void removeDefaultGroup(GroupModel group); - // Key is clientId - Map getClientNameMap(); - List getClients(); ClientModel addClient(String name); diff --git a/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index c9d89b462a..d349f4e02e 100755 --- a/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -234,12 +234,12 @@ public class RepresentationToModel { // Now that all possible roles and clients are created, create scope mappings - Map appMap = newRealm.getClientNameMap(); + //Map appMap = newRealm.getClientNameMap(); if (rep.getClientScopeMappings() != null) { for (Map.Entry> entry : rep.getClientScopeMappings().entrySet()) { - ClientModel app = appMap.get(entry.getKey()); + ClientModel app = newRealm.getClientByClientId(entry.getKey()); if (app == null) { throw new RuntimeException("Unable to find client role mappings for client: " + entry.getKey()); } @@ -320,7 +320,7 @@ public class RepresentationToModel { if (rep.getUsers() != null) { for (UserRepresentation userRep : rep.getUsers()) { - UserModel user = createUser(session, newRealm, userRep, appMap); + UserModel user = createUser(session, newRealm, userRep); } } @@ -383,14 +383,13 @@ public class RepresentationToModel { List groups = rep.getGroups(); if (groups == null) return; - Map clientMap = realm.getClientNameMap(); GroupModel parent = null; for (GroupRepresentation group : groups) { - importGroup(realm, clientMap, parent, group); + importGroup(realm, parent, group); } } - public static void importGroup(RealmModel realm, Map clientMap, GroupModel parent, GroupRepresentation group) { + public static void importGroup(RealmModel realm, GroupModel parent, GroupRepresentation group) { GroupModel newGroup = realm.createGroup(group.getId(), group.getName()); if (group.getAttributes() != null) { for (Map.Entry> attr : group.getAttributes().entrySet()) { @@ -410,7 +409,7 @@ public class RepresentationToModel { } if (group.getClientRoles() != null) { for (Map.Entry> entry : group.getClientRoles().entrySet()) { - ClientModel client = clientMap.get(entry.getKey()); + ClientModel client = realm.getClientByClientId(entry.getKey()); if (client == null) { throw new RuntimeException("Unable to find client role mappings for client: " + entry.getKey()); } @@ -427,7 +426,7 @@ public class RepresentationToModel { } if (group.getSubGroups() != null) { for (GroupRepresentation subGroup : group.getSubGroups()) { - importGroup(realm, clientMap, newGroup, subGroup); + importGroup(realm, newGroup, subGroup); } } } @@ -1180,7 +1179,7 @@ public class RepresentationToModel { // Users - public static UserModel createUser(KeycloakSession session, RealmModel newRealm, UserRepresentation userRep, Map clientMap) { + public static UserModel createUser(KeycloakSession session, RealmModel newRealm, UserRepresentation userRep) { convertDeprecatedSocialProviders(userRep); // Import users just to user storage. Don't federate @@ -1228,7 +1227,7 @@ public class RepresentationToModel { } if (userRep.getServiceAccountClientId() != null) { String clientId = userRep.getServiceAccountClientId(); - ClientModel client = clientMap.get(clientId); + ClientModel client = newRealm.getClientByClientId(clientId); if (client == null) { throw new RuntimeException("Unable to find client specified for service account link. Client: " + clientId); } @@ -1316,9 +1315,8 @@ public class RepresentationToModel { } } if (userRep.getClientRoles() != null) { - Map clientMap = realm.getClientNameMap(); for (Map.Entry> entry : userRep.getClientRoles().entrySet()) { - ClientModel client = clientMap.get(entry.getKey()); + ClientModel client = realm.getClientByClientId(entry.getKey()); if (client == null) { throw new RuntimeException("Unable to find client role mappings for client: " + entry.getKey()); } diff --git a/services/src/main/java/org/keycloak/exportimport/util/ImportUtils.java b/services/src/main/java/org/keycloak/exportimport/util/ImportUtils.java index 0e21f7aec6..06f6e54998 100755 --- a/services/src/main/java/org/keycloak/exportimport/util/ImportUtils.java +++ b/services/src/main/java/org/keycloak/exportimport/util/ImportUtils.java @@ -199,9 +199,8 @@ public class ImportUtils { private static void importUsers(KeycloakSession session, RealmProvider model, String realmName, List userReps) { RealmModel realm = model.getRealmByName(realmName); - Map apps = realm.getClientNameMap(); for (UserRepresentation user : userReps) { - RepresentationToModel.createUser(session, realm, user, apps); + RepresentationToModel.createUser(session, realm, user); } } diff --git a/services/src/main/java/org/keycloak/partialimport/UsersPartialImport.java b/services/src/main/java/org/keycloak/partialimport/UsersPartialImport.java old mode 100644 new mode 100755 index dbfc8406ac..2dc413626b --- a/services/src/main/java/org/keycloak/partialimport/UsersPartialImport.java +++ b/services/src/main/java/org/keycloak/partialimport/UsersPartialImport.java @@ -107,9 +107,8 @@ public class UsersPartialImport extends AbstractPartialImport apps = realm.getClientNameMap(); user.setId(KeycloakModelUtils.generateId()); - UserModel userModel = RepresentationToModel.createUser(session, realm, user, apps); + UserModel userModel = RepresentationToModel.createUser(session, realm, user); if (userModel == null) throw new RuntimeException("Unable to create user " + getName(user)); createdIds.put(getName(user), userModel.getId()); } diff --git a/services/src/main/java/org/keycloak/services/managers/RealmManager.java b/services/src/main/java/org/keycloak/services/managers/RealmManager.java index 8b6a732d0e..fd3a009824 100755 --- a/services/src/main/java/org/keycloak/services/managers/RealmManager.java +++ b/services/src/main/java/org/keycloak/services/managers/RealmManager.java @@ -327,7 +327,7 @@ public class RealmManager implements RealmImporter { private void setupAccountManagement(RealmModel realm) { - ClientModel client = realm.getClientNameMap().get(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); + ClientModel client = realm.getClientByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); if (client == null) { client = KeycloakModelUtils.createClient(realm, Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); client.setName("${client_" + Constants.ACCOUNT_MANAGEMENT_CLIENT_ID + "}"); @@ -352,7 +352,7 @@ public class RealmManager implements RealmImporter { } public void setupBrokerService(RealmModel realm) { - ClientModel client = realm.getClientNameMap().get(Constants.BROKER_SERVICE_CLIENT_ID); + ClientModel client = realm.getClientByClientId(Constants.BROKER_SERVICE_CLIENT_ID); if (client == null) { client = KeycloakModelUtils.createClient(realm, Constants.BROKER_SERVICE_CLIENT_ID); client.setEnabled(true); diff --git a/services/src/main/java/org/keycloak/services/resources/RealmsResource.java b/services/src/main/java/org/keycloak/services/resources/RealmsResource.java index 1d39612b7e..1ad6b7b6e3 100755 --- a/services/src/main/java/org/keycloak/services/resources/RealmsResource.java +++ b/services/src/main/java/org/keycloak/services/resources/RealmsResource.java @@ -139,7 +139,7 @@ public class RealmsResource { public AccountService getAccountService(final @PathParam("realm") String name) { RealmModel realm = init(name); - ClientModel client = realm.getClientNameMap().get(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); + ClientModel client = realm.getClientByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); if (client == null || !client.isEnabled()) { logger.debug("account management not enabled"); throw new NotFoundException("account management not enabled"); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java index 8d9e85d836..7c5152bde4 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java @@ -73,7 +73,7 @@ public class AccountTest { public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { UserModel user = manager.getSession().users().getUserByUsername("test-user@localhost", appRealm); - ClientModel accountApp = appRealm.getClientNameMap().get(org.keycloak.models.Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); + ClientModel accountApp = appRealm.getClientByClientId(org.keycloak.models.Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); UserModel user2 = manager.getSession().users().addUser(appRealm, "test-user-no-access@localhost"); user2.setEnabled(true); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ClientModelTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ClientModelTest.java index e66aa6087c..24161a2b08 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ClientModelTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ClientModelTest.java @@ -75,7 +75,7 @@ public class ClientModelTest extends AbstractModelTest { public void persist() { RealmModel persisted = realmManager.getRealm(realm.getId()); - ClientModel actual = persisted.getClientNameMap().get("app-name"); + ClientModel actual = persisted.getClientByClientId("app-name"); assertEquals(client, actual); } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ImportTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ImportTest.java index a60877e99e..0f02666437 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ImportTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ImportTest.java @@ -118,12 +118,12 @@ public class ImportTest extends AbstractModelTest { Assert.assertNotNull(application); Assert.assertNotNull(otherApp); Assert.assertNull(nonExisting); - Map clients = realm.getClientNameMap(); + List clients = realm.getClients(); Assert.assertEquals(8, clients.size()); - Assert.assertTrue(clients.values().contains(application)); - Assert.assertTrue(clients.values().contains(otherApp)); - Assert.assertTrue(clients.values().contains(accountApp)); - realm.getClients().containsAll(clients.values()); + Assert.assertTrue(clients.contains(application)); + Assert.assertTrue(clients.contains(otherApp)); + Assert.assertTrue(clients.contains(accountApp)); + realm.getClients().containsAll(clients); Assert.assertEquals("Applicationn", application.getName()); Assert.assertEquals(50, application.getNodeReRegistrationTimeout()); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/oauth/AuthorizationCodeTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/oauth/AuthorizationCodeTest.java index 2ceca15360..9a71c6497d 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/oauth/AuthorizationCodeTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/oauth/AuthorizationCodeTest.java @@ -91,7 +91,7 @@ public class AuthorizationCodeTest { keycloakRule.update(new KeycloakRule.KeycloakSetup() { @Override public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - appRealm.getClientNameMap().get("test-app").addRedirectUri(Constants.INSTALLED_APP_URN); + appRealm.getClientByClientId("test-app").addRedirectUri(Constants.INSTALLED_APP_URN); } }); oauth.redirectUri(Constants.INSTALLED_APP_URN); @@ -110,7 +110,7 @@ public class AuthorizationCodeTest { keycloakRule.update(new KeycloakRule.KeycloakSetup() { @Override public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - appRealm.getClientNameMap().get("test-app").removeRedirectUri(Constants.INSTALLED_APP_URN); + appRealm.getClientByClientId("test-app").removeRedirectUri(Constants.INSTALLED_APP_URN); } }); } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/oauth/OAuthRedirectUriTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/oauth/OAuthRedirectUriTest.java index 5b1274899a..a08ca371dc 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/oauth/OAuthRedirectUriTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/oauth/OAuthRedirectUriTest.java @@ -113,7 +113,7 @@ public class OAuthRedirectUriTest { keycloakRule.update(new KeycloakRule.KeycloakSetup() { @Override public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - appRealm.getClientNameMap().get("test-app").addRedirectUri("http://localhost:8081/app2"); + appRealm.getClientByClientId("test-app").addRedirectUri("http://localhost:8081/app2"); } }); @@ -127,7 +127,7 @@ public class OAuthRedirectUriTest { keycloakRule.update(new KeycloakRule.KeycloakSetup() { @Override public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - appRealm.getClientNameMap().get("test-app").removeRedirectUri("http://localhost:8081/app2"); + appRealm.getClientByClientId("test-app").removeRedirectUri("http://localhost:8081/app2"); } }); } @@ -138,7 +138,7 @@ public class OAuthRedirectUriTest { keycloakRule.update(new KeycloakRule.KeycloakSetup() { @Override public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - appRealm.getClientNameMap().get("test-app").removeRedirectUri("http://localhost:8081/app/*"); + appRealm.getClientByClientId("test-app").removeRedirectUri("http://localhost:8081/app/*"); } }); @@ -152,7 +152,7 @@ public class OAuthRedirectUriTest { keycloakRule.update(new KeycloakRule.KeycloakSetup() { @Override public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - appRealm.getClientNameMap().get("test-app").addRedirectUri("http://localhost:8081/app/*"); + appRealm.getClientByClientId("test-app").addRedirectUri("http://localhost:8081/app/*"); } }); } @@ -163,7 +163,7 @@ public class OAuthRedirectUriTest { keycloakRule.update(new KeycloakRule.KeycloakSetup() { @Override public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - appRealm.getClientNameMap().get("test-app").removeRedirectUri("http://localhost:8081/app/*"); + appRealm.getClientByClientId("test-app").removeRedirectUri("http://localhost:8081/app/*"); } }); @@ -177,7 +177,7 @@ public class OAuthRedirectUriTest { keycloakRule.update(new KeycloakRule.KeycloakSetup() { @Override public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - appRealm.getClientNameMap().get("test-app").addRedirectUri("http://localhost:8081/app/*"); + appRealm.getClientByClientId("test-app").addRedirectUri("http://localhost:8081/app/*"); } }); }