use of org.eclipse.jetty.util.resource.PathResource in project jetty.project by eclipse.
the class AllowSymLinkAliasChecker method check.
@Override
public boolean check(String uri, Resource resource) {
// Only support PathResource alias checking
if (!(resource instanceof PathResource))
return false;
PathResource pathResource = (PathResource) resource;
try {
Path path = pathResource.getPath();
Path alias = pathResource.getAliasPath();
if (path.equals(alias))
// Unknown why this is an alias
return false;
if (hasSymbolicLink(path) && Files.isSameFile(path, alias)) {
if (LOG.isDebugEnabled())
LOG.debug("Allow symlink {} --> {}", resource, pathResource.getAliasPath());
return true;
}
} catch (Exception e) {
LOG.ignore(e);
}
return false;
}
use of org.eclipse.jetty.util.resource.PathResource in project opennms by OpenNMS.
the class ApproveAbsolutePathAliasesTest method canApproveDoubleSlash.
@Test
public void canApproveDoubleSlash() throws URISyntaxException, IOException {
ApproveAbsolutePathAliases aliasCheck = new ApproveAbsolutePathAliases();
// If the alias and file only differ by a double slash, it should be approved
String path = "/WEB-INF/jsp//support/index.jsp";
String uri = "file:///opt/opennms/jetty-webapps/opennms/WEB-INF/jsp//support/index.jsp";
assertThat(aliasCheck.check(path, new PathResource(new URI(uri)) {
@Override
public URI getAlias() {
try {
return new URI("file:///opt/opennms/jetty-webapps/opennms/WEB-INF/jsp/support/index.jsp");
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}), equalTo(true));
// Other differences should not be approved
uri = "file:///opt/opennms/jetty-webapps/opennms/WEB-INF/jsp/support/index.jsp";
assertThat(aliasCheck.check(path, new PathResource(new URI(uri)) {
@Override
public URI getAlias() {
try {
return new URI("file:///opt/opennms/jetty-webapps/opennms/WEB-INF/jsp/.support/index.jsp");
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}), equalTo(false));
}
use of org.eclipse.jetty.util.resource.PathResource in project jphp by jphp-compiler.
the class PHttpResourceHandler method __invoke.
@Signature
public void __invoke(PHttpServerRequest request, PHttpServerResponse response) throws Exception {
final boolean[] once = { false };
ResourceHandler resourceHandler = new ResourceHandler() {
@Override
public Resource getResource(String path) {
if (!once[0]) {
once[0] = true;
Object attr = request.getRequest().getAttribute("**");
File file;
if (attr != null) {
file = new File(PHttpResourceHandler.this.file, "/" + attr);
} else {
file = new File(PHttpResourceHandler.this.file);
}
if (file.exists()) {
return new PathResource(file.getAbsoluteFile());
} else {
return null;
}
} else {
return null;
}
}
};
resourceHandler.doStart();
resourceHandler.setResourceBase(file());
if (cacheControl() != null) {
resourceHandler.setCacheControl(cacheControl());
}
resourceHandler.setRedirectWelcome(redirectWelcome());
resourceHandler.setPathInfoOnly(pathInfoOnly());
resourceHandler.setDirectoriesListed(directoriesListed());
resourceHandler.setDirAllowed(dirAllowed());
resourceHandler.setAcceptRanges(acceptRanges());
resourceHandler.setEtags(etags());
Request baseRequest = Request.getBaseRequest(request.getRequest());
resourceHandler.handle(request.getRequest().getRequestURI(), baseRequest, request.getRequest(), response.getResponse());
}
use of org.eclipse.jetty.util.resource.PathResource in project gitiles by GerritCodeReview.
the class DevServer method staticHandler.
private Handler staticHandler() throws IOException {
Path staticRoot = sourceRoot.resolve("resources/com/google/gitiles/static");
ResourceHandler rh = new ResourceHandler();
try {
rh.setBaseResource(new PathResource(staticRoot.toUri().toURL()));
} catch (URISyntaxException e) {
throw new IOException(e);
}
rh.setWelcomeFiles(new String[] {});
rh.setDirectoriesListed(false);
ContextHandler handler = new ContextHandler("/+static");
handler.setHandler(rh);
return handler;
}
use of org.eclipse.jetty.util.resource.PathResource 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();
}
Aggregations