Search in sources :

Example 81 with SecurityGroup

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

the class CatalogNodeManagerController method doEditOwners.

private void doEditOwners(UserRequest ureq) {
    removeAsListenerAndDispose(groupCtrl);
    removeAsListenerAndDispose(cmc);
    // add ownership management
    SecurityGroup secGroup = catalogEntry.getOwnerGroup();
    if (secGroup == null) {
        catalogEntry = catalogManager.loadCatalogEntry(catalogEntry);
        secGroup = securityManager.createAndPersistSecurityGroup();
        catalogEntry.setOwnerGroup(secGroup);
        catalogEntry = catalogManager.saveCatalogEntry(catalogEntry);
    }
    groupCtrl = new GroupController(ureq, getWindowControl(), true, false, false, false, false, false, secGroup);
    listenTo(groupCtrl);
    // open form in dialog
    removeAsListenerAndDispose(cmc);
    cmc = new CloseableModalController(getWindowControl(), "close", groupCtrl.getInitialComponent(), true, translate("tools.edit.catalog.category.ownergroup"));
    listenTo(cmc);
    cmc.activate();
}
Also used : GroupController(org.olat.admin.securitygroup.gui.GroupController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) SecurityGroup(org.olat.basesecurity.SecurityGroup)

Example 82 with SecurityGroup

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

the class CatalogNodeManagerController method doContact.

private void doContact(UserRequest ureq) {
    removeAsListenerAndDispose(cmc);
    removeAsListenerAndDispose(contactCtrl);
    ContactList caretaker = new ContactList(translate("contact.to.groupname.caretaker"));
    List<Identity> owners = new ArrayList<Identity>();
    CatalogEntry parent = catalogEntry;
    while (parent != null && owners.isEmpty()) {
        SecurityGroup parentOwner = parent.getOwnerGroup();
        if (parentOwner != null) {
            owners = securityManager.getIdentitiesOfSecurityGroup(parentOwner);
        }
        parent = parent.getParent();
    }
    for (int i = owners.size(); i-- > 0; ) {
        caretaker.add(owners.get(i));
    }
    // create e-mail Message
    ContactMessage cmsg = new ContactMessage(ureq.getIdentity());
    cmsg.addEmailTo(caretaker);
    contactCtrl = new ContactFormController(ureq, getWindowControl(), true, false, false, cmsg);
    listenTo(contactCtrl);
    // open form in dialog
    cmc = new CloseableModalController(getWindowControl(), "close", contactCtrl.getInitialComponent(), true, translate("contact.caretaker"));
    listenTo(cmc);
    cmc.activate();
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ContactFormController(org.olat.modules.co.ContactFormController) ArrayList(java.util.ArrayList) CatalogEntry(org.olat.repository.CatalogEntry) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) ContactMessage(org.olat.core.util.mail.ContactMessage)

Example 83 with SecurityGroup

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

the class OLATUpgrade_7_1_1 method createRepoEntrySecurityGroups.

private void createRepoEntrySecurityGroups(RepositoryEntryUpgrade entry) {
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    boolean save = false;
    if (entry.getTutorGroup() == null) {
        // security group for tutors / coaches
        SecurityGroup tutorGroup = securityManager.createAndPersistSecurityGroup();
        // member of this group may modify member's membership
        securityManager.createAndPersistPolicy(tutorGroup, Constants.PERMISSION_ACCESS, entry.getOlatResource());
        // members of this group are always tutors also
        securityManager.createAndPersistPolicy(tutorGroup, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_TUTOR);
        entry.setTutorGroup(tutorGroup);
        securityManager.createAndPersistPolicy(entry.getTutorGroup(), Constants.PERMISSION_COACH, entry.getOlatResource());
        DBFactory.getInstance().commit();
        save = true;
    }
    if (entry.getParticipantGroup() == null) {
        // security group for participants
        SecurityGroup participantGroup = securityManager.createAndPersistSecurityGroup();
        // member of this group may modify member's membership
        securityManager.createAndPersistPolicy(participantGroup, Constants.PERMISSION_ACCESS, entry.getOlatResource());
        // members of this group are always participants also
        securityManager.createAndPersistPolicy(participantGroup, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_PARTICIPANT);
        entry.setParticipantGroup(participantGroup);
        securityManager.createAndPersistPolicy(entry.getParticipantGroup(), Constants.PERMISSION_PARTI, entry.getOlatResource());
        DBFactory.getInstance().commit();
        save = true;
    }
    if (save) {
        DBFactory.getInstance().updateObject(entry);
    }
}
Also used : SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 84 with SecurityGroup

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

