{
// Only support PathResource alias checking
if (!(resource instanceof PathResource))
return false;
PathResource pathResource = (PathResource)resource;
try
{
Path path = pathResource.getPath();
// is the file itself a symlink?
if (Files.isSymbolicLink(path) && Files.isSameFile(path,pathResource.getAliasPath()))
{
if (LOG.isDebugEnabled())
LOG.debug("Allow symlink {} --> {}",resource,pathResource.getAliasPath());
return true;
}
// No, so let's check each element ourselves
Path d = path.getRoot();
for (Path e:path)
{
d=d.resolve(e);
while (Files.exists(d) && Files.isSymbolicLink(d))
{
Path link=Files.readSymbolicLink(d);
if (!link.isAbsolute())
link=d.resolve(link);
d=link;
}
}
if (pathResource.getAliasPath().equals(d))
{
if (LOG.isDebugEnabled())
LOG.debug("Allow path symlink {} --> {}",resource,d);
return true;
}