Search in sources :

Example 1 with KeycloakApplication

use of org.keycloak.services.resources.KeycloakApplication 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;
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) UndertowRequestFilter(org.keycloak.testsuite.UndertowRequestFilter) KeycloakApplication(org.keycloak.services.resources.KeycloakApplication) Filter(javax.servlet.Filter) UndertowRequestFilter(org.keycloak.testsuite.UndertowRequestFilter) IOException(java.io.IOException) DefaultServletConfig(io.undertow.servlet.api.DefaultServletConfig) InstanceHandle(io.undertow.servlet.api.InstanceHandle) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo)

Aggregations

DefaultServletConfig (io.undertow.servlet.api.DefaultServletConfig)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 FilterInfo (io.undertow.servlet.api.FilterInfo)1 InstanceHandle (io.undertow.servlet.api.InstanceHandle)1 IOException (java.io.IOException)1 Filter (javax.servlet.Filter)1 ResteasyDeployment (org.jboss.resteasy.spi.ResteasyDeployment)1 KeycloakApplication (org.keycloak.services.resources.KeycloakApplication)1 UndertowRequestFilter (org.keycloak.testsuite.UndertowRequestFilter)1