Search in sources :

Example 6 with ACService

use of org.olat.resource.accesscontrol.ACService in project openolat by klemens.

the class CoursesInfosWebService method collect.

private CourseInfoVO collect(final Identity identity, final Roles roles, final RepositoryEntry entry, final Set<Long> forumNotified, final Map<Long, Set<String>> courseNotified) {
    CourseInfoVO info = new CourseInfoVO();
    info.setRepoEntryKey(entry.getKey());
    info.setSoftKey(entry.getSoftkey());
    info.setDisplayName(entry.getDisplayname());
    ACService acManager = CoreSpringFactory.getImpl(ACService.class);
    AccessResult result = acManager.isAccessible(entry, identity, false);
    if (result.isAccessible()) {
        try {
            final ICourse course = CourseFactory.loadCourse(entry);
            final List<FolderVO> folders = new ArrayList<FolderVO>();
            final List<ForumVO> forums = new ArrayList<ForumVO>();
            final IdentityEnvironment ienv = new IdentityEnvironment(identity, roles);
            new CourseTreeVisitor(course, ienv).visit(new Visitor() {

                @Override
                public void visit(INode node) {
                    if (node instanceof BCCourseNode) {
                        BCCourseNode bcNode = (BCCourseNode) node;
                        folders.add(BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId())));
                    } else if (node instanceof FOCourseNode) {
                        FOCourseNode forumNode = (FOCourseNode) node;
                        forums.add(ForumCourseNodeWebService.createForumVO(course, forumNode, forumNotified));
                    }
                }
            }, new VisibleTreeFilter());
            info.setKey(course.getResourceableId());
            info.setTitle(course.getCourseTitle());
            info.setFolders(folders.toArray(new FolderVO[folders.size()]));
            info.setForums(forums.toArray(new ForumVO[forums.size()]));
        } catch (Exception e) {
            log.error("", e);
        }
    }
    return info;
}
Also used : ForumVO(org.olat.modules.fo.restapi.ForumVO) INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) FolderVO(org.olat.restapi.support.vo.FolderVO) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 7 with ACService

use of org.olat.resource.accesscontrol.ACService in project openolat by klemens.

the class CoursesWebService method isCourseAccessible.

public static boolean isCourseAccessible(ICourse course, boolean authorRightsMandatory, HttpServletRequest request) {
    if (authorRightsMandatory && !isAuthor(request)) {
        return false;
    }
    Identity identity = getIdentity(request);
    RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
    ACService acManager = CoreSpringFactory.getImpl(ACService.class);
    AccessResult result = acManager.isAccessible(entry, identity, false);
    if (result.isAccessible()) {
        return true;
    }
    return false;
}
Also used : ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity)

Example 8 with ACService

use of org.olat.resource.accesscontrol.ACService in project openolat by klemens.

the class RepositoryIndexer method checkAccess.

/**
 * @see org.olat.search.service.indexer.Indexer#checkAccess(org.olat.core.id.context.ContextEntry, org.olat.core.id.context.BusinessControl, org.olat.core.id.Identity, org.olat.core.id.Roles)
 */
@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    boolean debug = isLogDebugEnabled();
    if (debug)
        logDebug("checkAccess for businessControl=" + businessControl + "  identity=" + identity + "  roles=" + roles);
    Long repositoryKey = contextEntry.getOLATResourceable().getResourceableId();
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryKey);
    if (repositoryEntry == null) {
        return false;
    }
    if (roles.isGuestOnly()) {
        if (repositoryEntry.getAccess() != RepositoryEntry.ACC_USERS_GUESTS) {
            return false;
        }
    }
    boolean isOwner = repositoryManager.isOwnerOfRepositoryEntry(identity, repositoryEntry);
    boolean isAllowedToLaunch = false;
    if (!isOwner) {
        isAllowedToLaunch = repositoryManager.isAllowedToLaunch(identity, roles, repositoryEntry);
        if (isAllowedToLaunch) {
            List<ContextEntry> entries = businessControl.getEntriesDownTheControls();
            if (entries.size() > 1) {
                boolean hasAccess = false;
                ACService acService = CoreSpringFactory.getImpl(ACService.class);
                AccessResult acResult = acService.isAccessible(repositoryEntry, identity, false);
                if (acResult.isAccessible()) {
                    hasAccess = true;
                } else if (!acResult.getAvailableMethods().isEmpty()) {
                    for (OfferAccess offer : acResult.getAvailableMethods()) {
                        String type = offer.getMethod().getType();
                        if (type.equals(FreeAccessHandler.METHOD_TYPE) || type.equals(PaypalAccessHandler.METHOD_TYPE)) {
                            hasAccess = true;
                        }
                    }
                }
                isAllowedToLaunch = hasAccess;
            }
        }
    }
    if (debug)
        logDebug("isOwner=" + isOwner + "  isAllowedToLaunch=" + isAllowedToLaunch);
    if (isOwner || isAllowedToLaunch) {
        Indexer repositoryEntryIndexer = getRepositoryEntryIndexer(repositoryEntry);
        if (debug)
            logDebug("repositoryEntryIndexer=" + repositoryEntryIndexer);
        if (repositoryEntryIndexer != null) {
            return super.checkAccess(contextEntry, businessControl, identity, roles) && repositoryEntryIndexer.checkAccess(contextEntry, businessControl, identity, roles);
        }
    }
    return false;
}
Also used : OlatFullIndexer(org.olat.search.service.indexer.OlatFullIndexer) AbstractHierarchicalIndexer(org.olat.search.service.indexer.AbstractHierarchicalIndexer) Indexer(org.olat.search.service.indexer.Indexer) OfferAccess(org.olat.resource.accesscontrol.OfferAccess) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) RepositoryEntry(org.olat.repository.RepositoryEntry) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 9 with ACService

