Make ProtocolMappers case insensitive

Closes #37577

Signed-off-by: Sebastian Łaskawiec <sebastian.laskawiec@defenseunicorns.com>
Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
Co-authored-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Sebastian Łaskawiec 2025-02-24 09:41:31 +01:00 • committed by Marek Posolda
parent 3ce8064083
commit 5316db251f
2 changed files with 10 additions and 3 deletions

View file

@ -101,13 +101,14 @@ public class ProtocolMapperUtils {
} else {
continue;
}
propertyName = Character.toLowerCase(propertyName.charAt(0)) + propertyName.substring(1);
ACCESSORS.put(propertyName, method);
ACCESSORS.put(getLowerCasedProperty(propertyName), method);
}
}
public static String getUserModelValue(UserModel user, String propertyName) {
Method m = ACCESSORS.get(propertyName);
// To support existing configurations, we accept property names starting with both upper and lower case
// as earlier versions of Keycloak where applying this behavior.
Method m = ACCESSORS.get(getLowerCasedProperty(propertyName));
if (m == null) {
return null;
}
@ -121,6 +122,10 @@ public class ProtocolMapperUtils {
return null;
}
private static String getLowerCasedProperty(String propertyName) {
return Character.toLowerCase(propertyName.charAt(0)) + propertyName.substring(1);
}
/**
* Find the builtin locale mapper.
*

View file

@ -42,7 +42,9 @@ public class ProtocolMapperUtilsTest {
};
Assert.assertEquals("theo", ProtocolMapperUtils.getUserModelValue(useModel, "username"));
Assert.assertEquals("theo", ProtocolMapperUtils.getUserModelValue(useModel, "Username"));
Assert.assertEquals("true", ProtocolMapperUtils.getUserModelValue(useModel, "emailVerified"));
Assert.assertNull(ProtocolMapperUtils.getUserModelValue(useModel, "emailverified"));
Assert.assertNull(ProtocolMapperUtils.getUserModelValue(useModel, "unknown"));
}
}