use of org.olat.ldap.model.LDAPUser in project openolat by klemens.
the class LDAPLoginManagerImpl method syncBusinessGroup.
private void syncBusinessGroup(LdapContext ctx, BusinessGroup businessGroup, LDAPGroup ldapGroup, Map<String, LDAPUser> dnToIdentityKeyMap, LDAPError errors) {
List<Identity> currentMembers = businessGroupRelationDao.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> participants = new ArrayList<>(ldapGroup.getParticipants());
// transfer member cn's to the participants list
for (String member : ldapGroup.getMembers()) {
try {
LDAPUser ldapUser = getLDAPUser(ctx, member, dnToIdentityKeyMap, errors);
dnToIdentityKeyMap.get(member);
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
for (Iterator<LDAPUser> participantIt = participants.iterator(); participantIt.hasNext(); ) {
LDAPUser participant = participantIt.next();
if (participant.isCoach()) {
if (!coaches.contains(participant)) {
coaches.add(participant);
}
participantIt.remove();
}
}
int count = 0;
for (LDAPUser participant : participants) {
IdentityRef memberIdentity = participant.getCachedIdentity();
if (memberIdentity != null && memberIdentity.getKey() != null) {
syncMembership(businessGroup, memberIdentity, false);
currentMemberKeys.remove(memberIdentity.getKey());
}
if (count % 20 == 0) {
dbInstance.commitAndCloseSession();
}
count++;
}
for (LDAPUser coach : coaches) {
IdentityRef memberIdentity = coach.getCachedIdentity();
if (memberIdentity != null && memberIdentity.getKey() != null) {
syncMembership(businessGroup, memberIdentity, true);
currentMemberKeys.remove(memberIdentity.getKey());
}
if (count % 20 == 0) {
dbInstance.commitAndCloseSession();
}
count++;
}
for (Long currentMemberKey : currentMemberKeys) {
Identity currentMember = securityManager.loadIdentityByKey(currentMemberKey);
List<String> roles = businessGroupRelationDao.getRoles(currentMember, businessGroup);
for (String role : roles) {
businessGroupRelationDao.removeRole(currentMember, businessGroup, role);
}
if (count % 20 == 0) {
dbInstance.commitAndCloseSession();
}
count++;
}
dbInstance.commitAndCloseSession();
}
use of org.olat.ldap.model.LDAPUser in project openolat by klemens.
the class LDAPLoginManagerImpl method getLDAPUser.
private LDAPUser getLDAPUser(LdapContext ctx, String member, Map<String, LDAPUser> dnToIdentityKeyMap, LDAPError errors) {
LDAPUser ldapUser = dnToIdentityKeyMap.get(member);
IdentityRef identity = ldapUser == null ? null : ldapUser.getCachedIdentity();
if (identity == null) {
String userFilter = syncConfiguration.getLdapUserFilter();
String userDN = member;
LDAPUserVisitor visitor = new LDAPUserVisitor(syncConfiguration);
ldapDao.search(visitor, userDN, userFilter, syncConfiguration.getUserAttributes(), ctx);
List<LDAPUser> ldapUserList = visitor.getLdapUserList();
if (ldapUserList.size() == 1) {
ldapUser = ldapUserList.get(0);
Attributes userAttrs = ldapUser.getAttributes();
identity = findIdentityByLdapAuthentication(userAttrs, errors);
if (identity != null) {
dnToIdentityKeyMap.put(userDN, ldapUser);
}
}
}
return ldapUser;
}
Aggregations