org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker Java Examples

The following examples show how to use org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyAppServer.java    From selenium with Apache License 2.0 6 votes vote down vote up
protected ServletContextHandler addResourceHandler(String contextPath, Path resourceBase) {
  ServletContextHandler context = new ServletContextHandler();

  ResourceHandler staticResource = new ResourceHandler();
  staticResource.setDirectoriesListed(true);
  staticResource.setWelcomeFiles(new String[] { "index.html" });
  staticResource.setResourceBase(resourceBase.toAbsolutePath().toString());
  MimeTypes mimeTypes = new MimeTypes();
  mimeTypes.addMimeMapping("appcache", "text/cache-manifest");
  staticResource.setMimeTypes(mimeTypes);

  context.setContextPath(contextPath);
  context.setAliasChecks(Arrays.asList(new ApproveAliases(), new AllowSymLinkAliasChecker()));

  HandlerList allHandlers = new HandlerList();
  allHandlers.addHandler(staticResource);
  allHandlers.addHandler(context.getHandler());
  context.setHandler(allHandlers);

  handlers.addHandler(context);

  return context;
}
 
Example #2
Source File: HttpServer.java    From quarks with Apache License 2.0 5 votes vote down vote up
/**
 * Initialization of the context path for the web application "/console" occurs in this method
 * and the handler for the web application is set.  This only occurs once.
 * @return HttpServer: the singleton instance of this class
 * @throws IOException
 */
public static HttpServer getInstance() throws Exception {
    if (!HttpServerHolder.INITIALIZED) {
        HttpServerHolder.WEBAPP.setContextPath("/console");
        ServletContextHandler contextJobs = new ServletContextHandler(ServletContextHandler.SESSIONS);
        contextJobs.setContextPath("/jobs");
        ServletContextHandler contextMetrics = new ServletContextHandler(ServletContextHandler.SESSIONS);
        contextMetrics.setContextPath("/metrics");
        ServerUtil sUtil = new ServerUtil();
        String commandWarFilePath = sUtil.getAbsoluteWarFilePath("console.war");
        if (commandWarFilePath.equals("")){
        	// check if we are on Eclipse, if Eclipse can't find it, it probably does not exist
        	// running on Eclipse, look for the eclipse war file path
        	ProtectionDomain protectionDomain = HttpServer.class.getProtectionDomain();
        	String eclipseWarFilePath = sUtil.getEclipseWarFilePath(protectionDomain, "console.war");
        	if (!eclipseWarFilePath.equals("")) {            	
        		HttpServerHolder.WEBAPP.setWar(eclipseWarFilePath);
        	} else {
        		throw new Exception(HttpServerHolder.consoleWarNotFoundMessage);
        	}
        } else {
        	HttpServerHolder.WEBAPP.setWar(commandWarFilePath);
        }


        
        HttpServerHolder.WEBAPP.addAliasCheck(new AllowSymLinkAliasChecker()); 
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(new Handler[] { contextJobs, contextMetrics, HttpServerHolder.WEBAPP });
        HttpServerHolder.JETTYSERVER.setHandler(contexts);
        HttpServerHolder.INITIALIZED = true;
    }
    return HttpServerHolder.INSTANCE;
}