Make sure user-defined user profile config is set if provided

Closes #48008

Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
This commit is contained in:
Pedro Igor 2026-04-13 17:06:09 -03:00
parent 51449ccf4f
commit 4e4caa2cba
3 changed files with 6 additions and 64 deletions

View file

@ -105,7 +105,6 @@ import org.keycloak.quarkus.runtime.storage.database.jpa.NamedJpaConnectionProvi
import org.keycloak.quarkus.runtime.themes.FlatClasspathThemeResourceProviderFactory;
import org.keycloak.representations.provider.ScriptProviderDescriptor;
import org.keycloak.representations.provider.ScriptProviderMetadata;
import org.keycloak.representations.userprofile.config.UPConfig;
import org.keycloak.services.DefaultKeycloakSessionFactory;
import org.keycloak.services.ServicesLogger;
import org.keycloak.services.resources.LoadBalancerResource;
@ -398,27 +397,6 @@ class KeycloakProcessor {
throw new ConfigurationException(msg);
}
/**
* Parse the default configuration for the User Profile provider
*/
@BuildStep
@Produce(UserProfileBuildItem.class)
UserProfileBuildItem parseDefaultUserProfileConfig() {
UPConfig defaultConfig = UPConfigUtils.parseSystemDefaultConfig();
logger.debug("Parsing default configuration for the User Profile provider");
return new UserProfileBuildItem(defaultConfig);
}
/**
* Set the default configuration to the User Profile provider
*/
@BuildStep
@Consume(ProfileBuildItem.class)
@Record(ExecutionTime.STATIC_INIT)
void setDefaultUserProfileConfig(KeycloakRecorder recorder, UserProfileBuildItem configuration) {
recorder.setDefaultUserProfileConfiguration(configuration.getDefaultConfig());
}
@BuildStep
@Consume(ProfileBuildItem.class)
@Produce(ValidatePersistenceUnitsBuildItem.class)
@ -712,6 +690,8 @@ class KeycloakProcessor {
}
}
recorder.setDefaultUserProfileConfiguration(UPConfigUtils.parseSystemDefaultConfig());
return SyntheticBeanBuildItem.configure(QuarkusKeycloakSessionFactory.class).scope(Singleton.class)
.unremovable()
.runtimeValue(recorder.createSessionFactory(factories, defaultProviders, preConfiguredProviders,

View file

@ -1,37 +0,0 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.quarkus.deployment;
import org.keycloak.representations.userprofile.config.UPConfig;
import io.quarkus.builder.item.SimpleBuildItem;
/**
* Build item that store default configuration for a User Profile provider
*/
public final class UserProfileBuildItem extends SimpleBuildItem {
private final UPConfig defaultConfig;
public UserProfileBuildItem(UPConfig defaultConfig) {
this.defaultConfig = defaultConfig;
}
public UPConfig getDefaultConfig() {
return defaultConfig;
}
}

View file

@ -108,6 +108,7 @@ public class DeclarativeUserProfileProviderFactory implements UserProfileProvide
private static volatile UPConfig PARSED_DEFAULT_RAW_CONFIG;
private final Map<UserProfileContext, UserProfileMetadata> contextualMetadataRegistry = new HashMap<>();
private UPConfig parsedConfig;
public static void setDefaultConfig(UPConfig defaultConfig) {
if (PARSED_DEFAULT_RAW_CONFIG == null) {
@ -396,7 +397,7 @@ public class DeclarativeUserProfileProviderFactory implements UserProfileProvide
*/
protected UserProfileMetadata configureUserProfile(UserProfileMetadata metadata) {
// default metadata for each context is based on the default realm configuration
return new DeclarativeUserProfileProvider(null, this).decorateUserProfileForCache(metadata, PARSED_DEFAULT_RAW_CONFIG);
return new DeclarativeUserProfileProvider(null, this).decorateUserProfileForCache(metadata, parsedConfig);
}
private AttributeValidatorMetadata createReadOnlyAttributeUnchangedValidator(Pattern pattern) {
@ -548,7 +549,7 @@ public class DeclarativeUserProfileProviderFactory implements UserProfileProvide
// GETTER METHODS FOR INTERNAL FIELDS
protected UPConfig getParsedDefaultRawConfig() {
return PARSED_DEFAULT_RAW_CONFIG;
return parsedConfig;
}
protected Map<UserProfileContext, UserProfileMetadata> getContextualMetadataRegistry() {
@ -560,7 +561,7 @@ public class DeclarativeUserProfileProviderFactory implements UserProfileProvide
// The user-defined configuration is always parsed during init and should be avoided as much as possible
// If no user-defined configuration is set, the system default configuration must have been set
// In Quarkus, the system default configuration is set at build time for optimization purposes
UPConfig parsedConfig = ofNullable(config.get("configFile"))
parsedConfig = ofNullable(config.get("configFile"))
.map(Paths::get)
.map(UPConfigUtils::parseConfig)
.orElse(PARSED_DEFAULT_RAW_CONFIG);
@ -569,8 +570,6 @@ public class DeclarativeUserProfileProviderFactory implements UserProfileProvide
if (parsedConfig == null) {
parsedConfig = UPConfigUtils.parseSystemDefaultConfig();
}
setDefaultConfig(parsedConfig);
}
private static Map<String, Object> getEmailAnnotationDecorator(AttributeContext c) {