Search in sources :

Example 36 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.

the class InvitationEditRightsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_pf_invitation_form");
    FormLayoutContainer inviteeCont = FormLayoutContainer.createDefaultFormLayout("inviteeInfos", getTranslator());
    inviteeCont.setRootForm(mainForm);
    formLayout.add("inviteeInfos", inviteeCont);
    firstNameEl = uifactory.addTextElement("firstName", "firstName", 64, invitation.getFirstName(), inviteeCont);
    firstNameEl.setElementCssClass("o_sel_pf_invitation_firstname");
    firstNameEl.setMandatory(true);
    lastNameEl = uifactory.addTextElement("lastName", "lastName", 64, invitation.getLastName(), inviteeCont);
    lastNameEl.setElementCssClass("o_sel_pf_invitation_lastname");
    lastNameEl.setMandatory(true);
    String invitationEmail = email != null ? email : invitation.getMail();
    mailEl = uifactory.addTextElement("mail", "mail", 128, invitationEmail, inviteeCont);
    mailEl.setElementCssClass("o_sel_pf_invitation_mail");
    mailEl.setMandatory(true);
    mailEl.setNotEmptyCheck("map.share.empty.warn");
    mailEl.setEnabled(invitation.getKey() == null);
    if (StringHelper.containsNonWhitespace(invitation.getMail()) && MailHelper.isValidEmailAddress(invitation.getMail())) {
        SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
        List<Identity> shareWithIdentities = userManager.findIdentitiesByEmail(Collections.singletonList(invitation.getMail()));
        if (isAtLeastOneInSecurityGroup(shareWithIdentities, allUsers)) {
            mailEl.setErrorKey("map.share.with.mail.error.olatUser", new String[] { invitation.getMail() });
        }
    }
    String link = getInvitationLink();
    StaticTextElement linkEl = uifactory.addStaticTextElement("invitation.link", link, inviteeCont);
    linkEl.setElementCssClass("o_sel_pf_invitation_url");
    linkEl.setLabel("invitation.link", null);
    if (mailTemplate != null) {
        subjectEl = uifactory.addTextElement("subjectElem", "mail.subject", 128, mailTemplate.getSubjectTemplate(), inviteeCont);
        subjectEl.setDisplaySize(60);
        subjectEl.setMandatory(true);
        bodyEl = uifactory.addTextAreaElement("bodyElem", "mail.body", -1, 15, 60, true, mailTemplate.getBodyTemplate(), inviteeCont);
        bodyEl.setHelpUrlForManualPage("E-Mail");
        bodyEl.setMandatory(true);
    }
    // binder
    MultipleSelectionElement accessEl = uifactory.addCheckboxesHorizontal("access-" + (counter++), null, formLayout, theKeys, theValues);
    accessEl.addActionListener(FormEvent.ONCHANGE);
    binderRow = new BinderAccessRightsRow(accessEl, binder);
    // sections
    List<Section> sections = portfolioService.getSections(binder);
    Map<Long, SectionAccessRightsRow> sectionMap = new HashMap<>();
    for (Section section : sections) {
        MultipleSelectionElement sectionAccessEl = uifactory.addCheckboxesHorizontal("access-" + (counter++), null, formLayout, theKeys, theValues);
        sectionAccessEl.addActionListener(FormEvent.ONCHANGE);
        SectionAccessRightsRow sectionRow = new SectionAccessRightsRow(sectionAccessEl, section, binderRow);
        binderRow.getSections().add(sectionRow);
        sectionMap.put(section.getKey(), sectionRow);
    }
    // pages
    List<Page> pages = portfolioService.getPages(binder, null);
    for (Page page : pages) {
        Section section = page.getSection();
        SectionAccessRightsRow sectionRow = sectionMap.get(section.getKey());
        MultipleSelectionElement pageAccessEl = uifactory.addCheckboxesHorizontal("access-" + (counter++), null, formLayout, theKeys, theValues);
        pageAccessEl.addActionListener(FormEvent.ONCHANGE);
        PortfolioElementAccessRightsRow pageRow = new PortfolioElementAccessRightsRow(pageAccessEl, page, sectionRow);
        sectionRow.getPages().add(pageRow);
    }
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("binderRow", binderRow);
    }
    selectAll = uifactory.addFormLink("form.checkall", "form.checkall", null, formLayout, Link.LINK);
    selectAll.setIconLeftCSS("o_icon o_icon-sm o_icon_check_on");
    deselectAll = uifactory.addFormLink("form.uncheckall", "form.uncheckall", null, formLayout, Link.LINK);
    deselectAll.setIconLeftCSS("o_icon o_icon-sm o_icon_check_off");
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonsCont);
    buttonsCont.setRootForm(mainForm);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
    if (invitation.getKey() != null) {
        removeLink = uifactory.addFormLink("remove", buttonsCont, Link.BUTTON);
    }
    uifactory.addFormSubmitButton("save", buttonsCont);
}
Also used : HashMap(java.util.HashMap) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Page(org.olat.modules.portfolio.Page) SecurityGroup(org.olat.basesecurity.SecurityGroup) Section(org.olat.modules.portfolio.Section) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) Identity(org.olat.core.id.Identity)

Example 37 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.

the class RepositoryManagerTest method isInstitutionalRessourceManagerFor.

/**
 * How can be a resource manager if Constants.ORESOURCE_USERMANAGER is never used?
 */
