Search in sources :

Example 1 with AllowSymLinkAliasChecker

use of org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker in project jetty.project by eclipse.

the class DefaultServletTest method testSymLinks.

@Test
public void testSymLinks() throws Exception {
    testdir.ensureEmpty();
    File resBase = testdir.getPathFile("docroot").toFile();
    FS.ensureDirExists(resBase);
    File dir = new File(resBase, "dir");
    File dirLink = new File(resBase, "dirlink");
    File dirRLink = new File(resBase, "dirrlink");
    FS.ensureDirExists(dir);
    File foobar = new File(dir, "foobar.txt");
    File link = new File(dir, "link.txt");
    File rLink = new File(dir, "rlink.txt");
    createFile(foobar, "Foo Bar");
    String resBasePath = resBase.getAbsolutePath();
    ServletHolder defholder = context.addServlet(DefaultServlet.class, "/");
    defholder.setInitParameter("resourceBase", resBasePath);
    defholder.setInitParameter("gzip", "false");
    String response;
    response = connector.getResponse("GET /context/dir/foobar.txt HTTP/1.0\r\n\r\n");
    assertResponseContains("Foo Bar", response);
    if (!OS.IS_WINDOWS) {
        context.clearAliasChecks();
        Files.createSymbolicLink(dirLink.toPath(), dir.toPath());
        Files.createSymbolicLink(dirRLink.toPath(), new File("dir").toPath());
        Files.createSymbolicLink(link.toPath(), foobar.toPath());
        Files.createSymbolicLink(rLink.toPath(), new File("foobar.txt").toPath());
        response = connector.getResponse("GET /context/dir/link.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("404", response);
        response = connector.getResponse("GET /context/dir/rlink.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("404", response);
        response = connector.getResponse("GET /context/dirlink/foobar.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("404", response);
        response = connector.getResponse("GET /context/dirrlink/foobar.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("404", response);
        response = connector.getResponse("GET /context/dirlink/link.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("404", response);
        response = connector.getResponse("GET /context/dirrlink/rlink.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("404", response);
        context.addAliasCheck(new AllowSymLinkAliasChecker());
        response = connector.getResponse("GET /context/dir/link.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("Foo Bar", response);
        response = connector.getResponse("GET /context/dir/rlink.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("Foo Bar", response);
        response = connector.getResponse("GET /context/dirlink/foobar.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("Foo Bar", response);
        response = connector.getResponse("GET /context/dirrlink/foobar.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("Foo Bar", response);
        response = connector.getResponse("GET /context/dirlink/link.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("Foo Bar", response);
        response = connector.getResponse("GET /context/dirrlink/link.txt HTTP/1.0\r\n\r\n");
        assertResponseContains("Foo Bar", response);
    }
}
Also used : AllowSymLinkAliasChecker(org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker) File(java.io.File) Test(org.junit.Test)

Example 2 with AllowSymLinkAliasChecker

use of org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker in project jena by apache.

the class JettyFuseki method buildServerWebapp.

private void buildServerWebapp(String contextPath, String jettyConfig) {
    if (jettyConfig != null)
        // --jetty-config=jetty-fuseki.xml
        // for detailed configuration of the server using Jetty features.
        configServer(jettyConfig);
    else
        defaultServerConfig(serverConfig.port, serverConfig.loopback);
    WebAppContext webapp = createWebApp(contextPath);
    if (false) /*enable symbolic links */
    {
        // See http://www.eclipse.org/jetty/documentation/current/serving-aliased-files.html
        // Record what would be needed:
        // 1 - Allow all symbolic links without checking
        webapp.addAliasCheck(new ContextHandler.ApproveAliases());
        // 2 - Check links are to valid resources. But default for Unix?
        webapp.addAliasCheck(new AllowSymLinkAliasChecker());
    }
    servletContext = webapp.getServletContext();
    server.setHandler(webapp);
    // Replaced by Shiro.
    if (jettyConfig == null && serverConfig.authConfigFile != null)
        security(webapp, serverConfig.authConfigFile);
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) AllowSymLinkAliasChecker(org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker)

Example 3 with AllowSymLinkAliasChecker

use of org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker in project jetty.project by eclipse.

the class GCloudSessionTester method main.

public static void main(String[] args) throws Exception {
    if (args.length < 4)
        System.err.println("Usage: GCloudSessionTester projectid p12file password serviceaccount");
    System.setProperty("org.eclipse.jetty.server.session.LEVEL", "DEBUG");
    Server server = new Server(8080);
    HashLoginService loginService = new HashLoginService();
    loginService.setName("Test Realm");
    loginService.setConfig("../../jetty-distribution/target/distribution/demo-base/resources/realm.properties");
    server.addBean(loginService);
    DefaultSessionIdManager idmgr = new DefaultSessionIdManager(server);
    idmgr.setWorkerName("w1");
    server.setSessionIdManager(idmgr);
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar("../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
    webapp.addAliasCheck(new AllowSymLinkAliasChecker());
    GCloudSessionDataStore ds = new GCloudSessionDataStore();
    DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler());
    webapp.getSessionHandler().setSessionCache(ss);
    ss.setSessionDataStore(ds);
    webapp.getSessionHandler().setSessionIdManager(idmgr);
    // A WebAppContext is a ContextHandler as well so it needs to be set to
    // the server so it is aware of where to send the appropriate requests.
    server.setHandler(webapp);
    // Start things up! 
    server.start();
    server.join();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) DefaultSessionCache(org.eclipse.jetty.server.session.DefaultSessionCache) HashLoginService(org.eclipse.jetty.security.HashLoginService) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) AllowSymLinkAliasChecker(org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker) Server(org.eclipse.jetty.server.Server)

Aggregations

AllowSymLinkAliasChecker (org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker)3 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)2 File (java.io.File)1 HashLoginService (org.eclipse.jetty.security.HashLoginService)1 Server (org.eclipse.jetty.server.Server)1 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)1 DefaultSessionCache (org.eclipse.jetty.server.session.DefaultSessionCache)1 DefaultSessionIdManager (org.eclipse.jetty.server.session.DefaultSessionIdManager)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 Test (org.junit.Test)1