con.setHostname(TestConfiguration.d1hostname);
con.setPort(Integer.toString(TestConfiguration.d1port));
con.setPrincipal(TestConfiguration.d1principal);
con.setPassword(TestConfiguration.d1password);
con.setDataSource(dbType, TestConfiguration.dbs.get(dbType));
Session s = con.login();
s.getTraversalManager().resumeTraversal(null);
// delete the user, create same one with different GUID
ad.initialize();
ad.deleteEntity(user);
ad.createUser(false, user, ou);
// recrawl AD
s.getTraversalManager().resumeTraversal(null);
AuthenticationResponse response = s.getAuthenticationManager()
.authenticate(new SimpleAuthenticationIdentity(
user.sAMAccountName, TestConfiguration.password));
assertTrue("Authentication must succeed for resurrected user",
response.isValid());
assertFalse(
"New user mustn't belong to the group he belonged to prior deletion",
response.getGroups().contains(
new Principal(group.sAMAccountName.toLowerCase())));
// add new user as member to the group
ad.initialize();
group.children.add(user);
ad.setMembers(false, group);
s.getTraversalManager().resumeTraversal(null);
// delete the group, create the same one with different GUID
ad.deleteEntity(group);
ad.createGroup(false, group, ou);
s.getTraversalManager().resumeTraversal(null);
response = s.getAuthenticationManager().authenticate(
new SimpleAuthenticationIdentity(
user.sAMAccountName, TestConfiguration.password));
assertTrue("User from resurrected group can be authenticated",
response.isValid());