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
}
}
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
}
}
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
}
}
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
}
}
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;
}
Aggregations