Skip to content
Snippets Groups Projects
Commit 9441e12c authored by srosse's avatar srosse
Browse files

OO-3057: tweak performance of the synchronization of LDAP groups, make a set...

OO-3057: tweak performance of the synchronization of LDAP groups, make a set of identity keys to match the users
parent af5ec82a
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ import java.util.ArrayList; ...@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
...@@ -1275,12 +1276,17 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, GenericEventListe ...@@ -1275,12 +1276,17 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, GenericEventListe
doSyncGroupByAttribute(ldapUsers, cnToGroupMap); doSyncGroupByAttribute(ldapUsers, cnToGroupMap);
} }
int syncGroupCount = 0;
for(LDAPGroup group:cnToGroupMap.values()) { for(LDAPGroup group:cnToGroupMap.values()) {
BusinessGroup managedGroup = getManagerBusinessGroup(group.getCommonName()); BusinessGroup managedGroup = getManagerBusinessGroup(group.getCommonName());
if(managedGroup != null) { if(managedGroup != null) {
syncBusinessGroup(ctx, managedGroup, group, dnToIdentityKeyMap, errors); syncBusinessGroup(ctx, managedGroup, group, dnToIdentityKeyMap, errors);
} }
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
if(syncGroupCount % 100 == 0) {
log.info("Synched " + syncGroupCount + "/" + cnToGroupMap.size() + " LDAP groups");
}
syncGroupCount++;
} }
} }
...@@ -1318,14 +1324,22 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, GenericEventListe ...@@ -1318,14 +1324,22 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, GenericEventListe
private void syncBusinessGroup(LdapContext ctx, BusinessGroup businessGroup, LDAPGroup ldapGroup, Map<String,LDAPUser> dnToIdentityKeyMap, LDAPError errors) { private void syncBusinessGroup(LdapContext ctx, BusinessGroup businessGroup, LDAPGroup ldapGroup, Map<String,LDAPUser> dnToIdentityKeyMap, LDAPError errors) {
List<Identity> currentMembers = businessGroupRelationDao List<Identity> currentMembers = businessGroupRelationDao
.getMembers(businessGroup, GroupRoles.coach.name(), GroupRoles.participant.name()); .getMembers(businessGroup, GroupRoles.coach.name(), GroupRoles.participant.name());
Set<Long> currentMemberKeys = new HashSet<>();
for(Identity currentMember:currentMembers) {
currentMemberKeys.add(currentMember.getKey());
}
List<LDAPUser> coaches = new ArrayList<>(ldapGroup.getCoaches()); List<LDAPUser> coaches = new ArrayList<>(ldapGroup.getCoaches());
List<LDAPUser> participants = new ArrayList<>(ldapGroup.getParticipants()); List<LDAPUser> participants = new ArrayList<>(ldapGroup.getParticipants());
// transfer member cn's to the participants list // transfer member cn's to the participants list
for(String member:ldapGroup.getMembers()) { for(String member:ldapGroup.getMembers()) {
LDAPUser ldapUser = getLDAPUser(ctx, member, dnToIdentityKeyMap, errors); dnToIdentityKeyMap.get(member); try {
if(ldapUser != null && !participants.contains(ldapUser)) { LDAPUser ldapUser = getLDAPUser(ctx, member, dnToIdentityKeyMap, errors); dnToIdentityKeyMap.get(member);
participants.add(ldapUser); if(ldapUser != null && !participants.contains(ldapUser)) {
participants.add(ldapUser);
}
} catch (Exception e) {
log.error("Cannot retrieve this LDAP group member: " + member, e);
} }
} }
// transfer to ldap user flagged as coach to the coach list // transfer to ldap user flagged as coach to the coach list
...@@ -1342,25 +1356,31 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, GenericEventListe ...@@ -1342,25 +1356,31 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, GenericEventListe
int count = 0; int count = 0;
for(LDAPUser participant:participants) { for(LDAPUser participant:participants) {
IdentityRef memberIdentity = participant.getCachedIdentity(); IdentityRef memberIdentity = participant.getCachedIdentity();
syncMembership(businessGroup, memberIdentity, false); if(memberIdentity != null && memberIdentity.getKey() != null) {
currentMembers.remove(memberIdentity); syncMembership(businessGroup, memberIdentity, false);
currentMemberKeys.remove(memberIdentity.getKey());
}
if(count % 20 == 0) { if(count % 20 == 0) {
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
} }
count++;
} }
for(LDAPUser coach:coaches) { for(LDAPUser coach:coaches) {
IdentityRef memberIdentity = coach.getCachedIdentity(); IdentityRef memberIdentity = coach.getCachedIdentity();
syncMembership(businessGroup, memberIdentity, true); if(memberIdentity != null && memberIdentity.getKey() != null) {
currentMembers.remove(memberIdentity); syncMembership(businessGroup, memberIdentity, true);
currentMemberKeys.remove(memberIdentity.getKey());
}
if(count % 20 == 0) { if(count % 20 == 0) {
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
} }
count++;
} }
for(Identity currentMember:currentMembers) { for(Long currentMemberKey:currentMemberKeys) {
Identity currentMember = securityManager.loadIdentityByKey(currentMemberKey);
List<String> roles = businessGroupRelationDao.getRoles(currentMember, businessGroup); List<String> roles = businessGroupRelationDao.getRoles(currentMember, businessGroup);
for(String role:roles) { for(String role:roles) {
businessGroupRelationDao.removeRole(currentMember, businessGroup, role); businessGroupRelationDao.removeRole(currentMember, businessGroup, role);
...@@ -1369,7 +1389,9 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, GenericEventListe ...@@ -1369,7 +1389,9 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, GenericEventListe
if(count % 20 == 0) { if(count % 20 == 0) {
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
} }
count++;
} }
dbInstance.commitAndCloseSession();
} }
private void syncMembership(BusinessGroup businessGroup, IdentityRef identityRef, boolean coach) { private void syncMembership(BusinessGroup businessGroup, IdentityRef identityRef, boolean coach) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment