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 <tero.saarni@est.tech>
This commit is contained in:
Tero Saarni 2023-10-06 17:36:02 +03:00 committed by GitHub
parent cdb61215c9
commit 22d093f5c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()));
});
}
}