Search in sources :

Example 76 with SecurityGroup

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

the class LDAPLoginTest method testCreateChangedAttrMap.

@Test
@Ignore
public void testCreateChangedAttrMap() {
    Assume.assumeTrue(ldapLoginModule.isLDAPEnabled());
    // simulate closed session (user adding from startup job)
    DBFactory.getInstance().intermediateCommit();
    String uid = "kmeier";
    String pwd = "olat";
    LDAPError errors = new LDAPError();
    boolean usersSyncedAtStartup = ldapLoginModule.isLdapSyncOnStartup();
    if (usersSyncedAtStartup) {
        try {
            // create user but with different attributes - must fail since user already exists
            User user = UserManager.getInstance().createUser("klaus", "Meier", "klaus@meier.ch");
            Identity identity = securityManager.createAndPersistIdentityAndUser("kmeier", null, user, "LDAP", "kmeier");
            SecurityGroup secGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
            securityManager.addIdentityToSecurityGroup(identity, secGroup);
            // simulate closed session (user adding from startup job)
            DBFactory.getInstance().intermediateCommit();
            fail("Expected constrant violation becaus of doupliate entry");
        } catch (Exception e) {
        // success, this is what we expected
        }
        // changedAttrMap empty since already synchronized
        Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
        Identity identitys = securityManager.findIdentityByName(uid);
        Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
        // map is empty - no attributes to sync
        assertNull(changedAttrMap);
    } else {
        // create user but with different attributes - must fail since user already exists
        User user = UserManager.getInstance().createUser("klaus", "Meier", "klaus@meier.ch");
        Identity identity = securityManager.createAndPersistIdentityAndUser("kmeier", null, user, "LDAP", "kmeier");
        SecurityGroup secGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
        securityManager.addIdentityToSecurityGroup(identity, secGroup);
        // simulate closed session (user adding from startup job)
        DBFactory.getInstance().intermediateCommit();
        // changedAttrMap has 2 changes and uid as entrys (Klaus!=klaus, klaus@olat.org!=klaus@meier.ch)
        Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
        Identity identitys = securityManager.findIdentityByName(uid);
        Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
        // result must be 3: 2 changed plus the user ID which is always in the map
        assertEquals(3, changedAttrMap.keySet().size());
    }
    // nothing to change for this user
    uid = "mrohrer";
    Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
    Identity identitys = securityManager.findIdentityByName(uid);
    Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
    assertEquals(true, (changedAttrMap == null));
}
Also used : LDAPUser(org.olat.ldap.model.LDAPUser) User(org.olat.core.id.User) Attributes(javax.naming.directory.Attributes) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) NamingException(javax.naming.NamingException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 77 with SecurityGroup

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

the class EPFrontendManagerTest method deleteMap_withOldPolicy.

@Test
public void deleteMap_withOldPolicy() {
    // create map
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("frtuse-7");
    PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(id, "Delete map", "Description");
    PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(map, "Page while be deleted", "Page description");
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(id, "Forum");
    epFrontendManager.addArtefactToStructure(id, artefact, page);
    dbInstance.commit();
    // create an old policy manually
    SecurityGroup secGroup = securityManager.createAndPersistSecurityGroup();
    Policy policy = securityManager.createAndPersistPolicy(secGroup, "allusers_" + Constants.PERMISSION_READ, map.getOlatResource());
    Assert.assertNotNull(policy);
    dbInstance.commitAndCloseSession();
    // delete the map
    PortfolioStructure reloadedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    epFrontendManager.deletePortfolioStructure(reloadedMap);
    dbInstance.commit();
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) Policy(org.olat.basesecurity.Policy) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) Test(org.junit.Test)

Example 78 with SecurityGroup

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

the class CourseTest method removeAuthor.

@Test
public void removeAuthor() 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<>();
    authors.add(auth1);
    authors.add(auth2);
    IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
    repositoryManager.addOwners(admin, identitiesAddedEvent, repositoryEntry, null);
    dbInstance.intermediateCommit();
    // end setup
    // test
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors/" + auth1.getKey()).build();
    HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    URI request2 = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors/" + auth2.getKey()).build();
    HttpDelete method2 = conn.createDelete(request2, MediaType.APPLICATION_JSON);
    HttpResponse response2 = conn.execute(method2);
    assertEquals(200, response2.getStatusLine().getStatusCode());
    EntityUtils.consume(response2.getEntity());
    // control
    repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
    assertFalse(repositoryService.hasRole(auth1, repositoryEntry, GroupRoles.owner.name()));
    assertFalse(repositoryService.hasRole(auth2, repositoryEntry, GroupRoles.owner.name()));
    dbInstance.intermediateCommit();
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) 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 79 with SecurityGroup

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

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

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

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