From 22d093f5c09986b5a4bcfd739b6d709ebd2a459b Mon Sep 17 00:00:00 2001 From: Tero Saarni Date: Fri, 6 Oct 2023 17:36:02 +0300 Subject: [PATCH] Fix multi-valued LDAP attribute support FullName LDAP storage mapper was delegating to single-valued setter even when multi-valued setter was called. Closes #22091 Signed-off-by: Tero Saarni --- .../ldap/LDAPProvidersFullNameMapperTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPProvidersFullNameMapperTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPProvidersFullNameMapperTest.java index d3128b4424..4c713d21d5 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPProvidersFullNameMapperTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPProvidersFullNameMapperTest.java @@ -171,4 +171,36 @@ public class LDAPProvidersFullNameMapperTest extends AbstractLDAPTest { session.users().removeUser(appRealm, fullnameUser); }); } + + // Test for bug https://github.com/keycloak/keycloak/issues/22091 + @Test + public void testMultiValuedAttributes() { + + testingClient.server().run(session -> { + LDAPTestContext ctx = LDAPTestContext.init(session); + RealmModel appRealm = ctx.getRealm(); + + ComponentModel ldapModel = LDAPTestUtils.getLdapProviderModel(appRealm); + LDAPStorageProvider ldapFedProvider = LDAPTestUtils.getLdapProvider(session, ldapModel); + LDAPTestUtils.addLDAPUser(ldapFedProvider, appRealm, "fullname", "James", "Dee", "fullname@email.org", null, "4578"); + }); + + // Add multi-attribute value to the user while fullname mapper is used. + testingClient.server().run(session -> { + LDAPTestContext ctx = LDAPTestContext.init(session); + RealmModel appRealm = ctx.getRealm(); + + UserModel fullnameUser = session.users().getUserByUsername(appRealm, "fullname"); + fullnameUser.setAttribute("roles", Arrays.asList("role1", "role2")); + }); + + // Assert that multi-valued attribute is set. + testingClient.server().run(session -> { + LDAPTestContext ctx = LDAPTestContext.init(session); + RealmModel appRealm = ctx.getRealm(); + + UserModel fullnameUser = session.users().getUserByUsername(appRealm, "fullname"); + Assert.assertEquals(Arrays.asList("role1", "role2"), fullnameUser.getAttributeStream("roles").collect(Collectors.toList())); + }); + } }