use of io.undertow.servlet.api.DefaultServletConfig in project undertow by undertow-io.
the class ContentTypeFilesTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ContentTypeFilesTestCase.class.getClassLoader()).setContextPath("/app").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(ContentTypeServlet.class)).setDefaultServletConfig(new DefaultServletConfig(true)).addMimeMapping(new MimeMapping("jnlp", "application/x-java-jnlp-file"));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
use of io.undertow.servlet.api.DefaultServletConfig in project undertow by undertow-io.
the class DefaultServlet method init.
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
ServletContextImpl sc = (ServletContextImpl) config.getServletContext();
this.deployment = sc.getDeployment();
DefaultServletConfig defaultServletConfig = deployment.getDeploymentInfo().getDefaultServletConfig();
if (defaultServletConfig != null) {
defaultAllowed = defaultServletConfig.isDefaultAllowed();
allowed = new HashSet<>();
if (defaultServletConfig.getAllowed() != null) {
allowed.addAll(defaultServletConfig.getAllowed());
}
disallowed = new HashSet<>();
if (defaultServletConfig.getDisallowed() != null) {
disallowed.addAll(defaultServletConfig.getDisallowed());
}
}
if (config.getInitParameter(DEFAULT_ALLOWED) != null) {
defaultAllowed = Boolean.parseBoolean(config.getInitParameter(DEFAULT_ALLOWED));
}
if (config.getInitParameter(ALLOWED_EXTENSIONS) != null) {
String extensions = config.getInitParameter(ALLOWED_EXTENSIONS);
allowed = new HashSet<>(Arrays.asList(extensions.split(",")));
}
if (config.getInitParameter(DISALLOWED_EXTENSIONS) != null) {
String extensions = config.getInitParameter(DISALLOWED_EXTENSIONS);
disallowed = new HashSet<>(Arrays.asList(extensions.split(",")));
}
if (config.getInitParameter(RESOLVE_AGAINST_CONTEXT_ROOT) != null) {
resolveAgainstContextRoot = Boolean.parseBoolean(config.getInitParameter(RESOLVE_AGAINST_CONTEXT_ROOT));
}
if (config.getInitParameter(ALLOW_POST) != null) {
allowPost = Boolean.parseBoolean(config.getInitParameter(ALLOW_POST));
}
if (deployment.getDeploymentInfo().getPreCompressedResources().isEmpty()) {
this.resourceSupplier = new DefaultResourceSupplier(deployment.getDeploymentInfo().getResourceManager());
} else {
PreCompressedResourceSupplier preCompressedResourceSupplier = new PreCompressedResourceSupplier(deployment.getDeploymentInfo().getResourceManager());
for (Map.Entry<String, String> entry : deployment.getDeploymentInfo().getPreCompressedResources().entrySet()) {
preCompressedResourceSupplier.addEncoding(entry.getKey(), entry.getValue());
}
this.resourceSupplier = preCompressedResourceSupplier;
}
String listings = config.getInitParameter(DIRECTORY_LISTING);
if (Boolean.valueOf(listings)) {
this.directoryListingEnabled = true;
}
}
use of io.undertow.servlet.api.DefaultServletConfig 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;
}
use of io.undertow.servlet.api.DefaultServletConfig in project keycloak by keycloak.
the class KeycloakServer method start.
public void start() throws Throwable {
long start = System.currentTimeMillis();
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.setApplicationClass(KeycloakApplication.class.getName());
Builder builder = Undertow.builder().addHttpListener(config.getPort(), config.getHost()).setWorkerThreads(config.getWorkerThreads()).setIoThreads(config.getWorkerThreads() / 8);
if (config.getPortHttps() != -1) {
builder = builder.addHttpsListener(config.getPortHttps(), config.getHost(), createSSLContext()).setSocketOption(Options.SSL_CLIENT_AUTH_MODE, SslClientAuthMode.REQUESTED);
}
server = new UndertowJaxrsServer();
try {
server.start(builder);
DeploymentInfo di = server.undertowDeployment(deployment, "");
di.setClassLoader(getClass().getClassLoader());
di.setContextPath("/auth");
di.setDeploymentName("Keycloak");
di.setDefaultEncoding("UTF-8");
di.setDefaultServletConfig(new DefaultServletConfig(true));
// Note that the ResteasyServlet is configured via server.undertowDeployment(...);
// KEYCLOAK-14178
deployment.setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, true);
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);
filter.setAsyncSupported(true);
di.addFilter(filter);
di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST);
server.deploy(di);
sessionFactory = KeycloakApplication.getSessionFactory();
setupDevConfig();
if (config.getResourcesHome() != null) {
info("Loading resources from " + config.getResourcesHome());
}
info("Started Keycloak (http://" + config.getHost() + ":" + config.getPort() + "/auth" + (config.getPortHttps() > 0 ? ", https://" + config.getHost() + ":" + config.getPortHttps() + "/auth" : "") + ") in " + (System.currentTimeMillis() - start) + " ms\n");
} catch (RuntimeException e) {
server.stop();
throw e;
}
}
Aggregations