@Test
public void isInstitutionalRessourceManagerFor() {
    Identity owner1 = JunitTestHelper.createAndPersistIdentityAsUser("instit-" + UUID.randomUUID().toString());
    Identity owner2 = JunitTestHelper.createAndPersistIdentityAsUser("instit-" + UUID.randomUUID().toString());
    Identity part3 = JunitTestHelper.createAndPersistIdentityAsUser("instit-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryEntryRelationDao.addRole(owner1, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(owner2, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(part3, re, GroupRoles.participant.name());
    dbInstance.commit();
    // set the institutions
    owner1.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "volks");
    owner2.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "volks");
    part3.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "volks");
    userManager.updateUserFromIdentity(owner1);
    userManager.updateUserFromIdentity(owner2);
    userManager.updateUserFromIdentity(part3);
    dbInstance.commit();
    // promote owner1 to institution resource manager
    SecurityGroup institutionalResourceManagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER);
    securityManager.addIdentityToSecurityGroup(owner1, institutionalResourceManagerGroup);
    dbInstance.commitAndCloseSession();
    // check
    Roles rolesOwner1 = securityManager.getRoles(owner1);
    Roles rolesOwner2 = securityManager.getRoles(owner2);
    Roles rolesPart3 = securityManager.getRoles(part3);
    boolean institutionMgr1 = repositoryManager.isInstitutionalRessourceManagerFor(owner1, rolesOwner1, re);
    boolean institutionMgr2 = repositoryManager.isInstitutionalRessourceManagerFor(owner2, rolesOwner2, re);
    boolean institutionMgr3 = repositoryManager.isInstitutionalRessourceManagerFor(part3, rolesPart3, re);
    Assert.assertTrue(institutionMgr1);
    Assert.assertFalse(institutionMgr2);
    Assert.assertFalse(institutionMgr3);
}
Also used : GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) Test(org.junit.Test)

Example 38 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.

the class RepositoryManagerTest method queryByTypeLimitAccess_withInstitution.

@Test
public void queryByTypeLimitAccess_withInstitution() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("qbtla-3-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true);
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "qbtla-3", "tg", null, null, false, false, re);
    businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    // promote id to institution resource manager
    id.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "openolat.org");
    userManager.updateUserFromIdentity(id);
    SecurityGroup institutionalResourceManagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER);
    securityManager.addIdentityToSecurityGroup(id, institutionalResourceManagerGroup);
    dbInstance.commitAndCloseSession();
    // check
    List<String> types = Collections.singletonList(re.getOlatResource().getResourceableTypeName());
    List<RepositoryEntry> entries = repositoryManager.queryByTypeLimitAccess(id, new Roles(false, false, false, false, false, true, false), types);
    Assert.assertNotNull(entries);
    Assert.assertFalse(entries.isEmpty());
    Assert.assertTrue(entries.contains(re));
    for (RepositoryEntry entry : entries) {
        if (!entry.equals(re)) {
            Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS);
        }
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) Test(org.junit.Test)

Example 39 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.

the class EPStructureManagerTest method testGetStructureElementsForUser.

@Test
public void testGetStructureElementsForUser() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("EP-1-");
    PortfolioStructure el = epFrontendManager.createAndPersistPortfolioDefaultMap(user, "users-test-map", "a-map-to-test-get-afterwards");
    Assert.assertNotNull(el);
    dbInstance.commitAndCloseSession();
    List<SecurityGroup> secGroups = securityManager.getSecurityGroupsForIdentity(user);
    Assert.assertNotNull(secGroups);
    Assert.assertTrue(secGroups.size() >= 1);
    List<PortfolioStructure> elRes = epStructureManager.getStructureElementsForUser(user, ElementType.DEFAULT_MAP);
    Assert.assertNotNull(elRes);
    Assert.assertEquals(1, elRes.size());
    Assert.assertEquals("users-test-map", elRes.get(0).getTitle());
    // get another map
    PortfolioStructure el2 = epFrontendManager.createAndPersistPortfolioDefaultMap(user, "users-test-map-2", "2-a-map-to-test-get-afterwards");
    Assert.assertNotNull(el2);
    dbInstance.commitAndCloseSession();
    List<PortfolioStructure> elRes2 = epStructureManager.getStructureElementsForUser(user);
    Assert.assertNotNull(elRes2);
    Assert.assertEquals(2, elRes2.size());
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) Test(org.junit.Test)

Example 40 with SecurityGroup

use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.

the class JunitTestHelper method createAndPersistIdentityAsUser.

/**
 * Create an identity with user permissions
 * @param login
 * @return
 */
public static final Identity createAndPersistIdentityAsUser(String login) {
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity identity = securityManager.findIdentityByName(login);
    if (identity != null)
        return identity;
    SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
    if (group == null)
        group = securityManager.createAndPersistNamedSecurityGroup(Constants.GROUP_OLATUSERS);
    User user = UserManager.getInstance().createUser("first" + login, "last" + login, login + "@" + maildomain);
    identity = securityManager.createAndPersistIdentityAndUser(login, null, user, BaseSecurityModule.getDefaultAuthProviderIdentifier(), login, PWD);
    securityManager.addIdentityToSecurityGroup(identity, group);
    return identity;
}
Also used : User(org.olat.core.id.User) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity)

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