Search in sources :

Example 46 with SecurityGroup

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

the class CourseTest method addAuthors.

@Test
public void addAuthors() throws IOException, URISyntaxException {
    Assert.assertTrue(conn.login("administrator", "openolat"));
    ICourse course = CoursesWebService.createEmptyCourse(admin, "course1", "course1 long name", null);
    Identity author1 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-auth-1");
    Identity author2 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-auth-2");
    dbInstance.commitAndCloseSession();
    UserVO[] newAuthors = new UserVO[2];
    newAuthors[0] = UserVOFactory.get(author1);
    newAuthors[1] = UserVOFactory.get(author2);
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course.getResourceableId().toString()).path("authors").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, newAuthors);
    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 isAuthor1 = securityManager.isIdentityInSecurityGroup(author1, authorGroup);
    boolean isAuthor2 = securityManager.isIdentityInSecurityGroup(author2, authorGroup);
    dbInstance.commit();
    Assert.assertTrue(isAuthor1);
    Assert.assertTrue(isAuthor2);
    // is auth0 owner
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course, true);
    boolean isOwner1 = repositoryService.hasRole(author1, repositoryEntry, GroupRoles.owner.name());
    boolean isOwner2 = repositoryService.hasRole(author2, repositoryEntry, GroupRoles.owner.name());
    dbInstance.commit();
    Assert.assertTrue(isOwner1);
    Assert.assertTrue(isOwner2);
}
Also used : UserVO(org.olat.user.restapi.UserVO) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 47 with SecurityGroup

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

the class ImportAuthorOverviewIdentitiesController method loadModel.

private List<Identity> loadModel(String inp) {
    // securityManager.getIdentitiesOfSecurityGroup(securityGroup);
    List<Identity> existIdents = Collections.emptyList();
    List<Identity> okIdentities = new ArrayList<Identity>();
    List<String> isanonymous = new ArrayList<String>();
    List<String> notfounds = new ArrayList<String>();
    List<String> alreadyin = new ArrayList<String>();
    SecurityGroup anonymousSecGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ANONYMOUS);
    String[] lines = inp.split("\r?\n");
    for (int i = 0; i < lines.length; i++) {
        String username = lines[i].trim();
        if (!username.equals("")) {
            // skip empty lines
            Identity ident = securityManager.findIdentityByName(username);
            if (ident == null) {
                // not found, add to not-found-list
                notfounds.add(username);
            } else if (securityManager.isIdentityInSecurityGroup(ident, anonymousSecGroup)) {
                isanonymous.add(username);
            } else {
                // check if already in group
                boolean inGroup = PersistenceHelper.containsPersistable(existIdents, ident);
                if (inGroup) {
                    // added to warning: already in group
                    alreadyin.add(ident.getName());
                } else {
                    // ok to add -> preview (but filter duplicate entries)
                    if (!PersistenceHelper.containsPersistable(okIdentities, ident)) {
                        okIdentities.add(ident);
                    }
                }
            }
        }
    }
    return okIdentities;
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup)

Example 48 with SecurityGroup

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

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)

Example 49 with SecurityGroup

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

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

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

the class EPShareListController method createContainerForInvitation.

private void createContainerForInvitation(Invitation invitation, EPSharePolicyWrapper policyWrapper, String cmpName, FormLayoutContainer container) {
    FormLayoutContainer invitationContainer = FormLayoutContainer.createDefaultFormLayout("map.share.with." + cmpName, getTranslator());
    invitationContainer.contextPut("wrapper", policyWrapper);
    invitationContainer.setRootForm(mainForm);
    container.add("map.share.with." + cmpName, invitationContainer);
    TextElement firstNameEl = uifactory.addTextElement("map.share.with.firstName." + cmpName, "map.share.with.firstName", 64, invitation.getFirstName(), invitationContainer);
    firstNameEl.setMandatory(true);
    firstNameEl.setNotEmptyCheck("map.share.empty.warn");
    TextElement lastNameEl = uifactory.addTextElement("map.share.with.lastName." + cmpName, "map.share.with.lastName", 64, invitation.getLastName(), invitationContainer);
    lastNameEl.setMandatory(true);
    lastNameEl.setNotEmptyCheck("map.share.empty.warn");
    TextElement mailEl = uifactory.addTextElement("map.share.with.mail." + cmpName, "map.share.with.mail", 128, invitation.getMail(), invitationContainer);
    mailEl.setMandatory(true);
    mailEl.setNotEmptyCheck("map.share.empty.warn");
    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() });
        }
    }
    policyWrapper.setFirstNameEl(firstNameEl);
    policyWrapper.setLastNameEl(lastNameEl);
    policyWrapper.setMailEl(mailEl);
    String link = getInvitationLink(invitation, map);
    StaticTextElement linkEl = uifactory.addStaticTextElement("map.share.with.link." + cmpName, link, invitationContainer);
    linkEl.setLabel("map.share.with.link", null);
}
Also used : StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) 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