Search in sources :

Example 76 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class ConcurrentEveryoneACLTest method runTest.

@Override
public void runTest() throws Exception {
    Session session = null;
    try {
        session = runAsAdmin ? loginWriter() : loginAnonymous();
        for (int i = 0; i < itemsToRead; i++) {
            session.refresh(false);
            int a = random.nextInt(NODE_COUNT);
            int b = random.nextInt(NODE_COUNT);
            String path = "/" + ROOT_NODE_NAME + "/node" + a + "/node" + b + "/jcr:primaryType";
            session.getProperty(path).getString();
        }
    } finally {
        if (session != null) {
            session.logout();
        }
    }
}
Also used : Session(javax.jcr.Session)

Example 77 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class ConcurrentEveryoneACLTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    Session session = loginWriter();
    AccessControlManager acMgr = session.getAccessControlManager();
    Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
    final Node root = session.getRootNode().addNode(ROOT_NODE_NAME, "nt:unstructured");
    for (int i = 0; i < NODE_COUNT; i++) {
        Node node = root.addNode("node" + i, "nt:unstructured");
        for (int j = 0; j < NODE_COUNT; j++) {
            Node newNode = node.addNode("node" + j, "nt:unstructured");
            JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, newNode.getPath());
            acl.addEntry(EveryonePrincipal.getInstance(), privileges, true);
            acMgr.setPolicy(newNode.getPath(), acl);
        }
        session.save();
    }
    // deny everyone on root node
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, root.getPath());
    acl.addEntry(EveryonePrincipal.getInstance(), privileges, false);
    acMgr.setPolicy(root.getPath(), acl);
    session.save();
    final int[] numACEs = new int[1];
    ItemVisitor v = new TraversingItemVisitor.Default() {

        @Override
        protected void entering(Node node, int i) throws RepositoryException {
            if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
                numACEs[0]++;
            }
            super.entering(node, i);
        }

        @Override
        protected void entering(Property prop, int i) throws RepositoryException {
            super.entering(prop, i);
        }
    };
    v.visit(root);
    System.out.println("Num ACEs: " + numACEs[0]);
    session.logout();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) Node(javax.jcr.Node) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 78 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class ConcurrentEveryoneACLTest method afterSuite.

@Override
public void afterSuite() throws Exception {
    Session session = loginWriter();
    Node root = session.getRootNode().getNode(ROOT_NODE_NAME);
    root.remove();
    session.logout();
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 79 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class AbstractLoginTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    Session s = loginAdministrative();
    try {
        AccessControlUtils.addAccessControlEntry(s, "/", EveryonePrincipal.getInstance(), new String[] { Privilege.JCR_READ }, true);
        if (USER.equals(runAsUser)) {
            ((JackrabbitSession) s).getUserManager().createUser(USER, USER);
        }
    } finally {
        s.save();
        s.logout();
    }
}
Also used : Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 80 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class AbstractLoginTest method afterSuite.

@Override
public void afterSuite() throws Exception {
    Session s = loginAdministrative();
    try {
        Authorizable authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(USER);
        if (authorizable != null) {
            authorizable.remove();
            s.save();
        }
    } finally {
        s.logout();
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Aggregations

Session (javax.jcr.Session)1177 Node (javax.jcr.Node)645 Test (org.junit.Test)359 RepositoryException (javax.jcr.RepositoryException)206 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)158 SimpleCredentials (javax.jcr.SimpleCredentials)86 Property (javax.jcr.Property)78 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)77 Privilege (javax.jcr.security.Privilege)76 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)64 Value (javax.jcr.Value)63 Query (javax.jcr.query.Query)58 NodeIterator (javax.jcr.NodeIterator)55 QueryManager (javax.jcr.query.QueryManager)53 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)50 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)48 AccessControlManager (javax.jcr.security.AccessControlManager)47 HashMap (java.util.HashMap)44 UserManager (org.apache.jackrabbit.api.security.user.UserManager)43 ArrayList (java.util.ArrayList)41