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