use of org.olat.resource.accesscontrol.ACService in project OpenOLAT by OpenOLAT.

the class CoursesWebService method isCourseAccessible.

public static boolean isCourseAccessible(ICourse course, boolean authorRightsMandatory, HttpServletRequest request) {
    if (authorRightsMandatory && !isAuthor(request)) {
        return false;
    }
    Identity identity = getIdentity(request);
    RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
    ACService acManager = CoreSpringFactory.getImpl(ACService.class);
    AccessResult result = acManager.isAccessible(entry, identity, false);
    if (result.isAccessible()) {
        return true;
    }
    return false;
}
Also used : ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity)

Example 10 with ACService

use of org.olat.resource.accesscontrol.ACService in project OpenOLAT by OpenOLAT.

the class CoursesInfosWebService method collect.

private CourseInfoVO collect(final Identity identity, final Roles roles, final RepositoryEntry entry, final Set<Long> forumNotified, final Map<Long, Set<String>> courseNotified) {
    CourseInfoVO info = new CourseInfoVO();
    info.setRepoEntryKey(entry.getKey());
    info.setSoftKey(entry.getSoftkey());
    info.setDisplayName(entry.getDisplayname());
    ACService acManager = CoreSpringFactory.getImpl(ACService.class);
    AccessResult result = acManager.isAccessible(entry, identity, false);
    if (result.isAccessible()) {
        try {
            final ICourse course = CourseFactory.loadCourse(entry);
            final List<FolderVO> folders = new ArrayList<FolderVO>();
            final List<ForumVO> forums = new ArrayList<ForumVO>();
            final IdentityEnvironment ienv = new IdentityEnvironment(identity, roles);
            new CourseTreeVisitor(course, ienv).visit(new Visitor() {

                @Override
                public void visit(INode node) {
                    if (node instanceof BCCourseNode) {
                        BCCourseNode bcNode = (BCCourseNode) node;
                        folders.add(BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId())));
                    } else if (node instanceof FOCourseNode) {
                        FOCourseNode forumNode = (FOCourseNode) node;
                        forums.add(ForumCourseNodeWebService.createForumVO(course, forumNode, forumNotified));
                    }
                }
            }, new VisibleTreeFilter());
            info.setKey(course.getResourceableId());
            info.setTitle(course.getCourseTitle());
            info.setFolders(folders.toArray(new FolderVO[folders.size()]));
            info.setForums(forums.toArray(new ForumVO[forums.size()]));
        } catch (Exception e) {
            log.error("", e);
        }
    }
    return info;
}
Also used : ForumVO(org.olat.modules.fo.restapi.ForumVO) INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) FolderVO(org.olat.restapi.support.vo.FolderVO) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Aggregations

ACService (org.olat.resource.accesscontrol.ACService)20 AccessResult (org.olat.resource.accesscontrol.AccessResult)12 RepositoryEntry (org.olat.repository.RepositoryEntry)10 ArrayList (java.util.ArrayList)6 Identity (org.olat.core.id.Identity)6 ICourse (org.olat.course.ICourse)6 BCCourseNode (org.olat.course.nodes.BCCourseNode)6 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)6 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)6 BusinessGroup (org.olat.group.BusinessGroup)6 BusinessGroupService (org.olat.group.BusinessGroupService)6 RepositoryManager (org.olat.repository.RepositoryManager)6 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 INode (org.olat.core.util.nodes.INode)4 Visitor (org.olat.core.util.tree.Visitor)4 FOCourseNode (org.olat.course.nodes.FOCourseNode)4 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)4 FolderVO (org.olat.restapi.support.vo.FolderVO)3 Date (java.util.Date)2