use of org.olat.registration.TemporaryKey in project openolat by klemens.
the class UserDeletionManager method deleteIdentity.
/**
* Delete all user-data in registered deleteable resources.
* @param identity
* @return true
*/
public void deleteIdentity(Identity identity) {
logInfo("Start deleteIdentity for identity=" + identity);
String newName = getBackupStringWithDate(identity.getName());
logInfo("Start Deleting user=" + identity);
File archiveFilePath = getArchivFilePath(identity);
Map<String, UserDataDeletable> userDataDeletableResourcesMap = CoreSpringFactory.getBeansOfType(UserDataDeletable.class);
List<UserDataDeletable> userDataDeletableResources = new ArrayList<>(userDataDeletableResourcesMap.values());
Collections.sort(userDataDeletableResources, new UserDataDeletableComparator());
for (UserDataDeletable element : userDataDeletableResources) {
logInfo("UserDataDeletable-Loop element=" + element);
element.deleteUserData(identity, newName, archiveFilePath);
}
// Delete all authentications for certain identity
List<Authentication> authentications = securityManager.getAuthentications(identity);
for (Authentication auth : authentications) {
logInfo("deleteAuthentication auth=" + auth);
securityManager.deleteAuthentication(auth);
logDebug("Delete auth=" + auth + " of identity=" + identity);
}
// remove identity from its security groups
List<SecurityGroup> securityGroups = securityManager.getSecurityGroupsForIdentity(identity);
for (SecurityGroup secGroup : securityGroups) {
securityManager.removeIdentityFromSecurityGroup(identity, secGroup);
logInfo("Removing user=" + identity + " from security group=" + secGroup.toString());
}
// remove identity from groups
groupDao.removeMemberships(identity);
String key = identity.getUser().getProperty("emchangeKey", null);
TemporaryKey tempKey = registrationManager.loadTemporaryKeyByRegistrationKey(key);
if (tempKey != null) {
registrationManager.deleteTemporaryKey(tempKey);
}
identity = securityManager.loadIdentityByKey(identity.getKey());
// keep login-name only -> change email
User persistedUser = identity.getUser();
List<UserPropertyHandler> userPropertyHandlers = UserManager.getInstance().getAllUserPropertyHandlers();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
String actualProperty = userPropertyHandler.getName();
if (userPropertyHandler.isDeletable() && !(keepUserEmailAfterDeletion && UserConstants.EMAIL.equals(actualProperty))) {
persistedUser.setProperty(actualProperty, null);
}
if ((!keepUserEmailAfterDeletion && UserConstants.EMAIL.equals(actualProperty))) {
String oldEmail = userPropertyHandler.getUserProperty(persistedUser, null);
String newEmail = "";
if (StringHelper.containsNonWhitespace(oldEmail)) {
newEmail = getBackupStringWithDate(oldEmail);
}
logInfo("Update user-property user=" + persistedUser);
userPropertyHandler.setUserProperty(persistedUser, newEmail);
}
}
UserManager.getInstance().updateUserFromIdentity(identity);
logInfo("deleteUserProperties user=" + persistedUser);
dbInstance.commit();
identity = securityManager.loadIdentityByKey(identity.getKey());
// keep email only -> change login-name
if (!keepUserEmailAfterDeletion) {
identity = securityManager.saveIdentityName(identity, newName, null);
}
// keep everything, change identity.status to deleted
logInfo("Change stater identity=" + identity);
identity = securityManager.saveIdentityStatus(identity, Identity.STATUS_DELETED);
LifeCycleManager.createInstanceFor(identity).deleteTimestampFor(SEND_DELETE_EMAIL_ACTION);
LifeCycleManager.createInstanceFor(identity).markTimestampFor(USER_DELETED_ACTION, createLifeCycleLogDataFor(identity));
logAudit("User-Deletion: Delete all userdata for identity=" + identity);
}
Aggregations