Search in sources :

Example 26 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project elasticsearch-jetty by sonian.

the class RestConstraintSecurityHandlerTests method createServer.

@BeforeMethod
public void createServer() {
    server = new Server();
    connector = new LocalConnector();
    server.addConnector(connector);
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 27 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class JaspiTest method before.

@Before
public void before() throws Exception {
    System.setProperty("org.apache.geronimo.jaspic.configurationFile", "src/test/resources/jaspi.xml");
    _server = new Server();
    _connector = new LocalConnector(_server);
    _server.addConnector(_connector);
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    _server.setHandler(contexts);
    TestLoginService loginService = new TestLoginService("TestRealm");
    loginService.putUser("user", new Password("password"), new String[] { "users" });
    loginService.putUser("admin", new Password("secret"), new String[] { "users", "admins" });
    _server.addBean(loginService);
    ContextHandler context = new ContextHandler();
    contexts.addHandler(context);
    context.setContextPath("/ctx");
    JaspiAuthenticatorFactory jaspiAuthFactory = new JaspiAuthenticatorFactory();
    ConstraintSecurityHandler security = new ConstraintSecurityHandler();
    context.setHandler(security);
    security.setAuthenticatorFactory(jaspiAuthFactory);
    // security.setAuthenticator(new BasicAuthenticator());
    Constraint constraint = new Constraint("All", "users");
    constraint.setAuthenticate(true);
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec("/jaspi/*");
    mapping.setConstraint(constraint);
    security.addConstraintMapping(mapping);
    TestHandler handler = new TestHandler();
    security.setHandler(handler);
    ContextHandler other = new ContextHandler();
    contexts.addHandler(other);
    other.setContextPath("/other");
    ConstraintSecurityHandler securityOther = new ConstraintSecurityHandler();
    other.setHandler(securityOther);
    securityOther.setAuthenticatorFactory(jaspiAuthFactory);
    securityOther.addConstraintMapping(mapping);
    securityOther.setHandler(new TestHandler());
    _server.start();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Server(org.eclipse.jetty.server.Server) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) LocalConnector(org.eclipse.jetty.server.LocalConnector) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) Password(org.eclipse.jetty.util.security.Password) Before(org.junit.Before)

Example 28 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class AllowSymLinkAliasCheckerTest method setupServer.

private void setupServer() throws Exception {
    // Setup server
    server = new Server();
    localConnector = new LocalConnector(server);
    server.addConnector(localConnector);
    ResourceHandler fileResourceHandler = new ResourceHandler();
    fileResourceHandler.setDirectoriesListed(true);
    fileResourceHandler.setWelcomeFiles(new String[] { "index.html" });
    fileResourceHandler.setEtags(true);
    ContextHandler fileResourceContext = new ContextHandler();
    fileResourceContext.setContextPath("/");
    fileResourceContext.setAllowNullPathInfo(true);
    fileResourceContext.setHandler(fileResourceHandler);
    fileResourceContext.setBaseResource(new PathResource(rootPath));
    fileResourceContext.clearAliasChecks();
    fileResourceContext.addAliasCheck(new AllowSymLinkAliasChecker());
    server.setHandler(fileResourceContext);
    server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) PathResource(org.eclipse.jetty.util.resource.PathResource) LocalConnector(org.eclipse.jetty.server.LocalConnector)

Example 29 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class BufferedResponseHandlerTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    _server = new Server();
    _config = new HttpConfiguration();
    _config.setOutputBufferSize(1024);
    _config.setOutputAggregationSize(256);
    _local = new LocalConnector(_server, new HttpConnectionFactory(_config));
    _server.addConnector(_local);
    _bufferedHandler = new BufferedResponseHandler();
    _bufferedHandler.getPathIncludeExclude().include("/include/*");
    _bufferedHandler.getPathIncludeExclude().exclude("*.exclude");
    _bufferedHandler.getMimeIncludeExclude().exclude("text/excluded");
    _bufferedHandler.setHandler(_test = new TestHandler());
    _contextHandler = new ContextHandler("/ctx");
    _contextHandler.setHandler(_bufferedHandler);
    _server.setHandler(_contextHandler);
    _server.start();
// BufferedResponseHandler.LOG.setDebugEnabled(true);
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) BeforeClass(org.junit.BeforeClass)

Example 30 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class ContextHandlerCollectionTest method testVirtualHostWildcard.

@Test
public void testVirtualHostWildcard() throws Exception {
    Server server = new Server();
    LocalConnector connector = new LocalConnector(server);
    server.setConnectors(new Connector[] { connector });
    ContextHandler context = new ContextHandler("/");
    IsHandledHandler handler = new IsHandledHandler("H");
    context.setHandler(handler);
    ContextHandlerCollection c = new ContextHandlerCollection();
    c.addHandler(context);
    server.setHandler(c);
    try {
        server.start();
        checkWildcardHost(true, server, null, new String[] { "example.com", ".example.com", "vhost.example.com" });
        checkWildcardHost(false, server, new String[] { null }, new String[] { "example.com", ".example.com", "vhost.example.com" });
        checkWildcardHost(true, server, new String[] { "example.com", "*.example.com" }, new String[] { "example.com", ".example.com", "vhost.example.com" });
        checkWildcardHost(false, server, new String[] { "example.com", "*.example.com" }, new String[] { "badexample.com", ".badexample.com", "vhost.badexample.com" });
        checkWildcardHost(false, server, new String[] { "*." }, new String[] { "anything.anything" });
        checkWildcardHost(true, server, new String[] { "*.example.com" }, new String[] { "vhost.example.com", ".example.com" });
        checkWildcardHost(false, server, new String[] { "*.example.com" }, new String[] { "vhost.www.example.com", "example.com", "www.vhost.example.com" });
        checkWildcardHost(true, server, new String[] { "*.sub.example.com" }, new String[] { "vhost.sub.example.com", ".sub.example.com" });
        checkWildcardHost(false, server, new String[] { "*.sub.example.com" }, new String[] { ".example.com", "sub.example.com", "vhost.example.com" });
        checkWildcardHost(false, server, new String[] { "example.*.com", "example.com.*" }, new String[] { "example.vhost.com", "example.com.vhost", "example.com" });
    } finally {
        server.stop();
    }
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) Test(org.junit.Test)

Aggregations

LocalConnector (org.eclipse.jetty.server.LocalConnector)47 Server (org.eclipse.jetty.server.Server)43 Before (org.junit.Before)20 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)13 Test (org.junit.Test)12 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BeforeClass (org.junit.BeforeClass)7 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)6 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)4 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)4 Password (org.eclipse.jetty.util.security.Password)4 File (java.io.File)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 HandlerList (org.eclipse.jetty.server.handler.HandlerList)3 Path (java.nio.file.Path)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2