protected Principal getTestPrincipal(String name) throws RepositoryException { return new TestPrincipal(name); }
@Override protected Principal getPrincipal(Credentials credentials) { if (ignore) { return null; } else { return new TestPrincipal(((SimpleCredentials) credentials).getUserID()); } } }
@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(); } }
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); } } } }
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; }
/** * * @throws Exception */ public void testCacheDoesntContainTestPrincipalImpl() throws Exception { Set<Principal> principals = getPrincipalSetFromSession(superuser); for (Principal p : principals) { Principal testPrinc = new TestPrincipal(p.getName()); principalProvider.getGroupMembership(testPrinc); Principal fromProvider = principalProvider.getPrincipal(p.getName()); assertNotSame(testPrinc, fromProvider); assertFalse(fromProvider instanceof TestPrincipal); } }
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 } }
maxtries -= 1; authorizable = s.getUserManager().createUser(name, "password1", new TestPrincipal(name), INTERMEDIATE_PATH); s.save();
public void testCreatingGroupWithPrincipalMatchingExistingUserId() throws RepositoryException, NotExecutableException { Principal p = getTestPrincipal(); String uid = getTestUserId(p); User u = null; Group gr = null; try { u = userMgr.createUser(uid, buildPassword(uid), p, null); save(superuser); gr = userMgr.createGroup(new TestPrincipal(uid)); save(superuser); String msg = "Creating a Group with a principal-name that exists as UserID -> must create new GroupID but keep PrincipalName."; assertFalse(msg, gr.getID().equals(gr.getPrincipal().getName())); assertFalse(msg, gr.getID().equals(uid)); assertFalse(msg, gr.getID().equals(u.getID())); assertEquals(msg, uid, gr.getPrincipal().getName()); } finally { if (u != null) { u.remove(); save(superuser); } if (gr != null) { gr.remove(); save(superuser); } } }
GroupImpl gr = (GroupImpl) uMgr.createGroup(new TestPrincipal("z[x]")); save(s); uMgr.createGroup(new TestPrincipal("z*rik")); save(s); fail("A user \"z*rik\" already exists");
public void testMultipleGroupPermissionsOnNode2() throws NotExecutableException, RepositoryException { Group testGroup = getTestGroup(); /* create a second group the test user is member of */ Principal principal = new TestPrincipal("testGroup" + UUID.randomUUID()); UserManager umgr = getUserManager(superuser); Group group2 = umgr.createGroup(principal); try { group2.addMember(testUser); if (!umgr.isAutoSave() && superuser.hasPendingChanges()) { superuser.save(); } /* add privileges for the Group the test-user is member of */ Privilege[] privileges = privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES); withdrawPrivileges(path, testGroup.getPrincipal(), privileges, getRestrictions(superuser, path)); givePrivileges(path, group2.getPrincipal(), privileges, getRestrictions(superuser, path)); /* testuser must get the permissions/privileges inherited from the group it is member of. granting permissions for group2 must be effective */ String actions = javax.jcr.Session.ACTION_SET_PROPERTY + "," + javax.jcr.Session.ACTION_READ; AccessControlManager testAcMgr = getTestACManager(); assertTrue(getTestSession().hasPermission(path, actions)); Privilege[] privs = privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES); assertTrue(testAcMgr.hasPrivileges(path, privs)); } finally { group2.remove(); } }
public void testMultipleGroupPermissionsOnNode() throws NotExecutableException, RepositoryException { Group testGroup = getTestGroup(); /* create a second group the test user is member of */ Principal principal = new TestPrincipal("testGroup" + UUID.randomUUID()); UserManager umgr = getUserManager(superuser); Group group2 = umgr.createGroup(principal); try { group2.addMember(testUser); if (!umgr.isAutoSave() && superuser.hasPendingChanges()) { superuser.save(); } /* add privileges for the Group the test-user is member of */ Privilege[] privileges = privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES); givePrivileges(path, testGroup.getPrincipal(), privileges, getRestrictions(superuser, path)); withdrawPrivileges(path, group2.getPrincipal(), privileges, getRestrictions(superuser, path)); /* testuser must get the permissions/privileges inherited from the group it is member of. the denial of group2 must succeed */ String actions = javax.jcr.Session.ACTION_SET_PROPERTY + "," + javax.jcr.Session.ACTION_READ; AccessControlManager testAcMgr = getTestACManager(); assertFalse(getTestSession().hasPermission(path, actions)); Privilege[] privs = privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES); assertFalse(testAcMgr.hasPrivileges(path, privs)); } finally { group2.remove(); } }
try { u = uMgr.createUser("t", "t"); u2 = uMgr.createUser("tt", "tt", new TestPrincipal("tt"), "t/tt"); if (!uMgr.isAutoSave()) { superuser.save();
Principal principal = new TestPrincipal("testGroup" + UUID.randomUUID()); UserManager umgr = getUserManager(superuser); Group group2 = umgr.createGroup(principal);