Keycloak server fails to start when using different named schema
Closes #12219
This commit is contained in:
parent
9272c7a5ec
commit
c18b87af5f
7 changed files with 80 additions and 17 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -489,7 +489,7 @@ jobs:
|
||||||
|
|
||||||
- name: Run Quarkus Storage Tests
|
- name: Run Quarkus Storage Tests
|
||||||
run: |
|
run: |
|
||||||
./mvnw clean install -nsu -B -f quarkus/tests/pom.xml -Ptest-database -Dtest=PostgreSQLDistTest | misc/log/trimmer.sh
|
./mvnw clean install -nsu -B -f quarkus/tests/pom.xml -Ptest-database -Dtest=PostgreSQLDistTest,DatabaseOptionsDistTest | misc/log/trimmer.sh
|
||||||
TEST_RESULT=${PIPESTATUS[0]}
|
TEST_RESULT=${PIPESTATUS[0]}
|
||||||
find . -path '*/target/surefire-reports/*.xml' | zip -q reports-quarkus-tests.zip -@
|
find . -path '*/target/surefire-reports/*.xml' | zip -q reports-quarkus-tests.zip -@
|
||||||
exit $TEST_RESULT
|
exit $TEST_RESULT
|
||||||
|
|
|
@ -111,7 +111,6 @@ import org.keycloak.policy.BlacklistPasswordPolicyProviderFactory;
|
||||||
import org.keycloak.protocol.ProtocolMapperSpi;
|
import org.keycloak.protocol.ProtocolMapperSpi;
|
||||||
import org.keycloak.protocol.oidc.mappers.DeployedScriptOIDCProtocolMapper;
|
import org.keycloak.protocol.oidc.mappers.DeployedScriptOIDCProtocolMapper;
|
||||||
import org.keycloak.provider.EnvironmentDependentProviderFactory;
|
import org.keycloak.provider.EnvironmentDependentProviderFactory;
|
||||||
import org.keycloak.provider.KeycloakDeploymentInfo;
|
|
||||||
import org.keycloak.provider.Provider;
|
import org.keycloak.provider.Provider;
|
||||||
import org.keycloak.provider.ProviderFactory;
|
import org.keycloak.provider.ProviderFactory;
|
||||||
import org.keycloak.provider.ProviderManager;
|
import org.keycloak.provider.ProviderManager;
|
||||||
|
@ -217,11 +216,13 @@ class KeycloakProcessor {
|
||||||
if ("keycloak-default".equals(descriptor.getName())) {
|
if ("keycloak-default".equals(descriptor.getName())) {
|
||||||
configureJpaProperties(descriptor, config, jdbcDataSources);
|
configureJpaProperties(descriptor, config, jdbcDataSources);
|
||||||
configureJpaModel(descriptor, indexBuildItem);
|
configureJpaModel(descriptor, indexBuildItem);
|
||||||
|
runtimeConfigured.produce(new HibernateOrmIntegrationRuntimeConfiguredBuildItem("keycloak", descriptor.getName())
|
||||||
|
.setInitListener(recorder.createDefaultUnitListener()));
|
||||||
} else {
|
} else {
|
||||||
Properties properties = descriptor.getProperties();
|
Properties properties = descriptor.getProperties();
|
||||||
// register a listener for customizing the unit configuration at runtime
|
// register a listener for customizing the unit configuration at runtime
|
||||||
runtimeConfigured.produce(new HibernateOrmIntegrationRuntimeConfiguredBuildItem("keycloak", descriptor.getName())
|
runtimeConfigured.produce(new HibernateOrmIntegrationRuntimeConfiguredBuildItem("keycloak", descriptor.getName())
|
||||||
.setInitListener(recorder.createUnitListener(properties.getProperty(AvailableSettings.DATASOURCE))));
|
.setInitListener(recorder.createUserDefinedUnitListener(properties.getProperty(AvailableSettings.DATASOURCE))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import io.quarkus.smallrye.metrics.runtime.SmallRyeMetricsHandler;
|
||||||
import io.vertx.core.Handler;
|
import io.vertx.core.Handler;
|
||||||
import io.vertx.ext.web.RoutingContext;
|
import io.vertx.ext.web.RoutingContext;
|
||||||
import org.keycloak.common.Profile;
|
import org.keycloak.common.Profile;
|
||||||
|
import org.keycloak.quarkus.runtime.configuration.Configuration;
|
||||||
import org.keycloak.quarkus.runtime.integration.QuarkusKeycloakSessionFactory;
|
import org.keycloak.quarkus.runtime.integration.QuarkusKeycloakSessionFactory;
|
||||||
import org.keycloak.quarkus.runtime.storage.database.liquibase.FastServiceLocator;
|
import org.keycloak.quarkus.runtime.storage.database.liquibase.FastServiceLocator;
|
||||||
import org.keycloak.provider.Provider;
|
import org.keycloak.provider.Provider;
|
||||||
|
@ -101,7 +102,7 @@ public class KeycloakRecorder {
|
||||||
return metricsHandler;
|
return metricsHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HibernateOrmIntegrationRuntimeInitListener createUnitListener(String name) {
|
public HibernateOrmIntegrationRuntimeInitListener createUserDefinedUnitListener(String name) {
|
||||||
return new HibernateOrmIntegrationRuntimeInitListener() {
|
return new HibernateOrmIntegrationRuntimeInitListener() {
|
||||||
@Override
|
@Override
|
||||||
public void contributeRuntimeProperties(BiConsumer<String, Object> propertyCollector) {
|
public void contributeRuntimeProperties(BiConsumer<String, Object> propertyCollector) {
|
||||||
|
@ -119,4 +120,13 @@ public class KeycloakRecorder {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HibernateOrmIntegrationRuntimeInitListener createDefaultUnitListener() {
|
||||||
|
return new HibernateOrmIntegrationRuntimeInitListener() {
|
||||||
|
@Override
|
||||||
|
public void contributeRuntimeProperties(BiConsumer<String, Object> propertyCollector) {
|
||||||
|
propertyCollector.accept(AvailableSettings.DEFAULT_SCHEMA, Configuration.getRawValue("kc.db-schema"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.keycloak.it.junit5.extension;
|
package org.keycloak.it.junit5.extension;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.testcontainers.containers.JdbcDatabaseContainer;
|
import org.testcontainers.containers.JdbcDatabaseContainer;
|
||||||
import org.testcontainers.containers.MariaDBContainer;
|
import org.testcontainers.containers.MariaDBContainer;
|
||||||
import org.testcontainers.containers.PostgreSQLContainer;
|
import org.testcontainers.containers.PostgreSQLContainer;
|
||||||
|
@ -37,7 +38,8 @@ public class DatabaseContainer {
|
||||||
container = createContainer()
|
container = createContainer()
|
||||||
.withDatabaseName("keycloak")
|
.withDatabaseName("keycloak")
|
||||||
.withUsername(getUsername())
|
.withUsername(getUsername())
|
||||||
.withPassword(getPassword());
|
.withPassword(getPassword())
|
||||||
|
.withInitScript(resolveInitScript());
|
||||||
|
|
||||||
container.withStartupTimeout(Duration.ofMinutes(5)).start();
|
container.withStartupTimeout(Duration.ofMinutes(5)).start();
|
||||||
}
|
}
|
||||||
|
@ -73,4 +75,8 @@ public class DatabaseContainer {
|
||||||
throw new RuntimeException("Unsupported database: " + alias);
|
throw new RuntimeException("Unsupported database: " + alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String resolveInitScript() {
|
||||||
|
return String.format("database/scripts/init-%s.sql", alias);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2021 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
CREATE SCHEMA foo;
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2021 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.it.storage.database.dist;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.keycloak.it.junit5.extension.CLIResult;
|
||||||
|
import org.keycloak.it.junit5.extension.DistributionTest;
|
||||||
|
import org.keycloak.it.junit5.extension.WithDatabase;
|
||||||
|
|
||||||
|
import io.quarkus.test.junit.main.Launch;
|
||||||
|
import io.quarkus.test.junit.main.LaunchResult;
|
||||||
|
|
||||||
|
@DistributionTest
|
||||||
|
@WithDatabase(alias = "postgres")
|
||||||
|
public class DatabaseOptionsDistTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Launch({ "start-dev", "--db-schema=foo" })
|
||||||
|
void testSetSchema(LaunchResult result) {
|
||||||
|
CLIResult cliResult = (CLIResult) result;
|
||||||
|
cliResult.assertStartedDevMode();
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,22 +17,12 @@
|
||||||
|
|
||||||
package org.keycloak.it.storage.database.dist;
|
package org.keycloak.it.storage.database.dist;
|
||||||
|
|
||||||
import org.keycloak.it.junit5.extension.CLIResult;
|
|
||||||
import org.keycloak.it.junit5.extension.CLITest;
|
import org.keycloak.it.junit5.extension.CLITest;
|
||||||
import org.keycloak.it.junit5.extension.WithDatabase;
|
import org.keycloak.it.junit5.extension.WithDatabase;
|
||||||
import org.keycloak.it.storage.database.BasicDatabaseTest;
|
import org.keycloak.it.storage.database.MariaDBTest;
|
||||||
|
|
||||||
@CLITest
|
@CLITest
|
||||||
@WithDatabase(alias = "mariadb")
|
@WithDatabase(alias = "mariadb")
|
||||||
public class MariaDBDistTest extends BasicDatabaseTest {
|
public class MariaDBDistTest extends MariaDBTest {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assertWrongPassword(CLIResult cliResult) {
|
|
||||||
cliResult.assertMessage("Access denied for user");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assertWrongUsername(CLIResult cliResult) {
|
|
||||||
cliResult.assertMessage("Access denied for user 'wrong'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue