Search in sources :

Example 11 with TestPrincipal

use of org.apache.jackrabbit.core.security.TestPrincipal in project jackrabbit by apache.

the class NodeCreationTest method testIllegalChars.

public void testIllegalChars() throws RepositoryException, NotExecutableException {
    createUserManager(2, true, 2);
    UserImpl u = (UserImpl) uMgr.createUser("z", "z");
    save(s);
    // remember the z-folder for later removal
    toRemove.add((NodeImpl) u.getNode().getParent().getParent());
    String zu = Text.escapeIllegalJcrChars("z*");
    String zur = Text.escapeIllegalJcrChars("z*r");
    Map<String, String> m = new ListOrderedMap();
    // test illegal JCR chars in uid
    // on level 2
    m.put("z*rich", "/z/" + zu + "/" + Text.escapeIllegalJcrChars("z*rich"));
    m.put("z*riq", "/z/" + zu + "/" + Text.escapeIllegalJcrChars("z*riq"));
    // still on level 2 (too short for 3)
    m.put("z*", "/z/" + zu + "/" + zu);
    // on level 3
    m.put("z*rik", "/z/" + zu + "/" + zur + "/" + Text.escapeIllegalJcrChars("z*rik"));
    m.put("z*.ri", "/z/" + zu + "/" + Text.escapeIllegalJcrChars("z*.") + "/" + Text.escapeIllegalJcrChars("z*.ri"));
    for (String uid : m.keySet()) {
        u = (UserImpl) uMgr.createUser(uid, uid);
        save(s);
        assertEquals(usersPath + m.get(uid), u.getNode().getPath());
        Authorizable ath = uMgr.getAuthorizable(uid);
        assertNotNull("User with id " + uid + " must exist.", ath);
        assertFalse("User with id " + uid + " must not be a group.", ath.isGroup());
    }
    // test for groups as well
    GroupImpl gr = (GroupImpl) uMgr.createGroup(new TestPrincipal("z[x]"));
    save(s);
    // remember the z-folder for later removal
    toRemove.add((NodeImpl) gr.getNode().getParent().getParent());
    assertEquals("z[x]", gr.getID());
    String expectedPath = groupsPath + "/z/" + Text.escapeIllegalJcrChars("z[") + "/" + Text.escapeIllegalJcrChars("z[x]");
    assertEquals(expectedPath, gr.getNode().getPath());
    Authorizable ath = uMgr.getAuthorizable(gr.getID());
    assertNotNull(ath);
    assertTrue(ath.isGroup());
    // test if conflicting authorizables are detected.
    try {
        uMgr.createUser("z[x]", "z[x]");
        save(s);
        fail("A group \"z[x]\" already exists.");
    } catch (AuthorizableExistsException e) {
    // success
    }
    try {
        uMgr.createGroup(new TestPrincipal("z*rik"));
        save(s);
        fail("A user \"z*rik\" already exists");
    } catch (AuthorizableExistsException e) {
    // success
    }
}
Also used : AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Example 12 with TestPrincipal

use of org.apache.jackrabbit.core.security.TestPrincipal in project jackrabbit by apache.

the class AbstractACLTemplateTest method testRemoveNonExisting.

public void testRemoveNonExisting() throws RepositoryException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    try {
        pt.removeAccessControlEntry(new AccessControlEntry() {

            public Principal getPrincipal() {
                return testPrincipal;
            }

            public Privilege[] getPrivileges() {
                return new Privilege[0];
            }
        });
        fail("Attemt to remove a non-existing, custom ACE must throw AccessControlException.");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 13 with TestPrincipal

use of org.apache.jackrabbit.core.security.TestPrincipal in project jackrabbit by apache.

the class AbstractACLTemplateTest method testRemoveInvalidEntry2.

public void testRemoveInvalidEntry2() throws RepositoryException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    try {
        pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {

            public boolean isAllow() {
                return false;
            }

            public int getPrivilegeBits() {
                return 0;
            }

            public String[] getRestrictionNames() {
                return new String[0];
            }

            public Value getRestriction(String restrictionName) {
                return null;
            }

            public Value[] getRestrictions(String restrictionName) throws RepositoryException {
                return null;
            }

            public Principal getPrincipal() {
                return testPrincipal;
            }

            public Privilege[] getPrivileges() {
                return new Privilege[0];
            }
        });
        fail("Passing a ACE with invalid privileges should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) Value(javax.jcr.Value) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 14 with TestPrincipal

use of org.apache.jackrabbit.core.security.TestPrincipal in project jackrabbit by apache.

the class AbstractACLTemplateTest method testAddInvalidEntry.

public void testAddInvalidEntry() throws RepositoryException, NotExecutableException {
    Principal unknownPrincipal;
    if (!principalMgr.hasPrincipal("an unknown principal")) {
        unknownPrincipal = new TestPrincipal("an unknown principal");
    } else {
        throw new NotExecutableException();
    }
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    try {
        pt.addAccessControlEntry(unknownPrincipal, privilegesFromName(Privilege.JCR_READ));
        fail("Adding an ACE with an unknown principal should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 15 with TestPrincipal

use of org.apache.jackrabbit.core.security.TestPrincipal in project jackrabbit by apache.

the class AbstractEvaluationTest method getTestGroup.

protected Group getTestGroup() throws RepositoryException, NotExecutableException {
    if (testGroup == null) {
        // create the testGroup
        Principal principal = new TestPrincipal("testGroup" + UUID.randomUUID());
        UserManager umgr = getUserManager(superuser);
        testGroup = umgr.createGroup(principal);
        testGroup.addMember(testUser);
        if (!umgr.isAutoSave() && superuser.hasPendingChanges()) {
            superuser.save();
        }
    }
    return testGroup;
}
Also used : TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) UserManager(org.apache.jackrabbit.api.security.user.UserManager) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Aggregations

TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)18 Principal (java.security.Principal)16 EveryonePrincipal (org.apache.jackrabbit.core.security.principal.EveryonePrincipal)7 Privilege (javax.jcr.security.Privilege)6 UserManager (org.apache.jackrabbit.api.security.user.UserManager)6 AccessControlException (javax.jcr.security.AccessControlException)5 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)5 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)5 Group (org.apache.jackrabbit.api.security.user.Group)5 AccessControlEntry (javax.jcr.security.AccessControlEntry)4 Node (javax.jcr.Node)3 RepositoryException (javax.jcr.RepositoryException)3 AccessControlManager (javax.jcr.security.AccessControlManager)3 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)3 Value (javax.jcr.Value)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 User (org.apache.jackrabbit.api.security.user.User)2 HashMap (java.util.HashMap)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 Session (javax.jcr.Session)1