use of org.keycloak.services.DefaultKeycloakSessionFactory in project keycloak by keycloak.
the class PlainTextVaultProviderFactoryTest method shouldInitializeVaultCorrectly.
@Test
public void shouldInitializeVaultCorrectly() {
// given
VaultConfig config = new VaultConfig(Scenario.EXISTING.getAbsolutePathAsString());
KeycloakSession session = new DefaultKeycloakSession(new DefaultKeycloakSessionFactory());
FilesPlainTextVaultProviderFactory factory = new FilesPlainTextVaultProviderFactory() {
@Override
protected String getRealmName(KeycloakSession session) {
return "test";
}
};
// when
factory.init(config);
VaultProvider provider = factory.create(session);
// then
assertNotNull(provider);
}
use of org.keycloak.services.DefaultKeycloakSessionFactory in project keycloak by keycloak.
the class KeycloakModelTest method createKeycloakSessionFactory.
/**
* Creates a fresh initialized {@link KeycloakSessionFactory}. The returned factory uses configuration
* local to the thread that calls this method, allowing for per-thread customization. This in turn allows
* testing of several parallel session factories which can be used to simulate several servers
* running in parallel.
* @return
*/
public static KeycloakSessionFactory createKeycloakSessionFactory() {
int factoryIndex = FACTORY_COUNT.incrementAndGet();
String threadName = Thread.currentThread().getName();
CONFIG.reset();
CONFIG.spi(ComponentFactorySpi.NAME).provider(DefaultComponentFactoryProviderFactory.PROVIDER_ID).config("cachingForced", "true");
MODEL_PARAMETERS.forEach(m -> m.updateConfig(CONFIG));
LOG.debugf("Creating factory %d in %s using the following configuration:\n %s", factoryIndex, threadName, CONFIG);
DefaultKeycloakSessionFactory res = new DefaultKeycloakSessionFactory() {
@Override
protected boolean isEnabled(ProviderFactory factory, Scope scope) {
return super.isEnabled(factory, scope) && isFactoryAllowed(factory);
}
@Override
protected Map<Class<? extends Provider>, Map<String, ProviderFactory>> loadFactories(ProviderManager pm) {
spis.removeIf(s -> !isSpiAllowed(s));
return super.loadFactories(pm);
}
private boolean isSpiAllowed(Spi s) {
return MODEL_PARAMETERS.stream().anyMatch(p -> p.isSpiAllowed(s));
}
private boolean isFactoryAllowed(ProviderFactory factory) {
return MODEL_PARAMETERS.stream().anyMatch(p -> p.isFactoryAllowed(factory));
}
@Override
public String toString() {
return "KeycloakSessionFactory " + factoryIndex + " (from " + threadName + " thread)";
}
};
res.init();
res.publish(new PostMigrationEvent());
return res;
}
use of org.keycloak.services.DefaultKeycloakSessionFactory in project keycloak by keycloak.
the class DefaultHttpClientFactoryTest method createHttpClientProviderWithDisableTrustManager.
@Test
public void createHttpClientProviderWithDisableTrustManager() throws IOException {
Map<String, String> values = new HashMap<>();
values.put(DISABLE_TRUST_MANAGER_PROPERTY, "true");
DefaultHttpClientFactory factory = new DefaultHttpClientFactory();
factory.init(scope(values));
KeycloakSession session = new DefaultKeycloakSession(new DefaultKeycloakSessionFactory());
HttpClientProvider provider = factory.create(session);
Optional<String> testURL = getTestURL();
Assume.assumeTrue("Could not get test url for domain", testURL.isPresent());
try (CloseableHttpClient httpClient = (CloseableHttpClient) provider.getHttpClient();
CloseableHttpResponse response = httpClient.execute(new HttpGet(testURL.get()))) {
assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
}
}
use of org.keycloak.services.DefaultKeycloakSessionFactory in project keycloak by keycloak.
the class DefaultHttpClientFactoryTest method createHttpClientProviderWithUnvailableURL.
@Test(expected = SSLPeerUnverifiedException.class)
public void createHttpClientProviderWithUnvailableURL() throws IOException {
DefaultHttpClientFactory factory = new DefaultHttpClientFactory();
factory.init(scope(new HashMap<>()));
KeycloakSession session = new DefaultKeycloakSession(new DefaultKeycloakSessionFactory());
HttpClientProvider provider = factory.create(session);
try (CloseableHttpClient httpClient = (CloseableHttpClient) provider.getHttpClient()) {
Optional<String> testURL = getTestURL();
Assume.assumeTrue("Could not get test url for domain", testURL.isPresent());
httpClient.execute(new HttpGet(testURL.get()));
}
}
use of org.keycloak.services.DefaultKeycloakSessionFactory in project keycloak by keycloak.
the class KeycloakApplication method createSessionFactory.
public static KeycloakSessionFactory createSessionFactory() {
DefaultKeycloakSessionFactory factory = new DefaultKeycloakSessionFactory();
factory.init();
return factory;
}
Aggregations