Search in sources :

Example 21 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.

the class ImportMemberOverviewIdentitiesController method loadModelByIdentities.

private void loadModelByIdentities(List<Identity> keys) {
    notfounds = new ArrayList<>();
    Set<Identity> okSet = new HashSet<>();
    SecurityGroup anonymousSecGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ANONYMOUS);
    List<Identity> anonymousUsers = securityManager.getIdentitiesOfSecurityGroup(anonymousSecGroup);
    for (Identity ident : keys) {
        if (ident == null || anonymousUsers.contains(ident)) {
        // ignore
        } else if (!okSet.contains(ident)) {
            okSet.add(ident);
        }
    }
    oks = new ArrayList<>(okSet);
}
Also used : Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) HashSet(java.util.HashSet)

Example 22 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.

the class PoolDAO method createPool.

public PoolImpl createPool(Identity owner, String name, boolean publicPool) {
    PoolImpl pool = new PoolImpl();
    pool.setCreationDate(new Date());
    pool.setLastModified(new Date());
    pool.setName(name);
    pool.setPublicPool(publicPool);
    SecurityGroup ownerGroup = securityManager.createAndPersistSecurityGroup();
    pool.setOwnerGroup(ownerGroup);
    dbInstance.getCurrentEntityManager().persist(pool);
    if (owner != null) {
        securityManager.addIdentityToSecurityGroup(owner, ownerGroup);
    }
    return pool;
}
Also used : PoolImpl(org.olat.modules.qpool.model.PoolImpl) SecurityGroup(org.olat.basesecurity.SecurityGroup) Date(java.util.Date)

Example 23 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.

the class MembersOverviewIdentitiesController method loadModel.

private void loadModel(String inp) {
    oks = new ArrayList<Identity>();
    notfounds = new ArrayList<String>();
    SecurityGroup anonymousSecGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ANONYMOUS);
    List<String> identList = new ArrayList<String>();
    String[] lines = inp.split("\r?\n");
    for (int i = 0; i < lines.length; i++) {
        String username = lines[i].trim();
        if (username.length() > 0) {
            identList.add(username);
        }
    }
    // search by institutionalUserIdentifier, case sensitive
    List<Identity> institutIdentities = securityManager.findIdentitiesByNumber(identList);
    for (Identity identity : institutIdentities) {
        String userIdent = identity.getUser().getProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, null);
        if (userIdent != null) {
            identList.remove(userIdent);
        }
        if (!PersistenceHelper.containsPersistable(oks, identity) && !securityManager.isIdentityInSecurityGroup(identity, anonymousSecGroup)) {
            oks.add(identity);
        }
    }
    // make a lowercase copy of identList for processing username and email
    List<String> identListLowercase = new ArrayList<String>(identList.size());
    for (String ident : identList) {
        identListLowercase.add(ident.toLowerCase());
    }
    // search by names, must be lower case
    List<Identity> identities = securityManager.findIdentitiesByNameCaseInsensitive(identListLowercase);
    for (Identity identity : identities) {
        identListLowercase.remove(identity.getName().toLowerCase());
        if (!PersistenceHelper.containsPersistable(oks, identity) && !securityManager.isIdentityInSecurityGroup(identity, anonymousSecGroup)) {
            oks.add(identity);
        }
    }
    // search by email, case insensitive
    List<Identity> mailIdentities = userManager.findIdentitiesByEmail(identListLowercase);
    for (Identity identity : mailIdentities) {
        String email = identity.getUser().getProperty(UserConstants.EMAIL, null);
        if (email != null) {
            identListLowercase.remove(email.toLowerCase());
        }
        String institutEmail = identity.getUser().getProperty(UserConstants.INSTITUTIONALEMAIL, null);
        if (institutEmail != null) {
            identListLowercase.remove(institutEmail.toLowerCase());
        }
        if (!PersistenceHelper.containsPersistable(oks, identity) && !securityManager.isIdentityInSecurityGroup(identity, anonymousSecGroup)) {
            oks.add(identity);
        }
    }
    notfounds.addAll(identListLowercase);
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup)

Example 24 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.

the class QuestionItemDAO method removeAuthors.

public void removeAuthors(List<Identity> authors, QuestionItemShort item) {
    QuestionItemImpl lockedItem = loadForUpdate(item);
    SecurityGroup secGroup = lockedItem.getOwnerGroup();
    for (Identity author : authors) {
        if (securityManager.isIdentityInSecurityGroup(author, secGroup)) {
            securityManager.removeIdentityFromSecurityGroup(author, secGroup);
        }
    }
    dbInstance.commit();
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity)

Example 25 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.

the class QuestionItemDAO method addAuthors.

public void addAuthors(List<Identity> authors, QuestionItemShort item) {
    QuestionItemImpl lockedItem = loadForUpdate(item);
    SecurityGroup secGroup = lockedItem.getOwnerGroup();
    for (Identity author : authors) {
        if (!securityManager.isIdentityInSecurityGroup(author, secGroup)) {
            securityManager.addIdentityToSecurityGroup(author, secGroup);
        }
    }
    dbInstance.commit();
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity)

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