use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class MockResourceResolver method resolve.
@Override
public Resource resolve(final HttpServletRequest request, final String absPath) {
String path = absPath;
if (path == null) {
path = "/";
}
// split off query string or fragment that may be appendend to the URL
String urlRemainder = null;
int urlRemainderPos = Math.min(path.indexOf('?'), path.indexOf('#'));
if (urlRemainderPos >= 0) {
urlRemainder = path.substring(urlRemainderPos);
path = path.substring(0, urlRemainderPos);
}
// unmangle namespaces
if (options.isMangleNamespacePrefixes()) {
path = NamespaceMangler.unmangleNamespaces(path);
}
// build full path again
path = path + (urlRemainder != null ? urlRemainder : "");
Resource resource = this.getResource(path);
if (resource == null) {
resource = new NonExistingResource(this, absPath);
}
return resource;
}
use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class SlingCrudResourceResolverTest method testResolveNonexistingResource.
@Test
public void testResolveNonexistingResource() {
Resource resource = resourceResolver.resolve("/non/existing/path");
assertTrue(resource instanceof NonExistingResource);
assertEquals("/non/existing/path", resource.getPath());
}
use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class ResourceResolverTest method test_resolve_with_sling_alias_limited_access.
@Test
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();
}
}
use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method test_resolve_with_sling_alias_multi_value.
/*@Test public void test_resolve_with_sling_alias_limited_access() throws Exception {
Principal testUserPrincipal = AccessControlUtil.getPrincipalManager(session).getPrincipal("testuser");
Node child = rootNode.addNode("child");
child.setProperty("sling:alias", "kind");
AccessControlUtil.replaceAccessControlEntry(session, child.getPath(), testUserPrincipal, null, new String[] {"jcr:all"}, null, "last");
session.save();
try {
Session testUserSession = getRepository().login(new SimpleCredentials("testuser", "test".toCharArray()));
final Map<String, Object> authInfo = new HashMap<String, Object>();
authInfo.put(ResourceResolverFactory.USER, "admin");
authInfo.put(ResourceResolverFactory.PASSWORD, "admin".toCharArray());
authInfo.put("testAttributeString", "AStringValue");
authInfo.put("testAttributeNumber", 999);
ResourceResolver testUserResolver = resFac.getResourceResolver(authInfo);
try {
// expect child due to the aliased not not being visible and no parent
// due to mapping the rootPath onto root
String path = "/child";
String mapped = testUserResolver.map(child.getPath());
assertEquals(path, mapped);
Resource res = testUserResolver.resolve(null, path);
assertNotNull(res);
assertTrue(res instanceof NonExistingResource);
assertEquals("/child",
res.getResourceMetadata().getResolutionPath());
// TODO - is this correct?
assertEquals(null, res.getResourceMetadata().getResolutionPathInfo());
// second level alias
Node grandchild = child.addNode("grandchild");
grandchild.setProperty("sling:alias", "enkel");
AccessControlUtil.replaceAccessControlEntry(session, grandchild.getPath(), testUserPrincipal, new String[] { "jcr:all" }, null, null, "first");
session.save();
// expect /child/enkel due to parent node not being
// visible to the test user and no parent due to mapping
// the rootPath onto root
String pathEnkel = "/child/enkel";
String mappedEnkel = testUserResolver.map(grandchild.getPath());
assertEquals(pathEnkel, mappedEnkel);*/
//TODO already commented
/*
Resource resEnkel = testUserResolver.resolve(null, pathEnkel);
assertNotNull(resEnkel);
assertEquals(rootNode.getPath() + "/kind/enkel",
resEnkel.getResourceMetadata().getResolutionPath());
assertEquals("", resEnkel.getResourceMetadata().getResolutionPathInfo());
Node resNodeEnkel = resEnkel.adaptTo(Node.class);
assertNotNull(resNodeEnkel);
assertEquals(grandchild.getPath(), resNodeEnkel.getPath());
*/
/*} finally {
testUserSession.logout();
}
} finally {
child.remove();
session.save();
}
}*/
@Test
public void test_resolve_with_sling_alias_multi_value() throws Exception {
Node child = rootNode.addNode("child");
child.setProperty("sling:alias", new String[] { "kind", "enfant" });
try {
saveMappings(session);
// expect kind due to alias and no parent due to mapping
// the rootPath onto root
String path = "/kind";
String mapped = resResolver.map(child.getPath());
assertEquals(path, mapped);
Resource res = resResolver.resolve(null, path);
assertNotNull(res);
assertEquals(rootNode.getPath() + "/kind", res.getResourceMetadata().getResolutionPath());
assertEquals("", res.getResourceMetadata().getResolutionPathInfo());
Node resNode = res.adaptTo(Node.class);
assertNotNull(resNode);
assertEquals(child.getPath(), resNode.getPath());
// expect enfant due to alias and no parent due to mapping
// the rootPath onto root
String pathEnfant = "/enfant";
String mappedEnfant = resResolver.map(child.getPath());
// map always selects first alias
assertEquals(path, mappedEnfant);
Resource resEnfant = resResolver.resolve(null, pathEnfant);
assertNotNull(resEnfant);
assertEquals(rootNode.getPath() + "/enfant", resEnfant.getResourceMetadata().getResolutionPath());
assertEquals("", resEnfant.getResourceMetadata().getResolutionPathInfo());
Node resNodeEnfant = resEnfant.adaptTo(Node.class);
assertNotNull(resNodeEnfant);
assertEquals(child.getPath(), resNodeEnfant.getPath());
// second level alias
Node grandchild = child.addNode("grandchild");
grandchild.setProperty("sling:alias", "enkel");
saveMappings(session);
// expect kind/enkel due to alias and no parent due to mapping
// the rootPath onto root
String pathEnkel = "/kind/enkel";
String mappedEnkel = resResolver.map(grandchild.getPath());
assertEquals(pathEnkel, mappedEnkel);
Resource resEnkel = resResolver.resolve(null, pathEnkel);
assertNotNull(resEnkel);
assertEquals(rootNode.getPath() + "/kind/enkel", resEnkel.getResourceMetadata().getResolutionPath());
assertEquals("", resEnkel.getResourceMetadata().getResolutionPathInfo());
Node resNodeEnkel = resEnkel.adaptTo(Node.class);
assertNotNull(resNodeEnkel);
assertEquals(grandchild.getPath(), resNodeEnkel.getPath());
// expect kind/enkel due to alias and no parent due to mapping
// the rootPath onto root
String pathEnfantEnkel = "/enfant/enkel";
String mappedEnfantEnkel = resResolver.map(grandchild.getPath());
// map always selects first alias
assertEquals(pathEnkel, mappedEnfantEnkel);
Resource resEnfantEnkel = resResolver.resolve(null, pathEnfantEnkel);
assertNotNull(resEnfantEnkel);
assertEquals(rootNode.getPath() + "/enfant/enkel", resEnfantEnkel.getResourceMetadata().getResolutionPath());
assertEquals("", resEnfantEnkel.getResourceMetadata().getResolutionPathInfo());
Node resNodeEnfantEnkel = resEnfantEnkel.adaptTo(Node.class);
assertNotNull(resNodeEnfantEnkel);
assertEquals(grandchild.getPath(), resNodeEnfantEnkel.getPath());
} finally {
child.remove();
session.save();
}
}
use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveRemovedMixinVanityPath.
//see SLING-3558
@Ignore
@Test
public void testResolveRemovedMixinVanityPath() throws Exception {
Node childNode = null;
try {
//create new child with vanity path without mixin
childNode = maybeCreateNode(rootNode, "rootChild", "nt:unstructured");
childNode.setProperty("sling:vanityPath", "childVanity");
saveMappings(session);
String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/childVanity.print.html");
HttpServletRequest request = new FakeSlingHttpServletRequest(path);
Resource res = resResolver.resolve(request, path);
assertNotNull(res);
assertTrue(res instanceof NonExistingResource);
assertEquals("/childVanity.print.html", res.getPath());
//add mixin
childNode.addMixin("sling:VanityPath");
saveMappings(session);
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/childVanity.print.html");
request = new FakeSlingHttpServletRequest(path);
res = resResolver.resolve(request, path);
assertNotNull(res);
assertEquals(childNode.getPath(), res.getPath());
assertEquals(childNode.getPrimaryNodeType().getName(), res.getResourceType());
assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
assertNotNull(res.adaptTo(Node.class));
assertTrue(childNode.isSame(res.adaptTo(Node.class)));
//remove mixin
childNode.removeMixin("sling:VanityPath");
saveMappings(session);
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/childVanity.print.html");
request = new FakeSlingHttpServletRequest(path);
res = resResolver.resolve(request, path);
assertNotNull(res);
assertTrue(res instanceof NonExistingResource);
assertEquals("/childVanity.print.html", res.getPath());
} finally {
if (childNode != null) {
childNode.remove();
saveMappings(session);
}
}
}
Aggregations