From 18cef60bbd3ba9989d15668b17dd0a80a0852fbe Mon Sep 17 00:00:00 2001 From: Martin Bartos Date: Wed, 18 Aug 2021 14:15:34 +0200 Subject: [PATCH] KEYCLOAK-19037 Problems with validation of Email field that contains uppercase character --- .../userprofile/DefaultAttributes.java | 9 +- .../updaters/RealmAttributeUpdater.java | 20 ++ .../testsuite/forms/RegisterTest.java | 273 ++++++++++-------- 3 files changed, 186 insertions(+), 116 deletions(-) diff --git a/server-spi-private/src/main/java/org/keycloak/userprofile/DefaultAttributes.java b/server-spi-private/src/main/java/org/keycloak/userprofile/DefaultAttributes.java index c08a6b011c..e9e6a89264 100644 --- a/server-spi-private/src/main/java/org/keycloak/userprofile/DefaultAttributes.java +++ b/server-spi-private/src/main/java/org/keycloak/userprofile/DefaultAttributes.java @@ -24,9 +24,11 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Consumer; +import java.util.stream.Collectors; import org.keycloak.models.Constants; import org.keycloak.models.KeycloakSession; @@ -304,7 +306,12 @@ public class DefaultAttributes extends HashMap> implements List email = newAttributes.get(UserModel.EMAIL); if (email != null && realm.isRegistrationEmailAsUsername()) { - newAttributes.put(UserModel.USERNAME, email); + final List lowerCaseEmailList = email.stream() + .filter(Objects::nonNull) + .map(String::toLowerCase) + .collect(Collectors.toList()); + + newAttributes.put(UserModel.USERNAME, lowerCaseEmailList); } return newAttributes; diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/updaters/RealmAttributeUpdater.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/updaters/RealmAttributeUpdater.java index 533706de0e..03398384b2 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/updaters/RealmAttributeUpdater.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/updaters/RealmAttributeUpdater.java @@ -72,4 +72,24 @@ public class RealmAttributeUpdater extends ServerResourceUpdater