Search in sources :

Example 1 with IdentityRef

use of org.olat.basesecurity.IdentityRef in project OpenOLAT by OpenOLAT.

the class BusinessGroupRelationDAOTest method getDuplicateMemberships.

@Test
public void getDuplicateMemberships() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("wait-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("wait-1");
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "to-group-1", "to-group-1-desc", -1, -1, false, false, false, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "to-group-2", "to-group-2-desc", -1, -1, false, false, false, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "to-group-2", "to-group-2-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(id1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id1, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, group3, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // id1 is a duplicate
    List<BusinessGroup> groups = new ArrayList<>(2);
    groups.add(group1);
    groups.add(group2);
    groups.add(group3);
    List<IdentityRef> duplicates = businessGroupRelationDao.getDuplicateMemberships(groups);
    Assert.assertNotNull(duplicates);
    Assert.assertEquals(1, duplicates.size());
    Assert.assertEquals(id1.getKey(), duplicates.get(0).getKey());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) IdentityRef(org.olat.basesecurity.IdentityRef) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 2 with IdentityRef

use of org.olat.basesecurity.IdentityRef in project OpenOLAT by OpenOLAT.

the class GTAManagerImpl method getDuplicatedMemberships.

@Override
public List<IdentityRef> getDuplicatedMemberships(GTACourseNode cNode) {
    List<IdentityRef> duplicates;
    ModuleConfiguration config = cNode.getModuleConfiguration();
    if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
        List<Long> groupKeys = config.getList(GTACourseNode.GTASK_GROUPS, Long.class);
        List<Long> areaKeys = config.getList(GTACourseNode.GTASK_AREAS, Long.class);
        List<Long> consolidatedGroupKeys = new ArrayList<>();
        if (groupKeys != null && groupKeys.size() > 0) {
            consolidatedGroupKeys.addAll(groupKeys);
        }
        consolidatedGroupKeys.addAll(areaManager.findBusinessGroupKeysOfAreaKeys(areaKeys));
        List<BusinessGroupRef> businessGroups = BusinessGroupRefImpl.toRefs(consolidatedGroupKeys);
        duplicates = businessGroupRelationDao.getDuplicateMemberships(businessGroups);
    } else {
        duplicates = Collections.emptyList();
    }
    return duplicates;
}
Also used : BusinessGroupRef(org.olat.group.BusinessGroupRef) ModuleConfiguration(org.olat.modules.ModuleConfiguration) IdentityRef(org.olat.basesecurity.IdentityRef) ArrayList(java.util.ArrayList)

Example 3 with IdentityRef

use of org.olat.basesecurity.IdentityRef in project OpenOLAT by OpenOLAT.

the class IQIdentityListCourseNodeController method doConfirmExtraTime.

private void doConfirmExtraTime(UserRequest ureq) {
    List<IdentityRef> identities = getSelectedIdentities();
    if (identities == null || identities.isEmpty()) {
        showWarning("warning.users.extra.time");
        return;
    }
    List<AssessmentTestSession> testSessions = new ArrayList<>(identities.size());
    for (IdentityRef identity : identities) {
        List<AssessmentTestSessionStatistics> sessionsStatistics = qtiService.getAssessmentTestSessionsStatistics(getCourseRepositoryEntry(), courseNode.getIdent(), identity);
        if (!sessionsStatistics.isEmpty()) {
            if (sessionsStatistics.size() > 1) {
                Collections.sort(sessionsStatistics, new AssessmentTestSessionDetailsComparator());
            }
            AssessmentTestSession lastSession = sessionsStatistics.get(0).getTestSession();
            if (lastSession != null && lastSession.getFinishTime() == null) {
                testSessions.add(lastSession);
            }
        }
    }
    if (testSessions == null || testSessions.isEmpty()) {
        showWarning("warning.users.extra.time");
        return;
    }
    extraTimeCtrl = new ConfirmExtraTimeController(ureq, getWindowControl(), getCourseRepositoryEntry(), testSessions);
    listenTo(extraTimeCtrl);
    String title = translate("extra.time");
    cmc = new CloseableModalController(getWindowControl(), null, extraTimeCtrl.getInitialComponent(), true, title, true);
    listenTo(cmc);
    cmc.activate();
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) AssessmentTestSessionDetailsComparator(org.olat.course.nodes.iq.QTI21IdentityListCourseNodeToolsController.AssessmentTestSessionDetailsComparator) AssessmentTestSessionStatistics(org.olat.ims.qti21.model.jpa.AssessmentTestSessionStatistics) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) IdentityRef(org.olat.basesecurity.IdentityRef) ArrayList(java.util.ArrayList)

Example 4 with IdentityRef

use of org.olat.basesecurity.IdentityRef in project OpenOLAT by OpenOLAT.

the class LDAPLoginManagerImpl method syncRole.

private void syncRole(LDAPUser ldapUser, String role) {
    IdentityRef identityRef = ldapUser.getCachedIdentity();
    List<String> roleList = securityManager.getRolesAsString(identityRef);
    if (!roleList.contains(role)) {
        Identity identity = securityManager.loadIdentityByKey(identityRef.getKey());
        Roles roles = securityManager.getRoles(identity);
        switch(role) {
            case Constants.GROUP_AUTHORS:
                roles = new Roles(roles.isOLATAdmin(), roles.isUserManager(), roles.isGroupManager(), true, false, roles.isInstitutionalResourceManager(), roles.isPoolAdmin(), false);
                securityManager.updateRoles(null, identity, roles);
                break;
            case Constants.GROUP_USERMANAGERS:
                roles = new Roles(roles.isOLATAdmin(), true, roles.isGroupManager(), roles.isAuthor(), false, roles.isInstitutionalResourceManager(), roles.isPoolAdmin(), false);
                securityManager.updateRoles(null, identity, roles);
                break;
            case Constants.GROUP_GROUPMANAGERS:
                roles = new Roles(roles.isOLATAdmin(), roles.isUserManager(), true, roles.isAuthor(), false, roles.isInstitutionalResourceManager(), roles.isPoolAdmin(), false);
                securityManager.updateRoles(null, identity, roles);
                break;
            case Constants.GROUP_POOL_MANAGER:
                roles = new Roles(roles.isOLATAdmin(), roles.isUserManager(), roles.isGroupManager(), roles.isAuthor(), false, roles.isInstitutionalResourceManager(), true, false);
                securityManager.updateRoles(null, identity, roles);
                break;
            case Constants.GROUP_INST_ORES_MANAGER:
                roles = new Roles(roles.isOLATAdmin(), roles.isUserManager(), roles.isGroupManager(), roles.isAuthor(), false, true, roles.isPoolAdmin(), false);
                securityManager.updateRoles(null, identity, roles);
                break;
        }
    }
}
Also used : IdentityRef(org.olat.basesecurity.IdentityRef) Roles(org.olat.core.id.Roles) GroupRoles(org.olat.basesecurity.GroupRoles) Identity(org.olat.core.id.Identity)

Example 5 with IdentityRef

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

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