438434 ResourceHandler checks aliases
This commit is contained in:
parent
a8964979b9
commit
0751256559
|
@ -31,6 +31,7 @@ import org.eclipse.jetty.http.HttpStatus;
|
|||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.LocalConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
|
@ -76,16 +77,16 @@ public class AliasedConstraintTest
|
|||
loginService.putUser("user3",new Password("password"),new String[] { "foo" });
|
||||
|
||||
context.setContextPath("/ctx");
|
||||
context.setResourceBase(MavenTestingUtils.getTestResourceDir("docroot").getAbsolutePath());
|
||||
server.setHandler(context);
|
||||
context.setHandler(session);
|
||||
// context.addAliasCheck(new AllowSymLinkAliasChecker());
|
||||
|
||||
server.addBean(loginService);
|
||||
|
||||
security = new ConstraintSecurityHandler();
|
||||
session.setHandler(security);
|
||||
ResourceHandler handler = new ResourceHandler();
|
||||
String resourceBase = MavenTestingUtils.getTestResourceDir("docroot").getAbsolutePath();
|
||||
handler.setResourceBase(resourceBase);
|
||||
security.setHandler(handler);
|
||||
|
||||
List<ConstraintMapping> constraints = new ArrayList<>();
|
||||
|
|
|
@ -1648,10 +1648,15 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param path
|
||||
* @param resource
|
||||
* @return True if the alias is OK
|
||||
*/
|
||||
public boolean checkAlias(String path, Resource resource)
|
||||
{
|
||||
// Is the resource aliased?
|
||||
if (resource.getAlias() != null)
|
||||
if (resource.getAlias() != null)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Aliased resource: " + resource + "~=" + resource.getAlias());
|
||||
|
|
|
@ -308,15 +308,16 @@ public class ResourceHandler extends HandlerWrapper
|
|||
{
|
||||
if (_context==null)
|
||||
return null;
|
||||
base=_context.getBaseResource();
|
||||
if (base==null)
|
||||
return null;
|
||||
return _context.getResource(path);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
path=URIUtil.canonicalPath(path);
|
||||
return base.addPath(path);
|
||||
Resource r = base.addPath(path);
|
||||
if (r!=null && r.getAlias()!=null && !_context.checkAlias(path, r))
|
||||
return null;
|
||||
return r;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue