use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class ExternalLoginModuleAutoMembershipTest method testLoginAfterSyncSetup3.
@Test
public void testLoginAfterSyncSetup3() throws Exception {
setup3.sync(USER_ID, false);
ContentSession cs = null;
try {
cs = login(new SimpleCredentials(USER_ID, new char[0]));
// the login must set the existing auto-membership principals to the subject
Set<Principal> principals = cs.getAuthInfo().getPrincipals();
assertTrue(principals.contains(setup3.gr.getPrincipal()));
assertFalse(principals.contains(new PrincipalImpl(NON_EXISTING_NAME)));
assertFalse(principals.contains(setup1.gr.getPrincipal()));
assertFalse(principals.contains(setup2.gr.getPrincipal()));
// however, the existing auto-membership group must _not_ have changed
// and the test user must not be a stored member of this group.
root.refresh();
UserManager uMgr = getUserManager(root);
User user = uMgr.getAuthorizable(USER_ID, User.class);
Group gr = uMgr.getAuthorizable(setup3.gr.getID(), Group.class);
assertTrue(gr.isDeclaredMember(user));
assertTrue(gr.isMember(user));
} finally {
options.clear();
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class ExternalLoginModuleAutoMembershipTest method testLoginAfterSyncSetup2.
@Test
public void testLoginAfterSyncSetup2() throws Exception {
setup2.sync(USER_ID, false);
ContentSession cs = null;
try {
cs = login(new SimpleCredentials(USER_ID, new char[0]));
// the login must set the existing auto-membership principals to the subject
Set<Principal> principals = cs.getAuthInfo().getPrincipals();
assertTrue(principals.contains(setup2.gr.getPrincipal()));
assertFalse(principals.contains(new PrincipalImpl(NON_EXISTING_NAME)));
assertFalse(principals.contains(setup1.gr.getPrincipal()));
assertFalse(principals.contains(setup3.gr.getPrincipal()));
// however, the existing auto-membership group must _not_ have changed
// and the test user must not be a stored member of this group.
root.refresh();
UserManager uMgr = getUserManager(root);
User user = uMgr.getAuthorizable(USER_ID, User.class);
Group gr = uMgr.getAuthorizable(setup2.gr.getID(), Group.class);
assertFalse(gr.isDeclaredMember(user));
assertFalse(gr.isMember(user));
} finally {
options.clear();
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class ExternalLoginModuleAutoMembershipTest method testLoginAfterSyncSetup4.
@Test
public void testLoginAfterSyncSetup4() throws Exception {
setup4.sync(USER_ID, false);
ContentSession cs = null;
try {
cs = login(new SimpleCredentials(USER_ID, new char[0]));
// the login must set the existing auto-membership principals to the subject
Set<Principal> principals = cs.getAuthInfo().getPrincipals();
assertTrue(principals.contains(setup4.gr.getPrincipal()));
assertTrue(principals.contains(setup2.gr.getPrincipal()));
assertFalse(principals.contains(new PrincipalImpl(NON_EXISTING_NAME)));
assertFalse(principals.contains(setup1.gr.getPrincipal()));
assertFalse(principals.contains(setup3.gr.getPrincipal()));
// however, the existing auto-membership group must _not_ have changed
// and the test user must not be a stored member of this group.
root.refresh();
UserManager uMgr = getUserManager(root);
User user = uMgr.getAuthorizable(USER_ID, User.class);
Group gr = uMgr.getAuthorizable(setup4.gr.getID(), Group.class);
assertFalse(gr.isDeclaredMember(user));
assertFalse(gr.isMember(user));
} finally {
options.clear();
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class ExternalLoginModuleDynamicMembershipTest method testLoginPopulatesPrincipals.
@Test
public void testLoginPopulatesPrincipals() throws Exception {
ContentSession cs = null;
try {
cs = login(new SimpleCredentials(USER_ID, new char[0]));
Set<String> expectedExternal = new HashSet<String>();
calcExpectedPrincipalNames(idp.getUser(USER_ID), syncConfig.user().getMembershipNestingDepth(), expectedExternal);
Set<Principal> principals = new HashSet<Principal>(cs.getAuthInfo().getPrincipals());
root.refresh();
PrincipalManager principalManager = getPrincipalManager(root);
for (String pName : expectedExternal) {
Principal p = principalManager.getPrincipal(pName);
assertNotNull(p);
assertTrue(principals.remove(p));
}
UserManager uMgr = getUserManager(root);
User u = uMgr.getAuthorizable(USER_ID, User.class);
assertTrue(principals.remove(u.getPrincipal()));
Iterator<Group> it = u.memberOf();
assertFalse(it.hasNext());
assertTrue(principals.remove(EveryonePrincipal.getInstance()));
assertTrue(principals.isEmpty());
} finally {
if (cs != null) {
cs.close();
}
options.clear();
}
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class ExternalLoginModuleTest method testSyncCreateGroupNesting.
@Test
public void testSyncCreateGroupNesting() throws Exception {
syncConfig.user().setMembershipNestingDepth(2);
UserManager userManager = getUserManager(root);
ContentSession cs = null;
try {
cs = login(new SimpleCredentials(USER_ID, new char[0]));
root.refresh();
for (String id : new String[] { "a", "b", "c", "aa", "aaa" }) {
assertNotNull(userManager.getAuthorizable(id));
}
} finally {
if (cs != null) {
cs.close();
}
options.clear();
}
}
Aggregations