Search in sources :

Example 31 with Session

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

the class UserManagerTest method testCleanup.

@Test
public void testCleanup() throws RepositoryException, NotExecutableException {
    Session s = getHelper().getSuperuserSession();
    try {
        UserManager umgr = getUserManager(s);
        s.logout();
        // any more -> accessing users must fail.
        try {
            umgr.getAuthorizable("any userid");
            fail("After having logged out the original session, the user manager must not be live any more.");
        } catch (RepositoryException e) {
        // success
        }
    } finally {
        if (s.isLive()) {
            s.logout();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 32 with Session

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

the class UserImportTest method testImportWithIntermediatePath.

@Test
public void testImportWithIntermediatePath() throws Exception {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"some\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>d5433be9-68d0-4fba-bf96-efc29f461993</sv:value></sv:property>" + "<sv:node sv:name=\"intermediate\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>d87354a4-037e-4756-a8fb-deb2eb7c5149</sv:value></sv:property>" + "<sv:node sv:name=\"path\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>24263272-b789-4568-957a-3bcaf99dbab3</sv:value></sv:property>" + "<sv:node sv:name=\"t3\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>0b8854ad-38f0-36c6-9807-928d28195609</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}4358694eeb098c6708ae914a10562ce722bbbc34</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t3</sv:value></sv:property>" + "</sv:node>" + "</sv:node>" + "</sv:node>" + "</sv:node>";
    Node target = getTargetNode();
    doImport(getTargetPath(), xml);
    Session s = getImportSession();
    assertTrue(target.isModified());
    assertTrue(s.hasPendingChanges());
    Authorizable newUser = getUserManager().getAuthorizable("t3");
    assertNotNull(newUser);
    assertFalse(newUser.isGroup());
    assertEquals("t3", newUser.getPrincipal().getName());
    assertEquals("t3", newUser.getID());
    Node n = s.getNode(newUser.getPath());
    assertTrue(n.isNew());
    Node parent = n.getParent();
    assertFalse(n.isSame(target));
    assertTrue(parent.isNodeType(UserConstants.NT_REP_AUTHORIZABLE_FOLDER));
    assertFalse(parent.getDefinition().isProtected());
    assertTrue(target.hasNode("some"));
    assertTrue(target.hasNode("some/intermediate/path"));
}
Also used : Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 33 with Session

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

the class UserManagerTest method testCreateUserIdDifferentFromPrincipalName.

@Test
public void testCreateUserIdDifferentFromPrincipalName() throws RepositoryException, NotExecutableException {
    User u = null;
    Session uSession = null;
    try {
        Principal p = getTestPrincipal();
        String uid = createUserId();
        u = userMgr.createUser(uid, "pw", p, null);
        superuser.save();
        String msg = "Creating a User with principal-name distinct from Principal-name must succeed as long as both are unique.";
        assertEquals(msg, u.getID(), uid);
        assertEquals(msg, p.getName(), u.getPrincipal().getName());
        assertFalse(msg, u.getID().equals(u.getPrincipal().getName()));
        // make sure the userID exposed by a Session corresponding to that
        // user is equal to the users ID.
        uSession = superuser.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray()));
        assertEquals(uid, uSession.getUserID());
    } finally {
        if (uSession != null) {
            uSession.logout();
        }
        if (u != null) {
            u.remove();
            superuser.save();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Session(javax.jcr.Session) Test(org.junit.Test)

Example 34 with Session

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

the class UserImportTest method testIncompleteUser.

@Test
public void testIncompleteUser() throws Exception {
    List<String> incompleteXml = new ArrayList<String>();
    incompleteXml.add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + "</sv:node>");
    incompleteXml.add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + "</sv:node>");
    Session s = getImportSession();
    for (String xml : incompleteXml) {
        Node target = s.getNode(getTargetPath());
        try {
            doImport(getTargetPath(), xml);
            // saving changes of the import -> must fail as mandatory prop is missing
            try {
                s.save();
                fail("Import must be incomplete. Saving changes must fail.");
            } catch (ConstraintViolationException e) {
            // success
            }
        } finally {
            s.refresh(false);
            if (target.hasNode("t")) {
                target.getNode("t").remove();
                s.save();
            }
        }
    }
}
Also used : Node(javax.jcr.Node) ArrayList(java.util.ArrayList) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 35 with Session

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

the class UserManagerTest method testUnknownUserLogin.

@Test
public void testUnknownUserLogin() throws RepositoryException {
    String uid = createUserId();
    assertNull(userMgr.getAuthorizable(uid));
    try {
        Session s = superuser.getRepository().login(new SimpleCredentials(uid, uid.toCharArray()));
        s.logout();
        fail("An unknown user should not be allowed to execute the login.");
    } catch (Exception e) {
    // ok.
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) RepositoryException(javax.jcr.RepositoryException) AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

Session (javax.jcr.Session)1393 Node (javax.jcr.Node)761 Test (org.junit.Test)387 RepositoryException (javax.jcr.RepositoryException)304 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)162 Property (javax.jcr.Property)90 SimpleCredentials (javax.jcr.SimpleCredentials)88 Privilege (javax.jcr.security.Privilege)84 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)77 Value (javax.jcr.Value)71 Query (javax.jcr.query.Query)69 NodeIterator (javax.jcr.NodeIterator)68 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)65 QueryManager (javax.jcr.query.QueryManager)63 HashMap (java.util.HashMap)57 IOException (java.io.IOException)56 ArrayList (java.util.ArrayList)55 AccessControlManager (javax.jcr.security.AccessControlManager)55 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)52 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)49