Search in sources :

Example 1 with PropertyIterator

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());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 2 with PropertyIterator

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()));
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) PathNotFoundException(javax.jcr.PathNotFoundException) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Test(org.junit.Test)

Example 3 with PropertyIterator

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();
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 4 with PropertyIterator

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();
    }
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 5 with PropertyIterator

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()));
    }
}
Also used : Node(javax.jcr.Node) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) Test(org.junit.Test)

Aggregations

PropertyIterator (javax.jcr.PropertyIterator)130 Property (javax.jcr.Property)97 Node (javax.jcr.Node)79 NodeIterator (javax.jcr.NodeIterator)31 RepositoryException (javax.jcr.RepositoryException)28 Value (javax.jcr.Value)28 Session (javax.jcr.Session)21 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)14 HashMap (java.util.HashMap)11 PathNotFoundException (javax.jcr.PathNotFoundException)10 AccessDeniedException (javax.jcr.AccessDeniedException)7 Item (javax.jcr.Item)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)4 AccessControlException (java.security.AccessControlException)4 PropertyIteratorAdapter (org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter)4 RepositoryFileDaoReferentialIntegrityException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException)4