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());
}
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;
}
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();
}
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;
}
}
}
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;
}
Aggregations