fix: add a warning log if a deprecated admin env variable is used (#32038)
closes: #31491 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
parent
feddb660af
commit
b72ddbcc45
2 changed files with 19 additions and 2 deletions
|
@ -24,8 +24,11 @@ import org.keycloak.platform.Platform;
|
||||||
import org.keycloak.quarkus.runtime.Environment;
|
import org.keycloak.quarkus.runtime.Environment;
|
||||||
import org.keycloak.quarkus.runtime.cli.command.AbstractNonServerCommand;
|
import org.keycloak.quarkus.runtime.cli.command.AbstractNonServerCommand;
|
||||||
import org.keycloak.quarkus.runtime.configuration.Configuration;
|
import org.keycloak.quarkus.runtime.configuration.Configuration;
|
||||||
|
import org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider;
|
||||||
|
import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper;
|
||||||
import org.keycloak.quarkus.runtime.integration.QuarkusKeycloakSessionFactory;
|
import org.keycloak.quarkus.runtime.integration.QuarkusKeycloakSessionFactory;
|
||||||
import org.keycloak.quarkus.runtime.integration.QuarkusPlatform;
|
import org.keycloak.quarkus.runtime.integration.QuarkusPlatform;
|
||||||
|
import org.keycloak.services.ServicesLogger;
|
||||||
import org.keycloak.services.managers.ApplianceBootstrap;
|
import org.keycloak.services.managers.ApplianceBootstrap;
|
||||||
import org.keycloak.services.resources.KeycloakApplication;
|
import org.keycloak.services.resources.KeycloakApplication;
|
||||||
import org.keycloak.utils.StringUtil;
|
import org.keycloak.utils.StringUtil;
|
||||||
|
@ -72,8 +75,8 @@ public class QuarkusKeycloakApplication extends KeycloakApplication {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createTemporaryAdmin(KeycloakSession session) {
|
protected void createTemporaryAdmin(KeycloakSession session) {
|
||||||
var adminUsername = Configuration.getOptionalKcValue(BootstrapAdminOptions.USERNAME.getKey()).orElse(System.getenv(KEYCLOAK_ADMIN_ENV_VAR));
|
var adminUsername = getOption(BootstrapAdminOptions.USERNAME.getKey(), KEYCLOAK_ADMIN_ENV_VAR);
|
||||||
var adminPassword = Configuration.getOptionalKcValue(BootstrapAdminOptions.PASSWORD.getKey()).orElse(System.getenv(KEYCLOAK_ADMIN_PASSWORD_ENV_VAR));
|
var adminPassword = getOption(BootstrapAdminOptions.PASSWORD.getKey(), KEYCLOAK_ADMIN_PASSWORD_ENV_VAR);
|
||||||
|
|
||||||
var clientId = Configuration.getOptionalKcValue(BootstrapAdminOptions.CLIENT_ID.getKey()).orElse(null);
|
var clientId = Configuration.getOptionalKcValue(BootstrapAdminOptions.CLIENT_ID.getKey()).orElse(null);
|
||||||
var clientSecret = Configuration.getOptionalKcValue(BootstrapAdminOptions.CLIENT_SECRET.getKey()).orElse(null);
|
var clientSecret = Configuration.getOptionalKcValue(BootstrapAdminOptions.CLIENT_SECRET.getKey()).orElse(null);
|
||||||
|
@ -91,6 +94,16 @@ public class QuarkusKeycloakApplication extends KeycloakApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getOption(String option, String envVar) {
|
||||||
|
return Configuration.getOptionalKcValue(option).orElseGet(() -> {
|
||||||
|
String value = System.getenv(envVar);
|
||||||
|
if (value != null) {
|
||||||
|
ServicesLogger.LOGGER.usingDeprecatedEnvironmentVariable(envVar, Configuration.toEnvVarFormat(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + option));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public boolean createTemporaryMasterRealmAdminUser(String adminUserName, String adminPassword, /*Integer adminExpiration,*/ KeycloakSession session) {
|
public boolean createTemporaryMasterRealmAdminUser(String adminUserName, String adminPassword, /*Integer adminExpiration,*/ KeycloakSession session) {
|
||||||
return new ApplianceBootstrap(session).createTemporaryMasterRealmAdminUser(adminUserName, adminPassword /*, adminExpiration*/, false);
|
return new ApplianceBootstrap(session).createTemporaryMasterRealmAdminUser(adminUserName, adminPassword /*, adminExpiration*/, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -476,4 +476,8 @@ public interface ServicesLogger extends BasicLogger {
|
||||||
@Message(id=109, value="Failed to add client '%s' to realm '%s': client with client ID exists")
|
@Message(id=109, value="Failed to add client '%s' to realm '%s': client with client ID exists")
|
||||||
void addClientFailedClientExists(String clientId, String realm);
|
void addClientFailedClientExists(String clientId, String realm);
|
||||||
|
|
||||||
|
@LogMessage(level = WARN)
|
||||||
|
@Message(id=110, value="Environment variable '%s' is deprecated, use '%s' instead")
|
||||||
|
void usingDeprecatedEnvironmentVariable(String deprecated, String supported);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue