con.setPrincipal(TestConfiguration.d1principal);
con.setPassword(TestConfiguration.d1password);
con.setDataSource(dbType, TestConfiguration.dbs.get(dbType));
con.setIncludeBuiltinGroups(true);
Session s = con.login();
s.getTraversalManager().startTraversal();
AuthenticationManager am = s.getAuthenticationManager();
String username = TestConfiguration.d1principal.split("\\\\")[1];
AuthenticationResponse response = am.authenticate(
new SimpleAuthenticationIdentity(username));
assertNotNull(response);
Collection<Principal> principals = getGroups(response);
assertNotNull(principals);
assertTrue(principals.size() > 0);
// Count the builtin groups to make sure at least one is found.
ArrayList<Principal> groupsFound = new ArrayList<Principal>();
int foundCount = 0;
for (Principal principal : principals) {
if (isBuiltin(principal.getName())) {
foundCount++;
} else {
groupsFound.add(principal);
}
}
assertTrue(foundCount > 0);
// Run the traversal again, this time excluding builtin groups.
con.setIncludeBuiltinGroups(false);
am = s.getAuthenticationManager();
response = am.authenticate(new SimpleAuthenticationIdentity(username));
principals = getGroups(response);
assertNotNull(principals);
assertTrue(principals.size() > 0);