Map Store Removal: Remove obsolete KeycloakModelUtils.isUsernameCaseSensitive
method
Closes #27438 Signed-off-by: vramik <vramik@redhat.com>
This commit is contained in:
parent
87993905c8
commit
032bb8e9cc
5 changed files with 4 additions and 30 deletions
|
@ -159,9 +159,6 @@ public final class Constants {
|
||||||
public static final int MINIMUM_LOA = 0;
|
public static final int MINIMUM_LOA = 0;
|
||||||
public static final int NO_LOA = -1;
|
public static final int NO_LOA = -1;
|
||||||
|
|
||||||
public static final Boolean REALM_ATTR_USERNAME_CASE_SENSITIVE_DEFAULT = Boolean.FALSE;
|
|
||||||
public static final String REALM_ATTR_USERNAME_CASE_SENSITIVE = "keycloak.username-search.case-sensitive";
|
|
||||||
|
|
||||||
public static final String SESSION_NOTE_LIGHTWEIGHT_USER = "keycloak.userModel";
|
public static final String SESSION_NOTE_LIGHTWEIGHT_USER = "keycloak.userModel";
|
||||||
|
|
||||||
public static final String USE_LIGHTWEIGHT_ACCESS_TOKEN_ENABLED = "client.use.lightweight.access.token.enabled";
|
public static final String USE_LIGHTWEIGHT_ACCESS_TOKEN_ENABLED = "client.use.lightweight.access.token.enabled";
|
||||||
|
|
|
@ -81,9 +81,6 @@ import org.keycloak.sessions.RootAuthenticationSessionModel;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static org.keycloak.models.Constants.REALM_ATTR_USERNAME_CASE_SENSITIVE;
|
|
||||||
import static org.keycloak.models.Constants.REALM_ATTR_USERNAME_CASE_SENSITIVE_DEFAULT;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set of helper methods, which are useful in various model implementations.
|
* Set of helper methods, which are useful in various model implementations.
|
||||||
*
|
*
|
||||||
|
@ -1004,19 +1001,6 @@ public final class KeycloakModelUtils {
|
||||||
return SecretGenerator.SECRET_LENGTH_256_BITS;
|
return SecretGenerator.SECRET_LENGTH_256_BITS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns <code>true</code> if given realm has attribute {@link Constants#REALM_ATTR_USERNAME_CASE_SENSITIVE}
|
|
||||||
* set and its value is <code>true</code>. Otherwise default value of it is returned. The default setting
|
|
||||||
* can be seen at {@link Constants#REALM_ATTR_USERNAME_CASE_SENSITIVE_DEFAULT}.
|
|
||||||
*
|
|
||||||
* @param realm
|
|
||||||
* @return See the description
|
|
||||||
* @throws NullPointerException if <code>realm</code> is <code>null</code>
|
|
||||||
*/
|
|
||||||
public static boolean isUsernameCaseSensitive(RealmModel realm) {
|
|
||||||
return realm.getAttribute(REALM_ATTR_USERNAME_CASE_SENSITIVE, REALM_ATTR_USERNAME_CASE_SENSITIVE_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default groups on the realm
|
* Sets the default groups on the realm
|
||||||
* @param session
|
* @param session
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.List;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
|
||||||
import org.keycloak.services.messages.Messages;
|
import org.keycloak.services.messages.Messages;
|
||||||
import org.keycloak.services.validation.Validation;
|
import org.keycloak.services.validation.Validation;
|
||||||
import org.keycloak.userprofile.UserProfileAttributeValidationContext;
|
import org.keycloak.userprofile.UserProfileAttributeValidationContext;
|
||||||
|
@ -66,13 +65,11 @@ public class DuplicateUsernameValidator implements SimpleValidator {
|
||||||
UserModel user = UserProfileAttributeValidationContext.from(context).getAttributeContext().getUser();
|
UserModel user = UserProfileAttributeValidationContext.from(context).getAttributeContext().getUser();
|
||||||
String valueLowercased = value.toLowerCase();
|
String valueLowercased = value.toLowerCase();
|
||||||
|
|
||||||
if (! KeycloakModelUtils.isUsernameCaseSensitive(session.getContext().getRealm())) value = valueLowercased;
|
|
||||||
|
|
||||||
RealmModel realm = session.getContext().getRealm();
|
RealmModel realm = session.getContext().getRealm();
|
||||||
if (existing != null && (user == null || !existing.getId().equals(user.getId()))) {
|
if (existing != null && (user == null || !existing.getId().equals(user.getId()))) {
|
||||||
context.addError(new ValidationError(ID, inputHint, Messages.USERNAME_EXISTS)
|
context.addError(new ValidationError(ID, inputHint, Messages.USERNAME_EXISTS)
|
||||||
.setStatusCode(Response.Status.CONFLICT));
|
.setStatusCode(Response.Status.CONFLICT));
|
||||||
} else if (realm.isLoginWithEmailAllowed() && value.indexOf('@') > 0) {
|
} else if (realm.isLoginWithEmailAllowed() && valueLowercased.indexOf('@') > 0) {
|
||||||
// check the username does not collide with an email
|
// check the username does not collide with an email
|
||||||
existing = session.users().getUserByEmail(realm, valueLowercased);
|
existing = session.users().getUserByEmail(realm, valueLowercased);
|
||||||
if (existing != null && (user == null || !existing.getId().equals(user.getId()))) {
|
if (existing != null && (user == null || !existing.getId().equals(user.getId()))) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.util.List;
|
||||||
|
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
|
||||||
import org.keycloak.services.messages.Messages;
|
import org.keycloak.services.messages.Messages;
|
||||||
import org.keycloak.services.validation.Validation;
|
import org.keycloak.services.validation.Validation;
|
||||||
import org.keycloak.userprofile.AttributeContext;
|
import org.keycloak.userprofile.AttributeContext;
|
||||||
|
@ -66,11 +65,10 @@ public class UsernameMutationValidator implements SimpleValidator {
|
||||||
UserModel user = attributeContext.getUser();
|
UserModel user = attributeContext.getUser();
|
||||||
RealmModel realm = context.getSession().getContext().getRealm();
|
RealmModel realm = context.getSession().getContext().getRealm();
|
||||||
|
|
||||||
if (! KeycloakModelUtils.isUsernameCaseSensitive(realm)) value = value.toLowerCase();
|
String valueLowercased = value.toLowerCase();
|
||||||
|
if (!realm.isEditUsernameAllowed() && user != null && !valueLowercased.equals(user.getFirstAttribute(UserModel.USERNAME))) {
|
||||||
if (!realm.isEditUsernameAllowed() && user != null && !value.equals(user.getFirstAttribute(UserModel.USERNAME))) {
|
|
||||||
Attributes attributes = attributeContext.getAttributes();
|
Attributes attributes = attributeContext.getAttributes();
|
||||||
if (realm.isRegistrationEmailAsUsername() && value.equals(attributes.getFirst(UserModel.EMAIL))) {
|
if (realm.isRegistrationEmailAsUsername() && valueLowercased.equals(attributes.getFirst(UserModel.EMAIL))) {
|
||||||
// if username changed is because email as username is allowed so no validation should happen for update profile
|
// if username changed is because email as username is allowed so no validation should happen for update profile
|
||||||
// it is expected that username changes when attributes are normalized by the provider
|
// it is expected that username changes when attributes are normalized by the provider
|
||||||
return context;
|
return context;
|
||||||
|
|
|
@ -49,7 +49,6 @@ import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
import java.util.concurrent.ConcurrentSkipListSet;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
|
||||||
|
|
||||||
import static org.keycloak.storage.UserStorageProviderModel.IMPORT_ENABLED;
|
import static org.keycloak.storage.UserStorageProviderModel.IMPORT_ENABLED;
|
||||||
import static org.keycloak.utils.StreamsUtil.paginatedStream;
|
import static org.keycloak.utils.StreamsUtil.paginatedStream;
|
||||||
|
@ -125,7 +124,6 @@ public class UserMapStorage implements UserLookupProvider, UserStorageProvider,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUsername(String innerUsername) {
|
public void setUsername(String innerUsername) {
|
||||||
innerUsername = KeycloakModelUtils.isUsernameCaseSensitive(realm) ? innerUsername : innerUsername.toLowerCase();
|
|
||||||
if (! Objects.equals(innerUsername, username.toLowerCase())) {
|
if (! Objects.equals(innerUsername, username.toLowerCase())) {
|
||||||
throw new RuntimeException("Unsupported");
|
throw new RuntimeException("Unsupported");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue