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

OO-4842: synchronize coach as participant on LDAP sync

parent 4e47b03c
No related branches found
No related tags found
No related merge requests found
...@@ -99,6 +99,8 @@ public class LDAPSyncConfiguration { ...@@ -99,6 +99,8 @@ public class LDAPSyncConfiguration {
private String learningResourceManagerRoleAttribute; private String learningResourceManagerRoleAttribute;
private String learningResourceManagerRoleValue; private String learningResourceManagerRoleValue;
private String groupCoachAsParticipant;
/** /**
* Static user properties that should be added to user when syncing * Static user properties that should be added to user when syncing
*/ */
...@@ -260,6 +262,18 @@ public class LDAPSyncConfiguration { ...@@ -260,6 +262,18 @@ public class LDAPSyncConfiguration {
public void setAuthorRoleValue(String value) { public void setAuthorRoleValue(String value) {
this.authorRoleValue = value; this.authorRoleValue = value;
} }
public boolean isGroupCoachParticipant() {
return "true".equals(groupCoachAsParticipant);
}
public String getGroupCoachAsParticipant() {
return groupCoachAsParticipant;
}
public void setGroupCoachAsParticipant(String groupCoachAsParticipant) {
this.groupCoachAsParticipant = groupCoachAsParticipant;
}
public List<String> getUserManagersGroupBase() { public List<String> getUserManagersGroupBase() {
return userManagersGroupBase; return userManagersGroupBase;
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<property name="coachedGroupAttributeSeparator" value="${ldap.user.coachedGroupAttributeSeparator}"/> <property name="coachedGroupAttributeSeparator" value="${ldap.user.coachedGroupAttributeSeparator}"/>
<property name="coachRoleAttribute" value="${ldap.coachRoleAttribute}"/> <property name="coachRoleAttribute" value="${ldap.coachRoleAttribute}"/>
<property name="coachRoleValue" value="${ldap.coachRoleValue}"/> <property name="coachRoleValue" value="${ldap.coachRoleValue}"/>
<property name="groupCoachAsParticipant" value="${ldap.groupCoachAsParticipant}"/>
<!-- sync authors --> <!-- sync authors -->
<property name="authorsGroupBase" > <property name="authorsGroupBase" >
......
...@@ -26,6 +26,7 @@ import java.util.Date; ...@@ -26,6 +26,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration; import javax.naming.NamingEnumeration;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.naming.SizeLimitExceededException; import javax.naming.SizeLimitExceededException;
...@@ -144,15 +145,15 @@ public class LDAPDAO { ...@@ -144,15 +145,15 @@ public class LDAPDAO {
counter++; counter++;
} }
} catch (SizeLimitExceededException e) { } catch (SizeLimitExceededException e) {
log.error("SizeLimitExceededException after " log.error("SizeLimitExceededException after {} records when getting all users from LDAP, reconfigure your LDAP server, hints: http://www.ldapbrowser.com/forum/viewtopic.php?t=14", counter);
+ counter } catch (NameNotFoundException e) {
+ " records when getting all users from LDAP, reconfigure your LDAP server, hints: http://www.ldapbrowser.com/forum/viewtopic.php?t=14"); log.warn("Name not found: {} in base: {}", filter, ldapBase);
} catch (NamingException e) { } catch (NamingException e) {
log.error("NamingException when trying to search from LDAP using ldapBase::" + ldapBase + " on row::" + counter, e); log.error("NamingException when trying to search from LDAP using ldapBase::{} on row::{}", ldapBase,counter, e);
} catch (Exception e) { } catch (Exception e) {
log.error("Exception when trying to search from LDAP using ldapBase::" + ldapBase + " on row::" + counter, e); log.error("Exception when trying to search from LDAP using ldapBase::{} on row::{}", ldapBase, counter, e);
} }
log.debug("finished search for ldapBase:: " + ldapBase); log.debug("finished search for ldapBase:: {}", ldapBase);
} }
......
...@@ -614,7 +614,11 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro ...@@ -614,7 +614,11 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro
String olatProperty = mapLdapAttributeToOlatProperty(attr.getID()); String olatProperty = mapLdapAttributeToOlatProperty(attr.getID());
if (!attr.getID().equalsIgnoreCase(syncConfiguration.getOlatPropertyToLdapAttribute(LDAPConstants.LDAP_USER_IDENTIFYER)) ) { if (!attr.getID().equalsIgnoreCase(syncConfiguration.getOlatPropertyToLdapAttribute(LDAPConstants.LDAP_USER_IDENTIFYER)) ) {
String ldapValue = getAttributeValue(attr); String ldapValue = getAttributeValue(attr);
if (olatProperty == null || ldapValue == null) continue; if (olatProperty == null || ldapValue == null) {
continue;
} else if(ldapValue != null && ldapValue.length() > 250) {
ldapValue = ldapValue.substring(0, 250);
}
user.setProperty(olatProperty, ldapValue); user.setProperty(olatProperty, ldapValue);
} }
} }
...@@ -800,7 +804,8 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro ...@@ -800,7 +804,8 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro
boolean coach = groupList != null && groupList.contains(group.getCommonName()); boolean coach = groupList != null && groupList.contains(group.getCommonName());
if(coach) { if(coach) {
businessGroupRelationDao.addRole(identity, managedGroup, GroupRoles.coach.name()); businessGroupRelationDao.addRole(identity, managedGroup, GroupRoles.coach.name());
} else { }
if(!coach || syncConfiguration.isGroupCoachParticipant()) {
businessGroupRelationDao.addRole(identity, managedGroup, GroupRoles.participant.name()); businessGroupRelationDao.addRole(identity, managedGroup, GroupRoles.participant.name());
} }
} }
...@@ -1454,25 +1459,24 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro ...@@ -1454,25 +1459,24 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro
} }
int count = 0; int count = 0;
for(LDAPUser participant:participants) { Set<LDAPUser> members = new HashSet<>(participants);
IdentityRef memberIdentity = participant.getCachedIdentity(); members.addAll(coaches);
if(memberIdentity != null && memberIdentity.getKey() != null) { for(LDAPUser member:members) {
syncMembership(businessGroup, memberIdentity, false); boolean participant = participants.contains(member);
currentMemberKeys.remove(memberIdentity.getKey()); boolean coach = coaches.contains(member);
} if(syncConfiguration.isGroupCoachParticipant()) {
if(count % 20 == 0) { if(coach && !participant) {
dbInstance.commitAndCloseSession(); participant = true;
}
} else if(coach && participant) {
participant = false;
} }
count++;
} IdentityRef memberIdentity = member.getCachedIdentity();
for(LDAPUser coach:coaches) {
IdentityRef memberIdentity = coach.getCachedIdentity();
if(memberIdentity != null && memberIdentity.getKey() != null) { if(memberIdentity != null && memberIdentity.getKey() != null) {
syncMembership(businessGroup, memberIdentity, true); syncMemberships(businessGroup, memberIdentity, coach, participant);
currentMemberKeys.remove(memberIdentity.getKey()); currentMemberKeys.remove(memberIdentity.getKey());
} }
if(count % 20 == 0) { if(count % 20 == 0) {
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
} }
...@@ -1493,37 +1497,29 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro ...@@ -1493,37 +1497,29 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro
} }
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
} }
private void syncMembership(BusinessGroup businessGroup, IdentityRef identityRef, boolean coach) { private void syncMemberships(BusinessGroup businessGroup, IdentityRef identityRef, boolean coach, boolean participant) {
if(identityRef != null) { if(identityRef == null || businessGroup == null) return;
List<String> roles = businessGroupRelationDao.getRoles(identityRef, businessGroup);
if(roles.isEmpty()) { List<String> roles = businessGroupRelationDao.getRoles(identityRef, businessGroup);
Identity identity = securityManager.loadIdentityByKey(identityRef.getKey()); if((coach && participant && roles.size() == 2 && roles.contains(GroupRoles.coach.name()) && roles.contains(GroupRoles.participant.name()))
if(coach) { || (coach && !participant && roles.size() == 1 && roles.contains(GroupRoles.coach.name()))
businessGroupRelationDao.addRole(identity, businessGroup, GroupRoles.coach.name()); || (!coach && participant && roles.size() == 1 && roles.contains(GroupRoles.participant.name()))
} else { || (!coach && !participant && roles.isEmpty())) {
businessGroupRelationDao.addRole(identity, businessGroup, GroupRoles.participant.name()); return;// fail fast
} }
} else if(coach && roles.size() == 1 && roles.contains(GroupRoles.coach.name())) {
//coach and only coach, do nothing Identity identity = securityManager.loadIdentityByKey(identityRef.getKey());
} else if(!coach && roles.size() == 1 && roles.contains(GroupRoles.participant.name())) { if(coach && !roles.contains(GroupRoles.coach.name())) {
//participant and only participant, do nothing businessGroupRelationDao.addRole(identity, businessGroup, GroupRoles.coach.name());
} else { } else if(!coach && roles.contains(GroupRoles.coach.name())) {
boolean already = false; businessGroupRelationDao.removeRole(identity, businessGroup, GroupRoles.coach.name());
Identity identity = securityManager.loadIdentityByKey(identityRef.getKey()); }
String mainRole = coach ? GroupRoles.coach.name() : GroupRoles.participant.name();
for(String role:roles) { if(participant && !roles.contains(GroupRoles.participant.name())) {
if(mainRole.equals(role)) { businessGroupRelationDao.addRole(identity, businessGroup, GroupRoles.participant.name());
already = true; } else if(!participant && roles.contains(GroupRoles.participant.name())) {
} else { businessGroupRelationDao.removeRole(identity, businessGroup, GroupRoles.participant.name());
businessGroupRelationDao.removeRole(identity, businessGroup, role);
}
}
if(!already) {
businessGroupRelationDao.addRole(identity, businessGroup, mainRole);
}
}
} }
} }
...@@ -1533,7 +1529,7 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro ...@@ -1533,7 +1529,7 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro
List<BusinessGroup> businessGroups = businessGroupService.findBusinessGroups(params, null, 0, -1); List<BusinessGroup> businessGroups = businessGroupService.findBusinessGroups(params, null, 0, -1);
BusinessGroup managedBusinessGroup; BusinessGroup managedBusinessGroup;
if(businessGroups.size() == 0) { if(businessGroups.isEmpty()) {
String managedFlags = BusinessGroupManagedFlag.membersmanagement.name() + "," + BusinessGroupManagedFlag.delete.name(); String managedFlags = BusinessGroupManagedFlag.membersmanagement.name() + "," + BusinessGroupManagedFlag.delete.name();
managedBusinessGroup = businessGroupService managedBusinessGroup = businessGroupService
.createBusinessGroup(null, externalId, externalId, externalId, managedFlags, null, null, false, false, null); .createBusinessGroup(null, externalId, externalId, externalId, managedFlags, null, null, false, false, null);
...@@ -1541,7 +1537,7 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro ...@@ -1541,7 +1537,7 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, AuthenticationPro
} else if(businessGroups.size() == 1) { } else if(businessGroups.size() == 1) {
managedBusinessGroup = businessGroups.get(0); managedBusinessGroup = businessGroups.get(0);
} else { } else {
log.error(businessGroups.size() + " managed groups found with the following external id: " + externalId); log.error("{} managed groups found with the following external id: {}", businessGroups.size(), externalId);
managedBusinessGroup = null; managedBusinessGroup = null;
} }
return managedBusinessGroup; return managedBusinessGroup;
......
...@@ -1304,6 +1304,8 @@ ldap.user.groupAttributeSeparator=, ...@@ -1304,6 +1304,8 @@ ldap.user.groupAttributeSeparator=,
ldap.user.coachedGroupAttribute= ldap.user.coachedGroupAttribute=
ldap.user.coachedGroupAttribute.values=o ldap.user.coachedGroupAttribute.values=o
ldap.user.coachedGroupAttributeSeparator=, ldap.user.coachedGroupAttributeSeparator=,
# sync group coaches as participant too
ldap.groupCoachAsParticipant=false
# sync authors # sync authors
ldap.authorsGroupBases= ldap.authorsGroupBases=
......
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