in src/main/java/org/apache/sling/launchpad/webapp/integrationtest/resourceresolver/ResourceResolverGeneralTest.java [2559:2620]
public void test_resolve_with_sling_alias_limited_access() throws Exception {
Principal testUserPrincipal = new Principal() {
@Override
public String getName() {
return "testuser";
}
};
AccessControlUtil.getUserManager(session).createUser("testuser", "password", testUserPrincipal, null);
Node child = rootNode.addNode("child");
Node grandChild = child.addNode("grandChild");
grandChild.setProperty("sling:alias", "enkel");
saveMappings(session);
session.save();
// deny jcr:all on /
AccessControlUtil.replaceAccessControlEntry(
session, "/", testUserPrincipal, null, new String[] {"jcr:all"}, null, "last");
// grant read on /content/child
AccessControlUtil.replaceAccessControlEntry(
session, child.getPath(), testUserPrincipal, new String[] {"jcr:read"}, null, null, "last");
session.save();
try {
final Map<String, Object> authInfo = new HashMap<String, Object>();
authInfo.put(ResourceResolverFactory.USER, "testuser");
authInfo.put(ResourceResolverFactory.PASSWORD, "password".toCharArray());
ResourceResolver testUserResolver = resourceResolverFactory.getResourceResolver(authInfo);
try {
// testing map
String path = grandChild.getPath();
String mapped = testUserResolver.map(path);
assertEquals("/child/enkel", mapped);
// testing resolve
path = grandChild.getPath();
Resource res = testUserResolver.resolve(null, path);
assertNotNull(res);
assertFalse(res instanceof NonExistingResource);
assertEquals(path, res.getPath());
path = child.getPath() + "/enkel";
res = testUserResolver.resolve(null, path);
assertNotNull(res);
assertFalse(res instanceof NonExistingResource);
assertEquals(grandChild.getPath(), res.getPath());
} finally {
if (testUserResolver != null && testUserResolver.isLive()) {
testUserResolver.close();
}
}
} finally {
removeAce(session, testUserPrincipal, "/");
child.remove();
Authorizable authorizable =
AccessControlUtil.getUserManager(session).getAuthorizable("testuser");
authorizable.remove();
session.save();
}
}