the class OLATUpgrade_7_1_1 method migrateRepoEntrySecurityGroups.

private void migrateRepoEntrySecurityGroups(RepositoryEntryUpgrade entry) {
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    List<BGContextImpl> contexts = findBGContextsForResource(entry.getOlatResource(), true, true);
    for (BGContextImpl context : contexts) {
        List<BusinessGroupUpgrade> groups = getGroupsOfBGContext(context);
        for (BusinessGroupUpgrade group : groups) {
            // migrate tutors
            if (group.getOwnerGroup() != null) {
                int count = 0;
                List<Identity> owners = securityManager.getIdentitiesOfSecurityGroup(group.getOwnerGroup());
                SecurityGroup tutorGroup = entry.getTutorGroup();
                for (Identity owner : owners) {
                    if (securityManager.isIdentityInSecurityGroup(owner, tutorGroup)) {
                        continue;
                    }
                    securityManager.addIdentityToSecurityGroup(owner, tutorGroup);
                    if (count++ % 20 == 0) {
                        DBFactory.getInstance().intermediateCommit();
                    }
                }
                DBFactory.getInstance().intermediateCommit();
            }
            // migrate participants
            if (group.getPartipiciantGroup() != null) {
                int count = 0;
                List<Identity> participants = securityManager.getIdentitiesOfSecurityGroup(group.getPartipiciantGroup());
                SecurityGroup participantGroup = entry.getParticipantGroup();
                for (Identity participant : participants) {
                    if (securityManager.isIdentityInSecurityGroup(participant, participantGroup)) {
                        continue;
                    }
                    securityManager.addIdentityToSecurityGroup(participant, participantGroup);
                    if (count++ % 20 == 0) {
                        DBFactory.getInstance().intermediateCommit();
                    }
                }
                DBFactory.getInstance().intermediateCommit();
            }
        }
    }
}
Also used : BGContextImpl(org.olat.upgrade.model.BGContextImpl) BusinessGroupUpgrade(org.olat.upgrade.model.BusinessGroupUpgrade) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 85 with SecurityGroup

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

the class OLATUpgrade_10_0_0 method processMapPolicy.

private EPMapUpgradeToGroupRelation processMapPolicy(Policy policy, EPMapUpgrade element) {
    String permission = policy.getPermission();
    SecurityGroup secGroup = policy.getSecurityGroup();
    Group group;
    String role;
    if (permission.startsWith(EPMapPolicy.Type.user.name())) {
        group = groupDao.createGroup();
        processSecurityGroup(group, GroupRoles.participant.name(), secGroup);
        role = EPMapPolicy.Type.user.name();
    } else if (permission.startsWith(EPMapPolicy.Type.group.name())) {
        group = findGroupOfBusinessGroup(secGroup);
        role = EPMapPolicy.Type.group.name();
    } else if (permission.startsWith(EPMapPolicy.Type.invitation.name())) {
        InvitationUpgrade invitation = findInvitation(policy.getSecurityGroup());
        if (invitation == null) {
            return null;
        }
        group = invitation.getBaseGroup();
        role = EPMapPolicy.Type.invitation.name();
    } else if (permission.startsWith(EPMapPolicy.Type.allusers.name())) {
        group = groupDao.createGroup(EPMapPolicy.Type.allusers.name());
        role = EPMapPolicy.Type.allusers.name();
    } else {
        return null;
    }
    if (group == null) {
        log.error("Group not resolve for policy of map: " + element.getKey() + " and policy: " + policy.getKey());
        return null;
    }
    EPMapUpgradeToGroupRelation relation = new EPMapUpgradeToGroupRelation();
    relation.setDefaultGroup(false);
    relation.setCreationDate(new Date());
    relation.setEntry(element);
    relation.setValidTo(policy.getTo());
    relation.setValidFrom(policy.getFrom());
    relation.setGroup(group);
    relation.setRole(role);
    return relation;
}
Also used : Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) EPMapUpgradeToGroupRelation(org.olat.upgrade.model.EPMapUpgradeToGroupRelation) InvitationUpgrade(org.olat.upgrade.model.InvitationUpgrade) SecurityGroup(org.olat.basesecurity.SecurityGroup) Date(java.util.Date)

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