Search in sources :

Example 6 with RepositoryManager

use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.

the class CourseSecurityTest method setUp.

/**
 * SetUp is called before each test.
 */
@Before
public void setUp() throws Exception {
    super.setUp();
    conn = new RestConnection();
    try {
        // create course and persist as OLATResourceImpl
        admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
        id1 = JunitTestHelper.createAndPersistIdentityAsUser("id-c-s-0");
        Assert.assertNotNull(id1);
        auth1 = JunitTestHelper.createAndPersistIdentityAsAuthor("id-c-s-1");
        Assert.assertNotNull(auth1);
        auth2 = JunitTestHelper.createAndPersistIdentityAsAuthor("id-c-s-2");
        Assert.assertNotNull(auth2);
        course = CoursesWebService.createEmptyCourse(admin, "course-security-2", "Test course for the security test", null);
        DBFactory.getInstance().intermediateCommit();
        RepositoryManager rm = RepositoryManager.getInstance();
        RepositoryEntry re = rm.lookupRepositoryEntry(course, false);
        IdentitiesAddEvent identitiesAddEvent = new IdentitiesAddEvent(Collections.singletonList(auth2));
        rm.addOwners(admin, identitiesAddEvent, re, null);
        DBFactory.getInstance().closeSession();
    } catch (Exception e) {
        log.error("Exception in setUp(): " + e);
    }
}
Also used : IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Example 7 with RepositoryManager

use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.

the class SharedFolderWebDAVMergeSource method loadMergedContainers.

@Override
protected List<VFSContainer> loadMergedContainers() {
    SharedFolderManager sfm = SharedFolderManager.getInstance();
    RepositoryManager repoManager = RepositoryManager.getInstance();
    List<VFSContainer> containers = new ArrayList<>();
    Set<Long> addedEntries = new HashSet<>();
    List<RepositoryEntry> ownerEntries = repoManager.queryByMembership(getIdentity(), true, true, false, SharedFolderFileResource.TYPE_NAME);
    for (RepositoryEntry entry : ownerEntries) {
        VFSContainer container = sfm.getNamedSharedFolder(entry, true);
        if (container != null) {
            addContainerToList(container, containers);
            addedEntries.add(entry.getKey());
        }
    }
    List<RepositoryEntry> participantEntries = repoManager.queryByMembership(getIdentity(), false, false, true, SharedFolderFileResource.TYPE_NAME);
    for (RepositoryEntry entry : participantEntries) {
        addReadonlyFolder(entry, sfm, addedEntries, containers);
    }
    // see /webapp/WEB-INF/classes/org/olat/core/commons/services/webdav/webdavContext.xml
    if (publiclyReadableFolders != null && publiclyReadableFolders.size() > 0) {
        // Temporarily save added entries. This is needed to make sure not to add an entry twice.
        String firstItem = publiclyReadableFolders.get(0);
        // If the first value in the list is '*', list all resource folders.
        if (firstItem != null && firstItem.equals("*")) {
            // fake role that represents normally logged in user
            Roles registeredUserRole = new Roles(false, false, false, false, false, false, false);
            List<String> types = Collections.singletonList(SharedFolderFileResource.TYPE_NAME);
            List<RepositoryEntry> allEntries = repoManager.queryByTypeLimitAccess(getIdentity(), types, registeredUserRole);
            for (RepositoryEntry entry : allEntries) {
                addReadonlyFolder(entry, sfm, addedEntries, containers);
            }
        } else {
            // only list the specified folders
            List<Long> publiclyReadableFoldersKeys = getSharedKeys();
            List<RepositoryEntry> entries = repoManager.lookupRepositoryEntries(publiclyReadableFoldersKeys);
            for (RepositoryEntry entry : entries) {
                if (entry.getAccess() >= RepositoryEntry.ACC_USERS || (entry.getAccess() == RepositoryEntry.ACC_OWNERS && entry.isMembersOnly())) {
                    // add folder (which is a repo entry) to root container if not present
                    addReadonlyFolder(entry, sfm, addedEntries, containers);
                } else {
                    log.warn("Access denied on entry::" + entry.getKey(), null);
                }
            }
        }
    }
    return containers;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryManager(org.olat.repository.RepositoryManager) HashSet(java.util.HashSet)

Example 8 with RepositoryManager

use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.

the class GoToMeetingCourseNode method createNodeRunConstructionResult.

@Override
public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
    updateModuleConfigDefaults(false);
    Controller controller;
    Roles roles = ureq.getUserSession().getRoles();
    if (roles.isGuestOnly()) {
        Translator trans = Util.createPackageTranslator(GoToMeetingEditController.class, ureq.getLocale());
        String title = trans.translate("guestnoaccess.title");
        String message = trans.translate("guestnoaccess.message");
        controller = MessageUIFactory.createInfoMessage(ureq, wControl, title, message);
    } else {
        // check if user is moderator of the virtual classroom
        boolean admin = roles.isOLATAdmin();
        boolean moderator = admin;
        RepositoryEntry re = userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        if (!admin) {
            RepositoryManager rm = RepositoryManager.getInstance();
            if (re != null) {
                admin = rm.isOwnerOfRepositoryEntry(ureq.getIdentity(), re) || rm.isInstitutionalRessourceManagerFor(ureq.getIdentity(), roles, re);
                moderator = admin || rm.isIdentityInTutorSecurityGroup(ureq.getIdentity(), re) || isCoach(re, ureq.getIdentity());
            }
        }
        // create run controller
        RepositoryEntry courseEntry = userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        controller = new GoToMeetingRunController(ureq, wControl, courseEntry, getIdent(), null, admin, moderator, userCourseEnv.isCourseReadOnly());
    }
    Controller ctrl = TitledWrapperHelper.getWrapper(ureq, wControl, controller, this, "o_gotomeeting_icon");
    return new NodeRunConstructionResult(ctrl);
}
Also used : Translator(org.olat.core.gui.translator.Translator) GoToMeetingRunController(org.olat.modules.gotomeeting.ui.GoToMeetingRunController) Roles(org.olat.core.id.Roles) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) TabbableController(org.olat.core.gui.control.generic.tabbable.TabbableController) GoToMeetingPeekViewController(org.olat.course.nodes.gotomeeting.GoToMeetingPeekViewController) GoToMeetingEditController(org.olat.course.nodes.gotomeeting.GoToMeetingEditController) Controller(org.olat.core.gui.control.Controller) NodeEditController(org.olat.course.editor.NodeEditController) GoToMeetingRunController(org.olat.modules.gotomeeting.ui.GoToMeetingRunController) ConditionEditController(org.olat.course.condition.ConditionEditController) NodeRunConstructionResult(org.olat.course.run.navigation.NodeRunConstructionResult)

