Search in sources :

Example 16 with TestPrincipal

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

the class EntryCollectorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // create some nodes below the test root in order to apply ac-stuff
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    Node cn1 = node.addNode(nodeName2, testNodeType);
    superuser.save();
    path = node.getPath();
    childNPath = cn1.getPath();
    // create the testGroup
    UserManager umgr = getUserManager(superuser);
    Principal groupPrincipal = new TestPrincipal("testGroup" + UUID.randomUUID());
    testGroup = umgr.createGroup(groupPrincipal);
    testUser = umgr.createUser("testUser" + UUID.randomUUID(), "pw");
    if (!umgr.isAutoSave() && superuser.hasPendingChanges()) {
        superuser.save();
    }
}
Also used : TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Node(javax.jcr.Node) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 17 with TestPrincipal

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

the class ConcurrentCreateUserTest method testCreateUsers.

public void testCreateUsers() throws Exception {
    log.println("ConcurrentCreateUserTest.testCreateUsers: c=" + CONCURRENCY);
    log.flush();
    runTask(new Task() {

        public void execute(Session session, Node test) throws RepositoryException {
            JackrabbitSession s = null;
            try {
                s = (JackrabbitSession) getHelper().getSuperuserSession();
                String name = "newname-" + UUID.randomUUID();
                Authorizable authorizable = null;
                int maxtries = RETRIES;
                RepositoryException lastex = null;
                while (authorizable == null && maxtries > 0) {
                    try {
                        maxtries -= 1;
                        authorizable = s.getUserManager().createUser(name, "password1", new TestPrincipal(name), INTERMEDIATE_PATH);
                        s.save();
                    } catch (InvalidItemStateException ex) {
                        lastex = ex;
                        log.println("got " + ex + ", retrying");
                    }
                }
                if (authorizable == null) {
                    throw new RepositoryException("user " + name + " not created in " + RETRIES + " attempts.", lastex);
                }
                userIDs.add(authorizable.getID());
                log.println(authorizable + " created");
            } finally {
                s.logout();
            }
        }
    }, CONCURRENCY, "/" + testPath);
}
Also used : TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 18 with TestPrincipal

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

the class UserManagerImplTest method testCreateGroupWithInvalidIdOrPrincipal.

public void testCreateGroupWithInvalidIdOrPrincipal() throws RepositoryException, NotExecutableException {
    Principal p = getTestPrincipal();
    String uid = p.getName();
    Map<String, Principal> fail = new HashMap<String, Principal>();
    fail.put(uid, null);
    fail.put(uid, new TestPrincipal(""));
    fail.put(null, p);
    fail.put("", p);
    for (String id : fail.keySet()) {
        Group g = null;
        try {
            Principal princ = fail.get(id);
            g = userMgr.createGroup(id, princ, null);
            fail("Creating group with id '" + id + "' and principal '" + princ + "' should fail");
        } catch (IllegalArgumentException e) {
        // success
        } finally {
            if (g != null) {
                g.remove();
                save(superuser);
            }
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) HashMap(java.util.HashMap) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) 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