use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class ReadTest method testAllowEveryoneDenyGroup.
public void testAllowEveryoneDenyGroup() throws Exception {
Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
Principal group = getTestGroup().getPrincipal();
Principal everyone = ((JackrabbitSession) superuser).getPrincipalManager().getEveryone();
/*
allow READ privilege for everyone at 'path'
*/
givePrivileges(path, everyone, privileges, getRestrictions(superuser, path));
/*
deny READ privilege for group at 'path'
*/
withdrawPrivileges(path, group, privileges, getRestrictions(superuser, path));
Session testSession = getTestSession();
assertFalse(testSession.nodeExists(path));
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class ReadTest method testDenyGroupAllowEveryone.
public void testDenyGroupAllowEveryone() throws Exception {
Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
Principal group = getTestGroup().getPrincipal();
Principal everyone = ((JackrabbitSession) superuser).getPrincipalManager().getEveryone();
/*
deny READ privilege for group at 'path'
*/
withdrawPrivileges(path, group, privileges, getRestrictions(superuser, path));
/*
allow READ privilege for everyone at 'path'
*/
givePrivileges(path, everyone, privileges, getRestrictions(superuser, path));
Session testSession = getTestSession();
assertTrue(testSession.nodeExists(path));
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class ReadTest method testAllowEveryonePathDenyGroupChildPath.
public void testAllowEveryonePathDenyGroupChildPath() throws Exception {
Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
Principal group = getTestGroup().getPrincipal();
Principal everyone = ((JackrabbitSession) superuser).getPrincipalManager().getEveryone();
/*
allow READ privilege for everyone at 'path'
*/
givePrivileges(path, everyone, privileges, getRestrictions(superuser, path));
/*
deny READ privilege for group at 'childNPath'
*/
withdrawPrivileges(path, group, privileges, getRestrictions(superuser, childNPath));
Session testSession = getTestSession();
assertFalse(testSession.nodeExists(childNPath));
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class UserTest method testDisable.
public void testDisable() throws Exception {
boolean remove = false;
Session s = getHelper().getReadOnlySession();
User user = null;
String userID = null;
String pw = "";
try {
User readonlyUser = getTestUser(s);
if (readonlyUser.isAdmin()) {
// configured readonly user is admin
// -> need to create another test user
pw = "test";
userID = getUserManager(superuser).createUser(getTestPrincipal().getName(), pw).getID();
remove = true;
} else {
userID = readonlyUser.getID();
}
user = (User) getUserManager(superuser).getAuthorizable(userID);
// by default a user isn't disabled
assertFalse(user.isDisabled());
assertNull(user.getDisabledReason());
// disable user
String reason = "readonly user is disabled!";
user.disable(reason);
save(superuser);
assertTrue(user.isDisabled());
assertEquals(reason, user.getDisabledReason());
// user must still be retrievable from user manager
assertNotNull(getUserManager(superuser).getAuthorizable(userID));
// ... and from principal manager as well
assertTrue(((JackrabbitSession) superuser).getPrincipalManager().hasPrincipal(user.getPrincipal().getName()));
// -> login must fail
try {
Session ss = getHelper().getRepository().login(new SimpleCredentials(userID, pw.toCharArray()));
ss.logout();
fail("A disabled user must not be allowed to login any more");
} catch (LoginException e) {
// success
}
// -> impersonating this user must fail
try {
Session ss = superuser.impersonate(new SimpleCredentials(userID, new char[0]));
ss.logout();
fail("A disabled user cannot be impersonated any more.");
} catch (LoginException e) {
// success
}
// enable user again
user.disable(null);
save(superuser);
assertFalse(user.isDisabled());
// -> login must succeed again
getHelper().getRepository().login(new SimpleCredentials(userID, pw.toCharArray())).logout();
} finally {
s.logout();
if (user != null) {
if (user.isDisabled()) {
user.disable(null);
}
if (remove) {
user.remove();
save(superuser);
}
}
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class CugImportBaseTest method testCugValidPrincipals.
@Test
public void testCugValidPrincipals() throws Exception {
testGroup = ((JackrabbitSession) adminSession).getUserManager().createGroup(new PrincipalImpl(TEST_GROUP_PRINCIPAL_NAME));
adminSession.save();
Node targetNode = getTargetNode();
targetNode.addMixin(CugConstants.MIX_REP_CUG_MIXIN);
doImport(getTargetPath(), XML_CUG_POLICY);
adminSession.save();
}
Aggregations