Example 9 with RepositoryManager

use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.

the class OpenMeetingsCourseNode method createNodeRunConstructionResult.

@Override
public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
    updateModuleConfigDefaults(false);
    Roles roles = ureq.getUserSession().getRoles();
    // check if user is moderator of the virtual classroom
    boolean admin = roles.isOLATAdmin();
    boolean moderator = admin;
    RepositoryEntry re = userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    if (!admin) {
        RepositoryManager rm = RepositoryManager.getInstance();
        if (re != null) {
            admin = rm.isOwnerOfRepositoryEntry(ureq.getIdentity(), re) || rm.isInstitutionalRessourceManagerFor(ureq.getIdentity(), roles, re);
            moderator = admin || rm.isIdentityInTutorSecurityGroup(ureq.getIdentity(), re) || isCoach(re, ureq.getIdentity());
        }
    }
    // create run controller
    OLATResourceable ores = OresHelper.clone(userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseResource());
    Controller runCtr = new OpenMeetingsRunController(ureq, wControl, null, ores, getIdent(), admin, moderator, userCourseEnv.isCourseReadOnly());
    Controller controller = TitledWrapperHelper.getWrapper(ureq, wControl, runCtr, this, "o_openmeetings_icon");
    return new NodeRunConstructionResult(controller);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) OpenMeetingsRunController(org.olat.modules.openmeetings.ui.OpenMeetingsRunController) Roles(org.olat.core.id.Roles) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) TabbableController(org.olat.core.gui.control.generic.tabbable.TabbableController) OpenMeetingsEditController(org.olat.course.nodes.openmeetings.OpenMeetingsEditController) OpenMeetingsPeekViewController(org.olat.course.nodes.openmeetings.OpenMeetingsPeekViewController) OpenMeetingsRunController(org.olat.modules.openmeetings.ui.OpenMeetingsRunController) CPEditController(org.olat.course.nodes.cp.CPEditController) Controller(org.olat.core.gui.control.Controller) NodeEditController(org.olat.course.editor.NodeEditController) OpenMeetingsRoomEditController(org.olat.modules.openmeetings.ui.OpenMeetingsRoomEditController) ConditionEditController(org.olat.course.condition.ConditionEditController) NodeRunConstructionResult(org.olat.course.run.navigation.NodeRunConstructionResult)

Example 10 with RepositoryManager

use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.

the class FeedMediaDispatcher method hasAccess.

/**
 * Verifiy if the identity has access to the feed.
 *
 * @param identity
 * @param token
 * @param feed
 * @return true if the identity has access.
 */
private boolean hasAccess(Identity identity, String token, OLATResourceable feed) {
    boolean hasAccess = false;
    RepositoryManager resMgr = RepositoryManager.getInstance();
    RepositoryEntry repoEntry = resMgr.lookupRepositoryEntry(feed, false);
    if (allowsGuestAccess(repoEntry)) {
        hasAccess = true;
    } else if (identity != null) {
        if (repoEntry != null) {
            final Roles roles = BaseSecurityManager.getInstance().getRoles(identity);
            final boolean isAllowedToLaunch = resMgr.isAllowedToLaunch(identity, roles, repoEntry);
            if (isAllowedToLaunch && validAuthentication(identity, token)) {
                hasAccess = true;
            }
        } else {
            // no repository entry -> could be a feed without a repository-entry (ePortfolio-Blog-feed)
            EPFrontendManager ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean("epFrontendManager");
            if (ePFMgr.checkFeedAccess(feed, identity)) {
                return validAuthentication(identity, token);
            }
        }
    }
    return hasAccess;
}
Also used : RepositoryManager(org.olat.repository.RepositoryManager) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) EPFrontendManager(org.olat.portfolio.manager.EPFrontendManager)

Aggregations

RepositoryManager (org.olat.repository.RepositoryManager)136 RepositoryEntry (org.olat.repository.RepositoryEntry)122 Path (javax.ws.rs.Path)42 Identity (org.olat.core.id.Identity)32 Produces (javax.ws.rs.Produces)30 Roles (org.olat.core.id.Roles)30 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)26 ArrayList (java.util.ArrayList)20 Consumes (javax.ws.rs.Consumes)20 PUT (javax.ws.rs.PUT)18 MailPackage (org.olat.core.util.mail.MailPackage)16 GET (javax.ws.rs.GET)14 BaseSecurity (org.olat.basesecurity.BaseSecurity)14 AssertException (org.olat.core.logging.AssertException)14 SearchRepositoryEntryParameters (org.olat.repository.model.SearchRepositoryEntryParameters)14 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)12 Controller (org.olat.core.gui.control.Controller)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 UserRequest (org.olat.core.gui.UserRequest)10 WindowControl (org.olat.core.gui.control.WindowControl)10