From d66030fcadf48eab8b2f8dc34a3d30921283c5e3 Mon Sep 17 00:00:00 2001 From: Stefan Guilhen Date: Mon, 28 Oct 2024 18:27:30 -0300 Subject: [PATCH] Check if LDAPObject is available from a previously cached proxied user Closes #34412 Signed-off-by: Stefan Guilhen --- .../storage/ldap/LDAPStorageUserManager.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageUserManager.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageUserManager.java index 798f188266..3c035d4003 100644 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageUserManager.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageUserManager.java @@ -45,7 +45,13 @@ public class LDAPStorageUserManager { } public LDAPObject getManagedLDAPObject(String userId) { - return managedLDAPObjects.get(userId); + ManagedUserEntry entry = managedUsers.get(userId); + if (entry != null) { + return entry.getLdapUser(); + } + else { + return managedLDAPObjects.get(userId); + } } public void setManagedLDAPObject(String userId, LDAPObject ldapObject) { @@ -74,7 +80,7 @@ public class LDAPStorageUserManager { } LDAPTransaction ldapTransaction = new LDAPTransaction(provider, ldapObject); - ManagedUserEntry newEntry = new ManagedUserEntry(proxiedUser, ldapTransaction); + ManagedUserEntry newEntry = new ManagedUserEntry(proxiedUser, ldapObject, ldapTransaction); managedUsers.put(userId, newEntry); } @@ -87,10 +93,12 @@ public class LDAPStorageUserManager { private static class ManagedUserEntry { private final UserModel managedProxiedUser; + private final LDAPObject ldapUser; private final LDAPTransaction ldapTransaction; - public ManagedUserEntry(UserModel managedProxiedUser, LDAPTransaction ldapTransaction) { + public ManagedUserEntry(UserModel managedProxiedUser, LDAPObject ldapUser, LDAPTransaction ldapTransaction) { this.managedProxiedUser = managedProxiedUser; + this.ldapUser = ldapUser; this.ldapTransaction = ldapTransaction; } @@ -98,6 +106,10 @@ public class LDAPStorageUserManager { return managedProxiedUser; } + public LDAPObject getLdapUser() { + return ldapUser; + } + public LDAPTransaction getLdapTransaction() { return ldapTransaction; }