Search in sources :

Example 6 with IdentityRef

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();
}
Also used : ArrayList(java.util.ArrayList) LDAPUser(org.olat.ldap.model.LDAPUser) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) IdentityRef(org.olat.basesecurity.IdentityRef) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 7 with IdentityRef

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;
}
Also used : IdentityRef(org.olat.basesecurity.IdentityRef) Attributes(javax.naming.directory.Attributes) LDAPUser(org.olat.ldap.model.LDAPUser)

Example 8 with IdentityRef

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());
    }
}
Also used : IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) CertificateLightPack(org.olat.course.certificate.model.CertificateLightPack) IdentityRef(org.olat.basesecurity.IdentityRef) CertificateLight(org.olat.course.certificate.CertificateLight)

Example 9 with IdentityRef

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());
        }
    }
}
Also used : BusinessGroupRef(org.olat.group.BusinessGroupRef) IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) RepositoryEntryRefImpl(org.olat.repository.model.RepositoryEntryRefImpl) IdentityRef(org.olat.basesecurity.IdentityRef) OLATResource(org.olat.resource.OLATResource) BusinessGroupRefImpl(org.olat.group.model.BusinessGroupRefImpl) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 10 with IdentityRef

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;
}
Also used : BusinessGroupRef(org.olat.group.BusinessGroupRef) IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) IdentityRef(org.olat.basesecurity.IdentityRef) ArrayList(java.util.ArrayList)

Aggregations

IdentityRef (org.olat.basesecurity.IdentityRef)36 ArrayList (java.util.ArrayList)18 IdentityRefImpl (org.olat.basesecurity.model.IdentityRefImpl)18 Identity (org.olat.core.id.Identity)8 BusinessGroupRef (org.olat.group.BusinessGroupRef)8 LDAPUser (org.olat.ldap.model.LDAPUser)8 RepositoryEntryRef (org.olat.repository.RepositoryEntryRef)6 RepositoryEntryRefImpl (org.olat.repository.model.RepositoryEntryRefImpl)6 OLATResource (org.olat.resource.OLATResource)6 HashMap (java.util.HashMap)4 AuthenticationException (javax.naming.AuthenticationException)4 NamingException (javax.naming.NamingException)4 Attributes (javax.naming.directory.Attributes)4 GroupRoles (org.olat.basesecurity.GroupRoles)4 Roles (org.olat.core.id.Roles)4 BusinessGroupRefImpl (org.olat.group.model.BusinessGroupRefImpl)4 ModuleConfiguration (org.olat.modules.ModuleConfiguration)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)3 File (java.io.File)2