use of org.eclipse.jetty.servlet.DefaultServlet in project jetty.project by eclipse.
the class DatabaseLoginServiceTestServer method configureServer.
protected void configureServer() throws Exception {
_protocol = "http";
_server.addBean(_loginService);
ConstraintSecurityHandler security = new ConstraintSecurityHandler();
_server.setHandler(security);
Constraint constraint = new Constraint();
constraint.setName("auth");
constraint.setAuthenticate(true);
constraint.setRoles(new String[] { "user", "admin" });
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec("/*");
mapping.setConstraint(constraint);
Set<String> knownRoles = new HashSet<>();
knownRoles.add("user");
knownRoles.add("admin");
security.setConstraintMappings(Collections.singletonList(mapping), knownRoles);
security.setAuthenticator(new BasicAuthenticator());
security.setLoginService(_loginService);
ServletContextHandler root = new ServletContextHandler();
root.setContextPath("/");
root.setResourceBase(_resourceBase);
ServletHolder servletHolder = new ServletHolder(new DefaultServlet());
servletHolder.setInitParameter("gzip", "true");
root.addServlet(servletHolder, "/*");
_handler = new TestHandler(_resourceBase);
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { _handler, root });
security.setHandler(handlers);
}
use of org.eclipse.jetty.servlet.DefaultServlet in project platformlayer by platformlayer.
the class StandaloneXaasWebserver method start.
public boolean start() throws Exception {
LogbackHook.attachToRootLogger();
this.server = new Server();
{
SslContextFactory sslContextFactory = new SslContextFactory(SslContextFactory.DEFAULT_KEYSTORE_PATH);
{
CertificateAndKey certificateAndKey = encryptionStore.getCertificateAndKey("https");
String secret = KeyStoreUtils.DEFAULT_KEYSTORE_SECRET;
KeyStore keystore = KeyStoreUtils.createEmpty(secret);
String alias = "https";
KeyStoreUtils.put(keystore, alias, certificateAndKey, secret);
sslContextFactory.setKeyStore(keystore);
sslContextFactory.setKeyStorePassword(secret);
sslContextFactory.setCertAlias(alias);
}
// TODO: Preconfigure a better SSLContext??
SSLContext sslContext = SSLContext.getDefault();
sslContextFactory.setIncludeCipherSuites(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledCipherSuites());
sslContextFactory.setIncludeProtocols(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledProtocols());
SslSelectChannelConnector connector = new SslSelectChannelConnector(sslContextFactory);
connector.setPort(PORT);
String host = configuration.lookup("http.host", null);
if (host != null) {
connector.setHost(host);
}
server.setConnectors(new Connector[] { connector });
}
ContextHandlerCollection contexts = new ContextHandlerCollection();
{
ServletContextHandler context = new ServletContextHandler(contexts, "/api");
// context.setContextPath("/");
context.addEventListener(guiceServletConfig);
// Must add DefaultServlet for embedded Jetty
// Failing to do this will cause 404 errors.
context.addServlet(DefaultServlet.class, "/");
FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
context.addFilter(filterHolder, "*", EnumSet.of(DispatcherType.REQUEST));
context.setClassLoader(Thread.currentThread().getContextClassLoader());
}
for (Entry<String, File> entry : wars.entrySet()) {
String contextPath = entry.getKey();
File war = entry.getValue();
WebAppContext context = new WebAppContext();
context.setWar(war.getAbsolutePath());
context.setContextPath(contextPath);
context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
context.addFilter(GwtCacheHeaderFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
contexts.addHandler(context);
}
server.setHandler(contexts);
server.addLifeCycleListener(new CloseOnFailLifecycleListener());
server.start();
if (!server.isStarted()) {
return false;
}
if (configuration.lookup("jobrunner.enabled", true)) {
scheduler.start();
jobPoller.start();
}
return true;
}
Aggregations