use of org.olat.ldap.model.LDAPGroup in project openolat by klemens.
the class LDAPGroupVisitor method visit.
@Override
public void visit(SearchResult searchResult) throws NamingException {
Attributes resAttributes = searchResult.getAttributes();
Attribute memberAttr = resAttributes.get("member");
Attribute cnAttr = resAttributes.get("cn");
if (memberAttr != null) {
LDAPGroup group = new LDAPGroup();
Object cn = cnAttr.get();
if (cn instanceof String) {
group.setCommonName((String) cn);
}
List<String> members = new ArrayList<String>();
try {
for (NamingEnumeration<?> memberEn = memberAttr.getAll(); memberEn.hasMoreElements(); ) {
Object member = memberEn.next();
if (member instanceof String) {
members.add((String) member);
}
}
} catch (NamingException e) {
log.error("", e);
}
group.setMembers(members);
groups.add(group);
}
}
use of org.olat.ldap.model.LDAPGroup in project openolat by klemens.
the class LDAPLoginManagerImpl method doSyncGroupByAttribute.
private void doSyncGroupByAttribute(List<LDAPUser> ldapUsers, Map<String, LDAPGroup> cnToGroupMap) {
for (LDAPUser ldapUser : ldapUsers) {
List<String> groupIds = ldapUser.getGroupIds();
List<String> coachedGroupIds = ldapUser.getCoachedGroupIds();
if ((groupIds != null && groupIds.size() > 0) || (coachedGroupIds != null && coachedGroupIds.size() > 0)) {
IdentityRef identity = ldapUser.getCachedIdentity();
if (identity == null) {
log.error("Identity with dn=" + ldapUser.getDn() + " not found");
} else {
if (groupIds != null && groupIds.size() > 0) {
for (String groupId : groupIds) {
if (!cnToGroupMap.containsKey(groupId)) {
cnToGroupMap.put(groupId, new LDAPGroup(groupId));
}
cnToGroupMap.get(groupId).getParticipants().add(ldapUser);
}
}
if (coachedGroupIds != null && coachedGroupIds.size() > 0) {
for (String coachedGroupId : coachedGroupIds) {
if (!cnToGroupMap.containsKey(coachedGroupId)) {
cnToGroupMap.put(coachedGroupId, new LDAPGroup(coachedGroupId));
}
cnToGroupMap.get(coachedGroupId).getCoaches().add(ldapUser);
}
}
}
}
}
}
use of org.olat.ldap.model.LDAPGroup in project openolat by klemens.
the class LDAPLoginManagerImpl method syncRole.
private void syncRole(LdapContext ctx, List<LDAPGroup> groups, String role, Map<String, LDAPUser> dnToIdentityKeyMap, LDAPError errors) {
if (groups == null || groups.isEmpty())
return;
for (LDAPGroup group : groups) {
List<String> members = group.getMembers();
if (members != null && members.size() > 0) {
for (String member : members) {
LDAPUser ldapUser = getLDAPUser(ctx, member, dnToIdentityKeyMap, errors);
if (ldapUser != null && ldapUser.getCachedIdentity() != null) {
syncRole(ldapUser, role);
}
}
}
dbInstance.commitAndCloseSession();
}
}
use of org.olat.ldap.model.LDAPGroup in project openolat by klemens.
the class LDAPLoginManagerImpl method doBatchSyncGroups.
private void doBatchSyncGroups(LdapContext ctx, List<LDAPUser> ldapUsers, Map<String, LDAPUser> dnToIdentityKeyMap, LDAPError errors) throws NamingException {
ctx.close();
log.info("LDAP batch sync LDAP user to OO groups");
ctx = bindSystem();
// sync groups by LDAP groups or attributes
Map<String, LDAPGroup> cnToGroupMap = new HashMap<>();
// retrieve all ldap group's with their list of members
if (syncConfiguration.syncGroupWithLDAPGroup()) {
List<String> groupDNs = syncConfiguration.getLdapGroupBases();
List<LDAPGroup> ldapGroups = ldapDao.searchGroups(ctx, groupDNs);
for (LDAPGroup ldapGroup : ldapGroups) {
cnToGroupMap.put(ldapGroup.getCommonName(), ldapGroup);
}
}
if (syncConfiguration.syncGroupWithAttribute()) {
doSyncGroupByAttribute(ldapUsers, cnToGroupMap);
}
int syncGroupCount = 0;
for (LDAPGroup group : cnToGroupMap.values()) {
BusinessGroup managedGroup = getManagerBusinessGroup(group.getCommonName());
if (managedGroup != null) {
syncBusinessGroup(ctx, managedGroup, group, dnToIdentityKeyMap, errors);
}
dbInstance.commitAndCloseSession();
if (syncGroupCount % 100 == 0) {
log.info("Synched " + syncGroupCount + "/" + cnToGroupMap.size() + " LDAP groups");
}
syncGroupCount++;
}
}
Aggregations