use of org.olat.basesecurity.IdentityRef in project OpenOLAT by OpenOLAT.
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.basesecurity.IdentityRef in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.basesecurity.IdentityRef in project OpenOLAT by OpenOLAT.
the class DownloadCertificateCellRenderer method render.
@Override
public void render(Renderer renderer, StringOutput target, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
if (renderer == null) {
if (cellValue instanceof CertificateLight) {
renderExcel(target, (CertificateLight) cellValue);
} else if (cellValue instanceof CertificateLightPack) {
CertificateLightPack pack = (CertificateLightPack) cellValue;
renderExcel(target, pack.getCertificate());
}
} else if (cellValue instanceof CertificateLight) {
CertificateLight certificate = (CertificateLight) cellValue;
if (assessedIdentity == null) {
IdentityRef idRef = new IdentityRefImpl(certificate.getIdentityKey());
render(target, certificate, idRef, translator.getLocale());
} else {
render(target, certificate, assessedIdentity, translator.getLocale());
}
} else if (cellValue instanceof CertificateLightPack) {
CertificateLightPack pack = (CertificateLightPack) cellValue;
render(target, pack.getCertificate(), pack.getIdentity(), translator.getLocale());
}
}
use of org.olat.basesecurity.IdentityRef in project OpenOLAT by OpenOLAT.
the class BusinessGroupMembershipProcessor method processResourceRemoved.
private void processResourceRemoved(Long groupKey, Long repoKey) {
BusinessGroupRef groupRef = new BusinessGroupRefImpl(groupKey);
RepositoryEntryRef entryRef = new RepositoryEntryRefImpl(repoKey);
OLATResource resource = repositoryManager.lookupRepositoryEntryResource(entryRef.getKey());
List<Long> memberKeys = businessGroupRelationDao.getMemberKeys(Collections.singletonList(groupRef), GroupRoles.coach.name(), GroupRoles.participant.name());
for (Long memberKey : memberKeys) {
IdentityRef member = new IdentityRefImpl(memberKey);
List<String> remaingRoles = repositoryEntryRelationDao.getRoles(member, entryRef);
if (remaingRoles.isEmpty()) {
notificationsManager.unsubscribeAllForIdentityAndResId(member, resource.getResourceableId());
}
}
}
use of org.olat.basesecurity.IdentityRef in project OpenOLAT by OpenOLAT.
the class BusinessGroupRelationDAO method getDuplicateMemberships.
/**
* @param groups
* @return The list of identity key which have multiple memberships in the specified groups
*/
public List<IdentityRef> getDuplicateMemberships(List<? extends BusinessGroupRef> groups) {
if (groups == null || groups.isEmpty())
return Collections.emptyList();
StringBuilder sb = new StringBuilder();
sb.append("select count(membership.key ), membership.identity.key from businessgroup as bgroup ").append(" inner join bgroup.baseGroup as baseGroup").append(" inner join baseGroup.members as membership").append(" where bgroup.key in (:businessGroupKeys) and membership.role='participant'").append(" group by membership.identity.key");
List<Long> groupKeys = new ArrayList<>(groups.size());
for (BusinessGroupRef group : groups) {
groupKeys.add(group.getKey());
}
List<Object[]> groupBy = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("businessGroupKeys", groupKeys).getResultList();
List<IdentityRef> duplicates = new ArrayList<>();
for (Object[] id : groupBy) {
Number numOfMembership = (Number) id[0];
Long identityKey = (Long) id[1];
if (numOfMembership.longValue() > 1) {
duplicates.add(new IdentityRefImpl(identityKey));
}
}
return duplicates;
}
Aggregations