Search in sources :

Example 96 with SecurityGroup

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;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) UserImpl(org.olat.user.UserImpl) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup)

Example 97 with SecurityGroup

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;
}
Also used : HashMap(java.util.HashMap) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) SecurityGroup(org.olat.basesecurity.SecurityGroup) Date(java.util.Date) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) EmailProperty(org.olat.user.propertyhandlers.EmailProperty) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) PermissionOnResourceable(org.olat.basesecurity.PermissionOnResourceable)

Example 98 with SecurityGroup

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();
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) SecurityGroup(org.olat.basesecurity.SecurityGroup) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 99 with SecurityGroup

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);
}
Also used : ArrayList(java.util.ArrayList) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) SecurityGroup(org.olat.basesecurity.SecurityGroup) PoolImpl(org.olat.modules.qpool.model.PoolImpl)

Example 100 with SecurityGroup

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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup)

Aggregations

SecurityGroup (org.olat.basesecurity.SecurityGroup)142 Identity (org.olat.core.id.Identity)104 ArrayList (java.util.ArrayList)36 Test (org.junit.Test)24 BaseSecurity (org.olat.basesecurity.BaseSecurity)20 User (org.olat.core.id.User)20 CatalogEntry (org.olat.repository.CatalogEntry)18 RepositoryEntry (org.olat.repository.RepositoryEntry)16 Path (javax.ws.rs.Path)14 Date (java.util.Date)12 UserVO (org.olat.user.restapi.UserVO)10 URI (java.net.URI)8 Calendar (java.util.Calendar)8 HashMap (java.util.HashMap)8 HttpResponse (org.apache.http.HttpResponse)8 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)8 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)8 LDAPUser (org.olat.ldap.model.LDAPUser)7 HashSet (java.util.HashSet)6 NamingException (javax.naming.NamingException)6