use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class SetupModule method createUser.
/**
* Method to create a user with the given configuration
*
* @return Identity or null
*/
protected Identity createUser(DefaultUser user) {
Identity identity;
identity = securityManager.findIdentityByName(user.getUserName());
if (identity == null) {
// Create new user and subject
UserImpl newUser = new UserImpl();
newUser.setFirstName(user.getFirstName());
newUser.setLastName(user.getLastName());
newUser.setEmail(user.getEmail());
newUser.getPreferences().setLanguage(user.getLanguage());
newUser.getPreferences().setInformSessionTimeout(true);
if (!StringUtils.hasText(authenticationProviderConstant)) {
throw new OLATRuntimeException(this.getClass(), "Auth token not set! Please fix! " + authenticationProviderConstant, null);
}
// Now finally create that user thing on the database with all
// credentials, person etc. in one transation context!
identity = securityManager.createAndPersistIdentityAndUser(user.getUserName(), null, newUser, authenticationProviderConstant, user.getUserName(), user.getPassword());
if (identity == null) {
throw new OLATRuntimeException(this.getClass(), "Error, could not create user and subject with name " + user.getUserName(), null);
} else {
if (user.isGuest()) {
SecurityGroup anonymousGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ANONYMOUS);
securityManager.addIdentityToSecurityGroup(identity, anonymousGroup);
log.info("Created anonymous user " + user.getUserName());
} else {
SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
if (user.isAdmin()) {
SecurityGroup adminGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
securityManager.addIdentityToSecurityGroup(identity, adminGroup);
securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
log.info("Created admin user " + user.getUserName());
} else if (user.isAuthor()) {
SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
securityManager.addIdentityToSecurityGroup(identity, authorGroup);
securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
log.info("Created author user " + user.getUserName());
} else if (user.isUserManager()) {
SecurityGroup usermanagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_USERMANAGERS);
securityManager.addIdentityToSecurityGroup(identity, usermanagerGroup);
securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
log.info("Created userManager user " + user.getUserName());
} else if (user.isGroupManager()) {
SecurityGroup groupmanagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_GROUPMANAGERS);
securityManager.addIdentityToSecurityGroup(identity, groupmanagerGroup);
securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
log.info("Created groupManager user " + user.getUserName());
} else {
securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
log.info("Created user " + user.getUserName());
}
}
}
}
return identity;
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class UsermanagerUserSearchForm method findIdentitiesFromSearchForm.
/**
* @return List of identities that match the criterias from the search form
*/
private List<Identity> findIdentitiesFromSearchForm() {
// get user attributes from form
String login = searchform.getStringValue("login");
// when searching for deleted users, add wildcard to match with backup prefix
if (searchform.getStatus().equals(Identity.STATUS_DELETED)) {
login = "*" + login;
}
Integer status = null;
// get user fields from form
// build user fields search map
Map<String, String> userPropertiesSearch = new HashMap<String, String>();
for (UserPropertyHandler userPropertyHandler : searchform.getPropertyHandlers()) {
if (userPropertyHandler == null)
continue;
FormItem ui = searchform.getItem(userPropertyHandler.getName());
String uiValue = userPropertyHandler.getStringValue(ui);
if (userPropertyHandler.getName().startsWith("genericCheckboxProperty") && ui instanceof MultipleSelectionElement) {
if (!"false".equals(uiValue)) {
// ignore false for the search
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
} else if (StringHelper.containsNonWhitespace(uiValue)) {
// when searching for deleted users, add wildcard to match with backup prefix
if (userPropertyHandler instanceof EmailProperty && searchform.getStatus().equals(Identity.STATUS_DELETED)) {
uiValue = "*" + uiValue;
}
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
}
if (userPropertiesSearch.isEmpty())
userPropertiesSearch = null;
// get group memberships from form
List<SecurityGroup> groupsList = new ArrayList<SecurityGroup>();
if (searchform.getRole("admin")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
groupsList.add(group);
}
if (searchform.getRole("author")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
groupsList.add(group);
}
if (searchform.getRole("groupmanager")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_GROUPMANAGERS);
groupsList.add(group);
}
if (searchform.getRole("usermanager")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_USERMANAGERS);
groupsList.add(group);
}
if (searchform.getRole("oresmanager")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER);
groupsList.add(group);
}
if (searchform.getRole("poolmanager")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_POOL_MANAGER);
groupsList.add(group);
}
status = searchform.getStatus();
SecurityGroup[] groups = groupsList.toArray(new SecurityGroup[groupsList.size()]);
// no permissions in this form so far
PermissionOnResourceable[] permissionOnResources = null;
String[] authProviders = searchform.getAuthProviders();
// get date constraints from form
Date createdBefore = searchform.getBeforeDate();
Date createdAfter = searchform.getAfterDate();
Date userLoginBefore = searchform.getUserLoginBefore();
Date userLoginAfter = searchform.getUserLoginAfter();
// now perform power search
List<Identity> myIdentities = securityManager.getIdentitiesByPowerSearch((login.equals("") ? null : login), userPropertiesSearch, true, groups, permissionOnResources, authProviders, createdAfter, createdBefore, userLoginAfter, userLoginBefore, status);
return myIdentities;
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class QuestionPoolServiceImpl method deleteItems.
@Override
public void deleteItems(List<? extends QuestionItemShort> items) {
if (items == null || items.isEmpty()) {
// nothing to do
return;
}
List<SecurityGroup> secGroups = new ArrayList<>();
for (QuestionItemShort item : items) {
markManager.deleteMarks(item);
commentAndRatingService.deleteAllIgnoringSubPath(item);
licenseService.delete(item);
QuestionItem loadedItem = loadItemById(item.getKey());
if (loadedItem instanceof QuestionItemImpl) {
QuestionItemImpl itemImpl = (QuestionItemImpl) loadedItem;
qpoolFileStorage.deleteDir(itemImpl.getDirectory());
secGroups.add(itemImpl.getOwnerGroup());
}
dbInstance.intermediateCommit();
}
poolDao.removeFromPools(items);
questionItemDao.removeFromShares(items);
collectionDao.deleteItemFromCollections(items);
questionItemDao.delete(items);
// Delete SecurityGroup after the item to avoid foreign key constraint violation.
for (SecurityGroup secGroup : secGroups) {
securityManager.deleteSecurityGroup(secGroup);
}
for (QuestionItemShort item : items) {
lifeIndexer.deleteDocument(QItemDocument.TYPE, item.getKey());
}
// allow reload of data
dbInstance.getCurrentEntityManager().flush();
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class QuestionPoolServiceImpl method removeOwners.
@Override
public void removeOwners(List<Identity> owners, List<Pool> pools) {
if (owners == null || owners.isEmpty() || pools == null || pools.isEmpty()) {
// nothing to do
return;
}
List<SecurityGroup> secGroups = new ArrayList<SecurityGroup>(pools.size());
for (Pool pool : pools) {
SecurityGroup secGroup = ((PoolImpl) pool).getOwnerGroup();
secGroups.add(secGroup);
}
securityManager.removeIdentityFromSecurityGroups(owners, secGroups);
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class MembersOverviewIdentitiesController method loadModel.
private void loadModel(List<String> keys) {
oks = new ArrayList<Identity>();
List<String> isanonymous = new ArrayList<>();
notfounds = new ArrayList<>();
SecurityGroup anonymousSecGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ANONYMOUS);
for (String identityKey : keys) {
Identity ident = securityManager.loadIdentityByKey(Long.parseLong(identityKey));
if (ident == null) {
// not found, add to not-found-list
notfounds.add(identityKey);
} else if (securityManager.isIdentityInSecurityGroup(ident, anonymousSecGroup)) {
isanonymous.add(identityKey);
} else if (!PersistenceHelper.containsPersistable(oks, ident)) {
oks.add(ident);
}
}
}
Aggregations