From 377fbced4a4dd580ce05c0cf5765bc55e6cb1f4f Mon Sep 17 00:00:00 2001 From: Hynek Mlnarik Date: Fri, 6 Jan 2017 10:00:11 +0100 Subject: [PATCH] KEYCLOAK-4091 Prevent NPE with disabled cache --- .../keycloak/storage/ldap/LDAPStorageProvider.java | 5 ++++- .../storage/ldap/LDAPStorageProviderFactory.java | 6 +++++- .../keycloak/migration/migrators/MigrateTo1_4_0.java | 6 +++++- .../keycloak/credential/OTPCredentialProvider.java | 11 +++++++++-- .../credential/PasswordCredentialProvider.java | 11 +++++++++-- .../java/org/keycloak/storage/UserStorageManager.java | 6 +++++- .../federation/storage/ldap/LDAPSyncTest.java | 6 +++++- 7 files changed, 42 insertions(+), 9 deletions(-) diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java index afdf6684eb..b98d31dfab 100755 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java @@ -637,7 +637,10 @@ public class LDAPStorageProvider implements UserStorageProvider, logger.warnf("User with username [%s] aready exists and is linked to provider [%s] but is not valid. Stale LDAP_ID on local user is: %s", username, model.getName(), user.getFirstAttribute(LDAPConstants.LDAP_ID)); logger.warn("Will re-create user"); - session.userCache().evict(realm, user); + UserCache userCache = session.userCache(); + if (userCache != null) { + userCache.evict(realm, user); + } new UserManager(session).removeUser(realm, user, session.userLocalStorage()); } } diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java index d8d04977b7..317cfaa1c4 100755 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java @@ -34,6 +34,7 @@ import org.keycloak.models.LDAPConstants; import org.keycloak.models.ModelException; import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; +import org.keycloak.models.cache.UserCache; import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.provider.ProviderConfigurationBuilder; @@ -532,7 +533,10 @@ public class LDAPStorageProviderFactory implements UserStorageProviderFactory