use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class RepositoryTest method getReferences.
@Test
public void getReferences() throws RepositoryException {
Session session = getAdminSession();
Node referee = getNode("/foo");
referee.addMixin("mix:referenceable");
getNode(TEST_PATH).setProperty("reference", session.getValueFactory().createValue(referee));
session.save();
PropertyIterator refs = referee.getReferences();
assertTrue(refs.hasNext());
Property p = refs.nextProperty();
assertEquals("reference", p.getName());
assertFalse(refs.hasNext());
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class AccessControlManagementTest method testReadAccessControlWithoutPrivilege.
@Test
public void testReadAccessControlWithoutPrivilege() throws Exception {
// re-grant READ in order to have an ACL-node
Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
JackrabbitAccessControlList tmpl = allow(path, privileges);
String policyPath = tmpl.getPath() + "/rep:policy";
// make sure the 'rep:policy' node has been created.
assertTrue(superuser.itemExists(policyPath));
/*
Testuser must still have READ-only access only and must not be
allowed to view the acl-node nor any item in the subtree that
has been created.
*/
assertFalse(testAcMgr.hasPrivileges(path, privilegesFromName(Privilege.JCR_READ_ACCESS_CONTROL)));
assertFalse(testSession.itemExists(policyPath));
assertFalse(testSession.nodeExists(policyPath));
try {
testSession.getNode(policyPath);
fail("Accessing the rep:policy node must throw PathNotFoundException.");
} catch (PathNotFoundException e) {
// ok.
}
try {
testAcMgr.getPolicies(tmpl.getPath());
fail("test user must not have READ_AC privilege.");
} catch (AccessDeniedException e) {
// success
}
try {
testAcMgr.getEffectivePolicies(tmpl.getPath());
fail("test user must not have READ_AC privilege.");
} catch (AccessDeniedException e) {
// success
}
for (NodeIterator aceNodes = superuser.getNode(policyPath).getNodes(); aceNodes.hasNext(); ) {
Node aceNode = aceNodes.nextNode();
String aceNodePath = aceNode.getPath();
assertFalse(testSession.nodeExists(aceNodePath));
for (PropertyIterator it = aceNode.getProperties(); it.hasNext(); ) {
assertFalse(testSession.propertyExists(it.nextProperty().getPath()));
}
}
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class JsonIndexCommand method appendNode.
private void appendNode(JsopBuilder builder, Node n, int depth) throws RepositoryException {
builder.object();
for (PropertyIterator it = n.getProperties(); depth != 0 && it.hasNext(); ) {
Property p = it.nextProperty();
String name = (p.getType() == PropertyType.STRING || p.getName().equals("jcr:primaryType") ? "" : "{" + PropertyType.nameFromValue(p.getType()) + "}") + p.getName();
builder.key(name);
if (p.isMultiple()) {
builder.array();
for (Value v : p.getValues()) {
builder.value(v.getString());
}
builder.endArray();
} else {
builder.value(p.getValue().getString());
}
}
for (NodeIterator it = n.getNodes(); depth != 0 && it.hasNext(); ) {
Node n2 = it.nextNode();
builder.key(n2.getName());
appendNode(builder, n2, depth - 1);
}
builder.endObject();
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class RepositorySidegradeTest method verifyReferencePropertiesContent.
@Test
public void verifyReferencePropertiesContent() throws Exception {
Session session = createAdminSession();
try {
assertTrue(session.nodeExists("/referenceable"));
String testNodeIdentifier = session.getNode("/referenceable").getIdentifier();
assertTrue(session.nodeExists("/properties"));
Node properties = session.getNode("/properties");
assertEquals(PropertyType.REFERENCE, properties.getProperty("reference").getType());
assertEquals(testNodeIdentifier, properties.getProperty("reference").getString());
assertEquals("/referenceable", properties.getProperty("reference").getNode().getPath());
PropertyIterator refs = session.getNode("/referenceable").getReferences();
assertTrue(refs.hasNext());
assertEquals(properties.getPath() + "/reference", refs.nextProperty().getPath());
assertFalse(refs.hasNext());
PropertyIterator refs2 = session.getNode("/versionable").getReferences();
assertTrue(refs2.hasNext());
assertEquals(properties.getPath() + "/mv_reference", refs2.nextProperty().getPath());
assertFalse(refs2.hasNext());
assertEquals(PropertyType.WEAKREFERENCE, properties.getProperty("weak_reference").getType());
assertEquals(testNodeIdentifier, properties.getProperty("weak_reference").getString());
assertEquals("/referenceable", properties.getProperty("weak_reference").getNode().getPath());
PropertyIterator weakRefs = session.getNode("/referenceable").getWeakReferences();
assertTrue(weakRefs.hasNext());
assertEquals(properties.getPath() + "/weak_reference", weakRefs.nextProperty().getPath());
assertFalse(weakRefs.hasNext());
PropertyIterator weakRefs2 = session.getNode("/versionable").getWeakReferences();
assertTrue(weakRefs2.hasNext());
assertEquals(properties.getPath() + "/mv_weak_reference", weakRefs2.nextProperty().getPath());
assertFalse(weakRefs2.hasNext());
} finally {
session.logout();
}
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class ReadPropertyTest method testDenySingleProperty.
@Test
public void testDenySingleProperty() throws Exception {
allow(path, privilegesFromName(PrivilegeConstants.JCR_READ));
deny(path, privilegesFromName(PrivilegeConstants.REP_READ_PROPERTIES), createGlobRestriction("*/" + propertyName1));
assertTrue(testSession.nodeExists(path));
assertTrue(testSession.itemExists(path));
assertTrue(testSession.nodeExists(childNPath));
List<String> allowed = new ArrayList<String>();
allowed.add(path + "/jcr:primaryType");
allowed.add(childNPath + "/jcr:primaryType");
for (String pPath : allowed) {
assertTrue(testSession.itemExists(pPath));
assertTrue(testSession.propertyExists(pPath));
}
List<String> denied = new ArrayList<String>();
denied.add(childPPath);
denied.add(childchildPPath);
for (String pPath : denied) {
assertFalse(testSession.itemExists(pPath));
assertFalse(testSession.propertyExists(pPath));
}
Node target = testSession.getNode(path);
PropertyIterator pit = target.getProperties();
while (pit.hasNext()) {
assertFalse(propertyName1.equals(pit.nextProperty().getName()));
}
}
Aggregations