boolean usersSyncedAtStartup = LDAPLoginModule.isLdapSyncOnStartup();
if (usersSyncedAtStartup) {
try {
//create user but with different attributes - must fail since user already exists
User user = UserManager.getInstance().createUser("klaus", "Meier", "klaus@meier.ch");
Identity identity = securityManager.createAndPersistIdentityAndUser("kmeier", user, "LDAP", "kmeier", null);
SecurityGroup secGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
securityManager.addIdentityToSecurityGroup(identity, secGroup);
// simulate closed session (user adding from startup job)
DBFactory.getInstance().intermediateCommit();
fail("Expected constrant violation becaus of doupliate entry");
} catch (Exception e) {
// success, this is what we expected
}
//changedAttrMap empty since already synchronized
Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
Identity identitys = securityManager.findIdentityByName(uid);
Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
// map is empty - no attributes to sync
assertNull(changedAttrMap);
} else {
//create user but with different attributes - must fail since user already exists
User user = UserManager.getInstance().createUser("klaus", "Meier", "klaus@meier.ch");
Identity identity = securityManager.createAndPersistIdentityAndUser("kmeier", user, "LDAP", "kmeier", null);
SecurityGroup secGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
securityManager.addIdentityToSecurityGroup(identity, secGroup);
// simulate closed session (user adding from startup job)
DBFactory.getInstance().intermediateCommit();