Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The getAttributes method in UserAttributeLDAPStorageMapper does not work for email or other UserModel properties #19352

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,6 @@ public Stream<String> getAttributeStream(String name) {
public Map<String, List<String>> getAttributes() {
Map<String, List<String>> attrs = new HashMap<>(super.getAttributes());

// Ignore UserModel properties
if (userModelProperties.get(userModelAttrName.toLowerCase()) != null) {
return attrs;
}

Set<String> allLdapAttrValues = ldapUser.getAttributeAsSet(ldapAttrName);
if (allLdapAttrValues != null) {
attrs.put(userModelAttrName, new ArrayList<>(allLdapAttrValues));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.keycloak.testsuite.federation.ldap;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -122,6 +123,20 @@ protected void afterImportTestRealm() {
@Page
protected LoginPasswordUpdatePage updatePasswordPage;

private static void checkEmailAddressMultipleVariants(KeycloakTestingClient testingClient, String username, String newEmail) {
testingClient.server().run((KeycloakSession session) -> {
LDAPTestContext ctx = LDAPTestContext.init(session);

RealmModel realm = ctx.getRealm();
UserModel user = session.users().getUserByUsername(realm, username);
Assert.assertNotNull("User not found", user);
Assert.assertEquals(newEmail, user.getEmail());
Assert.assertEquals(Collections.singletonList(newEmail), user.getAttributes().get(UserModel.EMAIL));
Assert.assertEquals(Collections.singletonList(newEmail), user.getAttributeStream(UserModel.EMAIL).collect(Collectors.toList()));
});
}


// KEYCLOAK-10852
@Test
public void resetPasswordLink() throws IOException, MessagingException {
Expand All @@ -135,9 +150,8 @@ public void resetPasswordLink() throws IOException, MessagingException {
changeEmailAddressInLDAP(testingClient,"john_new@email.org");

try {
// Search for the user and check email is new address
UserRepresentation john = testRealm().users().search("johnkeycloak").get(0);
Assert.assertEquals("john_new@email.org", john.getEmail());
// Search for the user and check email is new address in the multiple attribute variants
checkEmailAddressMultipleVariants(testingClient, "johnkeycloak", "john_new@email.org");

// Test 1 - Use username on the ResetPassword form. Mail should be sent to new address
triggerForgetPasswordForUser("johnkeycloak", 2, "john_new@email.org");
Expand Down