use of org.keycloak.testsuite.UndertowRequestFilter in project keycloak by keycloak.
the class KeycloakOnUndertow method createAuthServerDeploymentInfo.
private DeploymentInfo createAuthServerDeploymentInfo() {
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.setApplicationClass(KeycloakApplication.class.getName());
// RESTEASY-2034
deployment.setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, true);
// Prevent double gzip encoding of resources
deployment.getDisabledProviderClasses().add("org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor");
DeploymentInfo di = undertow.undertowDeployment(deployment);
di.setClassLoader(getClass().getClassLoader());
di.setContextPath("/auth");
di.setDeploymentName("Keycloak");
if (configuration.getKeycloakConfigPropertyOverridesMap() != null) {
try {
di.addInitParameter(JsonConfigProviderFactory.SERVER_CONTEXT_CONFIG_PROPERTY_OVERRIDES, JsonSerialization.writeValueAsString(configuration.getKeycloakConfigPropertyOverridesMap()));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
di.setDefaultServletConfig(new DefaultServletConfig(true));
di.addWelcomePage("theme/keycloak/welcome/resources/index.html");
// This is needed as in case of clustered undertow, several undertow instances share the same JVM, hence the default
// way accessing the factory in the UndertowRequestFilter via static reference to KeycloakApplication does not work:
// There are several KeycloakApplication instances in the JVM with no classloader separation as in a full-blown server.
InstanceHandle<Filter> filterInstance = new InstanceHandle<Filter>() {
@Override
public Filter getInstance() {
return new UndertowRequestFilter(sessionFactory);
}
@Override
public void release() {
}
};
FilterInfo filter = Servlets.filter("SessionFilter", UndertowRequestFilter.class, () -> filterInstance);
di.addFilter(filter);
di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST);
filter.setAsyncSupported(true);
return di;
}
Aggregations