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);
}
}
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);
}
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();
}
Aggregations