From 84f5c0926b5538eeac91bcb9c0ad6206e617b172 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Thu, 8 Sep 2016 16:47:06 -0400 Subject: [PATCH] KEYCLOAK-3423 --- .../keycloak/storage/UserStorageManager.java | 42 +++++++++-------- testsuite/integration/pom.xml | 45 +++++++++++++++++++ .../default-server-subsys-config.properties | 3 ++ 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/services/src/main/java/org/keycloak/storage/UserStorageManager.java b/services/src/main/java/org/keycloak/storage/UserStorageManager.java index e0b2ffd3c2..226a083fd8 100755 --- a/services/src/main/java/org/keycloak/storage/UserStorageManager.java +++ b/services/src/main/java/org/keycloak/storage/UserStorageManager.java @@ -137,7 +137,7 @@ public class UserStorageManager implements UserProvider, OnUserCache { @Override public boolean removeUser(RealmModel realm, UserModel user) { - getFederatedStorage().preRemove(realm, user); + if (getFederatedStorage() != null) getFederatedStorage().preRemove(realm, user); StorageId storageId = new StorageId(user.getId()); if (storageId.getProviderId() == null) { return localStorage().removeUser(realm, user); @@ -272,6 +272,7 @@ public class UserStorageManager implements UserProvider, OnUserCache { if (user != null) { return user; } + if (getFederatedStorage() == null) return null; String id = getFederatedStorage().getUserByFederatedIdentity(socialLink, realm); if (id != null) return getUserById(id, realm); return null; @@ -315,8 +316,6 @@ public class UserStorageManager implements UserProvider, OnUserCache { protected List query(PaginatedQuery pagedQuery, RealmModel realm, int firstResult, int maxResults) { if (maxResults == 0) return Collections.EMPTY_LIST; - - List storageProviders = getStorageProviders(session, realm, UserQueryProvider.class); // we can skip rest of method if there are no storage providers if (storageProviders.isEmpty()) { @@ -326,7 +325,7 @@ public class UserStorageManager implements UserProvider, OnUserCache { List results = new LinkedList(); providers.add(localStorage()); providers.addAll(storageProviders); - providers.add(getFederatedStorage()); + if (getFederatedStorage() != null) providers.add(getFederatedStorage()); int leftToRead = maxResults; int leftToFirstResult = firstResult; @@ -432,7 +431,7 @@ public class UserStorageManager implements UserProvider, OnUserCache { if (StorageId.isLocalStorage(user)) { set.addAll(localStorage().getFederatedIdentities(user, realm)); } - set.addAll(getFederatedStorage().getFederatedIdentities(user, realm)); + if (getFederatedStorage() != null) set.addAll(getFederatedStorage().getFederatedIdentities(user, realm)); return set; } @@ -443,7 +442,8 @@ public class UserStorageManager implements UserProvider, OnUserCache { FederatedIdentityModel model = localStorage().getFederatedIdentity(user, socialProvider, realm); if (model != null) return model; } - return getFederatedStorage().getFederatedIdentity(user, socialProvider, realm); + if (getFederatedStorage() != null) return getFederatedStorage().getFederatedIdentity(user, socialProvider, realm); + else return null; } @Override @@ -483,47 +483,53 @@ public class UserStorageManager implements UserProvider, OnUserCache { @Override public void preRemove(RealmModel realm) { localStorage().preRemove(realm); - getFederatedStorage().preRemove(realm); - for (UserStorageProvider provider : getStorageProviders(session, realm, UserStorageProvider.class)) { - provider.preRemove(realm); + if (getFederatedStorage() != null) { + getFederatedStorage().preRemove(realm); + for (UserStorageProvider provider : getStorageProviders(session, realm, UserStorageProvider.class)) { + provider.preRemove(realm); + } } } @Override public void preRemove(RealmModel realm, UserFederationProviderModel model) { - getFederatedStorage().preRemove(realm, model); + if (getFederatedStorage() != null) getFederatedStorage().preRemove(realm, model); localStorage().preRemove(realm, model); } @Override public void preRemove(RealmModel realm, GroupModel group) { localStorage().preRemove(realm, group); - getFederatedStorage().preRemove(realm, group); - for (UserStorageProvider provider : getStorageProviders(session, realm, UserStorageProvider.class)) { - provider.preRemove(realm, group); + if (getFederatedStorage() != null) { + getFederatedStorage().preRemove(realm, group); + for (UserStorageProvider provider : getStorageProviders(session, realm, UserStorageProvider.class)) { + provider.preRemove(realm, group); + } } } @Override public void preRemove(RealmModel realm, RoleModel role) { localStorage().preRemove(realm, role); - getFederatedStorage().preRemove(realm, role); - for (UserStorageProvider provider : getStorageProviders(session, realm, UserStorageProvider.class)) { - provider.preRemove(realm, role); + if (getFederatedStorage() != null) { + getFederatedStorage().preRemove(realm, role); + for (UserStorageProvider provider : getStorageProviders(session, realm, UserStorageProvider.class)) { + provider.preRemove(realm, role); + } } } @Override public void preRemove(RealmModel realm, ClientModel client) { localStorage().preRemove(realm, client); - getFederatedStorage().preRemove(realm, client); + if (getFederatedStorage() != null) getFederatedStorage().preRemove(realm, client); } @Override public void preRemove(ProtocolMapperModel protocolMapper) { localStorage().preRemove(protocolMapper); - getFederatedStorage().preRemove(protocolMapper); + if (getFederatedStorage() != null) getFederatedStorage().preRemove(protocolMapper); } @Override diff --git a/testsuite/integration/pom.xml b/testsuite/integration/pom.xml index 92187bc456..1e92f9b90e 100755 --- a/testsuite/integration/pom.xml +++ b/testsuite/integration/pom.xml @@ -510,6 +510,51 @@ + + mongodb-server + + + localhost + 27018 + keycloak + 127.0.0.1 + + + + + + + + com.github.joelittlejohn.embedmongo + embedmongo-maven-plugin + + + start-mongodb + pre-integration-test + + start + + + ${keycloak.connectionsMongo.port} + file + ${project.build.directory}/mongodb.log + ${keycloak.connectionsMongo.bindIp} + + + + stop-mongodb + post-integration-test + + stop + + + + + + + + + clean-jpa diff --git a/wildfly/server-subsystem/src/main/config/default-server-subsys-config.properties b/wildfly/server-subsystem/src/main/config/default-server-subsys-config.properties index 2355ab0e7e..e29d1bd303 100644 --- a/wildfly/server-subsystem/src/main/config/default-server-subsys-config.properties +++ b/wildfly/server-subsystem/src/main/config/default-server-subsys-config.properties @@ -30,6 +30,9 @@ keycloak.server.subsys.default.config=\ \ jpa\ \ + \ + jpa\ + \ \ \ \