Search in sources :

Example 46 with Session

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

the class RemoveMembersTest method runTest.

@Override
public void runTest() throws Exception {
    Session s = null;
    try {
        // use system session login to avoid measuring the login-performance here
        s = systemLogin();
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        String groupPath = groupPaths.get(random.nextInt(GROUP_CNT));
        Group g = (Group) userManager.getAuthorizableByPath(groupPath);
        removeMembers(userManager, g, s);
    } catch (RepositoryException e) {
        if (s.hasPendingChanges()) {
            s.refresh(false);
        }
    } finally {
        if (s != null) {
            s.logout();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 47 with Session

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

the class RemoveMembersTest method afterSuite.

@Override
public void afterSuite() throws Exception {
    Session s = loginAdministrative();
    try {
        Authorizable authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(GROUP + "0");
        if (authorizable != null) {
            Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
            n.remove();
        }
        // remove test-users if they have been created
        authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(USER + "0");
        if (authorizable != null) {
            Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
            n.remove();
        }
        s.save();
    } finally {
        s.logout();
    }
}
Also used : Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 48 with Session

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

the class JackrabbitAccessControlManagerTest method testHasPrivilegeThrowsAccessDenied.

public void testHasPrivilegeThrowsAccessDenied() throws RepositoryException {
    Session readOnly = getHelper().getReadOnlySession();
    JackrabbitAccessControlManager jacMgr = (JackrabbitAccessControlManager) readOnly.getAccessControlManager();
    try {
        jacMgr.hasPrivileges(testRoot, principals, new Privilege[] { jacMgr.privilegeFromName(Privilege.JCR_READ) });
        fail("ReadOnly session isn't allowed to determine the privileges of other principals.");
    } catch (AccessDeniedException e) {
    // success
    } finally {
        readOnly.logout();
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Session(javax.jcr.Session)

Example 49 with Session

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

the class JackrabbitAccessControlManagerTest method testGetPrivilegesThrowsAccessDenied.

public void testGetPrivilegesThrowsAccessDenied() throws RepositoryException {
    Session readOnly = getHelper().getReadOnlySession();
    JackrabbitAccessControlManager jacMgr = (JackrabbitAccessControlManager) readOnly.getAccessControlManager();
    try {
        jacMgr.getPrivileges(testRoot, principals);
        fail("ReadOnly session isn't allowed to determine the privileges of other principals.");
    } catch (AccessDeniedException e) {
    // success
    } finally {
        readOnly.logout();
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Session(javax.jcr.Session)

Example 50 with Session

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

the class ItemStateHierarchyManagerDeadlockTest method retrieveNodesUnderInvRootNode.

public void retrieveNodesUnderInvRootNode() {
    System.out.println("Start retrieveNodesUnderInvRootNode ");
    Session session = null;
    try {
        session = login();
        // start from the bottom of the tree and move up
        Node inventoryRoot = getInvRootNode(session);
        NodeIterator nodes = inventoryRoot.getNodes();
        while (nodes.hasNext()) {
            Node node = nodes.nextNode();
            // System.out.println("   Node: " + node.getName());
            PropertyIterator properties = node.getProperties();
            while (properties.hasNext()) {
                Property prop = properties.nextProperty();
            // System.out.println("      Prop: " + prop.getName() + " - " + prop.getString());
            }
        }
        session.save();
        System.out.println("End retrieveNodesUnderInvRootNode");
    } catch (Exception e) {
        System.err.println("Exception in retrieveNodesUnderInvRootNode:" + e.getMessage());
    } finally {
        if (session != null)
            session.logout();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) IOException(java.io.IOException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

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