Search in sources :

Example 1 with IdentityRefImpl

use of org.olat.basesecurity.model.IdentityRefImpl in project OpenOLAT by OpenOLAT.

the class LDAPLoginManagerImpl method doBatchSyncNewAndModifiedUsers.

private List<LDAPUser> doBatchSyncNewAndModifiedUsers(LdapContext ctx, String sinceSentence, Map<String, LDAPUser> dnToIdentityKeyMap, LDAPError errors) {
    // Get new and modified users from LDAP
    int count = 0;
    List<LDAPUser> ldapUserList = ldapDao.getUserAttributesModifiedSince(lastSyncDate, ctx);
    // Check for new and modified users
    List<LDAPUser> newLdapUserList = new ArrayList<LDAPUser>();
    Map<IdentityRef, Map<String, String>> changedMapIdentityMap = new HashMap<>();
    for (LDAPUser ldapUser : ldapUserList) {
        String user = null;
        try {
            Attributes userAttrs = ldapUser.getAttributes();
            String uidProp = syncConfiguration.getOlatPropertyToLdapAttribute(LDAPConstants.LDAP_USER_IDENTIFYER);
            user = getAttributeValue(userAttrs.get(uidProp));
            Identity identity = findIdentityByLdapAuthentication(userAttrs, errors);
            if (identity != null) {
                Map<String, String> changedAttrMap = prepareUserPropertyForSync(userAttrs, identity);
                if (changedAttrMap != null) {
                    changedMapIdentityMap.put(identity, changedAttrMap);
                }
                if (StringHelper.containsNonWhitespace(ldapUser.getDn())) {
                    dnToIdentityKeyMap.put(ldapUser.getDn(), ldapUser);
                    ldapUser.setCachedIdentity(new IdentityRefImpl(identity.getKey()));
                }
            } else if (errors.isEmpty()) {
                String[] reqAttrs = syncConfiguration.checkRequestAttributes(userAttrs);
                if (reqAttrs == null) {
                    newLdapUserList.add(ldapUser);
                } else {
                    log.warn("LDAP batch sync: can't create user with username::" + user + " : missing required attributes::" + ArrayUtils.toString(reqAttrs), null);
                }
            } else {
                log.warn(errors.get(), null);
            }
        } catch (Exception e) {
            // catch here to go on with other users on exeptions!
            log.error("some error occured in looping over set of changed user-attributes, actual user " + user + ". Will still continue with others.", e);
            errors.insert("Cannot sync user: " + user);
        } finally {
            dbInstance.commit();
            if (count % 10 == 0) {
                dbInstance.closeSession();
            }
        }
        if (count % 1000 == 0) {
            log.info("Retrieve " + count + "/" + ldapUserList.size() + " users in LDAP server");
        }
        count++;
    }
    // sync existing users
    if (changedMapIdentityMap == null || changedMapIdentityMap.isEmpty()) {
        log.info("LDAP batch sync: no users to sync" + sinceSentence);
    } else {
        int syncCount = 0;
        for (IdentityRef ident : changedMapIdentityMap.keySet()) {
            // sync user is exception save, no try/catch needed
            try {
                syncCount++;
                syncUser(changedMapIdentityMap.get(ident), ident);
            } catch (Exception e) {
                errors.insert("Cannot sync user: " + ident);
            } finally {
                dbInstance.commit();
                if (syncCount % 20 == 0) {
                    dbInstance.closeSession();
                }
            }
            if (syncCount % 1000 == 0) {
                log.info("Update " + syncCount + "/" + changedMapIdentityMap.size() + " LDAP users");
            }
        }
        log.info("LDAP batch sync: " + changedMapIdentityMap.size() + " users synced" + sinceSentence);
    }
    // create new users
    if (newLdapUserList.isEmpty()) {
        log.info("LDAP batch sync: no users to create" + sinceSentence);
    } else {
        int newCount = 0;
        for (LDAPUser ldapUser : newLdapUserList) {
            Attributes userAttrs = ldapUser.getAttributes();
            try {
                newCount++;
                Identity identity = createAndPersistUser(userAttrs);
                if (identity != null && StringHelper.containsNonWhitespace(ldapUser.getDn())) {
                    dnToIdentityKeyMap.put(ldapUser.getDn(), ldapUser);
                    ldapUser.setCachedIdentity(new IdentityRefImpl(identity.getKey()));
                }
            } catch (Exception e) {
                // catch here to go on with other users on exeptions!
                log.error("some error occured while creating new users, actual userAttribs " + userAttrs + ". Will still continue with others.", e);
            } finally {
                dbInstance.commit();
                if (newCount % 20 == 0) {
                    dbInstance.closeSession();
                }
            }
            if (newCount % 1000 == 0) {
                log.info("Create " + count + "/" + newLdapUserList.size() + " LDAP users");
            }
        }
        log.info("LDAP batch sync: " + newLdapUserList.size() + " users created" + sinceSentence);
    }
    dbInstance.commitAndCloseSession();
    return ldapUserList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Attributes(javax.naming.directory.Attributes) LDAPUser(org.olat.ldap.model.LDAPUser) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) IdentityRef(org.olat.basesecurity.IdentityRef) Identity(org.olat.core.id.Identity) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with IdentityRefImpl

use of org.olat.basesecurity.model.IdentityRefImpl 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 3 with IdentityRefImpl

use of org.olat.basesecurity.model.IdentityRefImpl 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 4 with IdentityRefImpl

use of org.olat.basesecurity.model.IdentityRefImpl 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)

Example 5 with IdentityRefImpl

use of org.olat.basesecurity.model.IdentityRefImpl in project OpenOLAT by OpenOLAT.

the class IdentityListCourseNodeController method doUpdateCompletion.

private void doUpdateCompletion(Double completion, AssessmentRunStatus status, AssessedIdentityElementRow row) {
    row.getCurrentCompletion().setCompletion(completion);
    boolean endedRow = row.getCurrentCompletion().isEnded();
    boolean endedEvent = status != null && AssessmentRunStatus.done.equals(status);
    row.getCurrentCompletion().setEnded(endedEvent);
    if (endedEvent && !endedRow) {
        IdentityRef assessedIdentity = new IdentityRefImpl(row.getIdentityKey());
        AssessmentEntry assessmentEntry = assessmentToolManager.getAssessmentEntries(assessedIdentity, courseEntry, courseNode.getIdent());
        row.setAssessmentEntry(assessmentEntry);
        tableEl.getComponent().setDirty(true);
    }
}
Also used : IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) IdentityRef(org.olat.basesecurity.IdentityRef) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Aggregations

IdentityRef (org.olat.basesecurity.IdentityRef)18 IdentityRefImpl (org.olat.basesecurity.model.IdentityRefImpl)18 ArrayList (java.util.ArrayList)8 BusinessGroupRef (org.olat.group.BusinessGroupRef)6 RepositoryEntryRef (org.olat.repository.RepositoryEntryRef)6 RepositoryEntryRefImpl (org.olat.repository.model.RepositoryEntryRefImpl)6 OLATResource (org.olat.resource.OLATResource)6 HashMap (java.util.HashMap)4 BusinessGroupRefImpl (org.olat.group.model.BusinessGroupRefImpl)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)4 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 Map (java.util.Map)2 AuthenticationException (javax.naming.AuthenticationException)2 NamingException (javax.naming.NamingException)2 Attributes (javax.naming.directory.Attributes)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 Identity (org.olat.core.id.Identity)2 CertificateLight (org.olat.course.certificate.CertificateLight)2 CertificateLightPack (org.olat.course.certificate.model.CertificateLightPack)2