Search in sources :

Example 11 with SecurityGroup

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

the class CourseTest method getAuthors.

@Test
public void getAuthors() throws IOException, URISyntaxException {
    // make auth1 and auth2 authors
    SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    if (!securityManager.isIdentityInSecurityGroup(auth1, authorGroup)) {
        securityManager.addIdentityToSecurityGroup(auth1, authorGroup);
    }
    if (!securityManager.isIdentityInSecurityGroup(auth2, authorGroup)) {
        securityManager.addIdentityToSecurityGroup(auth2, authorGroup);
    }
    dbInstance.intermediateCommit();
    // make auth1 and auth2 owner
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
    List<Identity> authors = new ArrayList<Identity>();
    authors.add(auth1);
    authors.add(auth2);
    IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
    repositoryManager.addOwners(admin, identitiesAddedEvent, repositoryEntry, null);
    dbInstance.intermediateCommit();
    // get them
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    assertNotNull(body);
    List<UserVO> authorVOs = parseUserArray(body);
    assertNotNull(authorVOs);
}
Also used : UserVO(org.olat.user.restapi.UserVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 12 with SecurityGroup

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

the class CourseTest method addAuthor.

@Test
public void addAuthor() throws IOException, URISyntaxException {
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors/" + auth0.getKey()).build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // is auth0 author
    SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    boolean isAuthor = securityManager.isIdentityInSecurityGroup(auth0, authorGroup);
    dbInstance.intermediateCommit();
    Assert.assertTrue(isAuthor);
    // is auth0 owner
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
    boolean isOwner = repositoryService.hasRole(auth0, repositoryEntry, GroupRoles.owner.name());
    dbInstance.intermediateCommit();
    Assert.assertTrue(isOwner);
}
Also used : HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) SecurityGroup(org.olat.basesecurity.SecurityGroup) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 13 with SecurityGroup

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

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 14 with SecurityGroup

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

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 15 with SecurityGroup

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

the class CourseWebService method getAuthor.

/**
 * Get this specific author and owner of the course
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The author
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found or the user is not an onwer or author of the course
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns an <code>UserVO</code>
 */
@GET
@Path("authors/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthor(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    Identity author = securityManager.loadIdentityByKey(identityKey, false);
    if (repositoryService.hasRole(author, repositoryEntry, GroupRoles.owner.name()) && securityManager.isIdentityInSecurityGroup(author, authorGroup)) {
        UserVO vo = UserVOFactory.get(author);
        return Response.ok(vo).build();
    }
    return Response.ok(author).build();
}
Also used : UserVO(org.olat.user.restapi.UserVO) RepositoryEntry(org.olat.repository.RepositoryEntry) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RepositoryService(org.olat.repository.RepositoryService) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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