Search in sources :

Example 6 with AccessResult

use of org.olat.resource.accesscontrol.AccessResult 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 AccessResult

use of org.olat.resource.accesscontrol.AccessResult 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 AccessResult

use of org.olat.resource.accesscontrol.AccessResult 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 AccessResult

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

the class TokenAccessController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    String token = tokenEl.getValue();
    AccessResult result = acService.accessResource(getIdentity(), link, token);
    if (result.isAccessible()) {
        fireEvent(ureq, AccessEvent.ACCESS_OK_EVENT);
    } else {
        String msg = translate("invalid.token");
        fireEvent(ureq, new AccessEvent(AccessEvent.ACCESS_FAILED, msg));
    }
}
Also used : AccessEvent(org.olat.resource.accesscontrol.ui.AccessEvent) AccessResult(org.olat.resource.accesscontrol.AccessResult)

Example 10 with AccessResult

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

the class MainAccessController method doAccessResource.

protected void doAccessResource(UserRequest ureq, OfferAccess link) {
    AccessResult result = acService.accessResource(getIdentity(), link, null);
    if (result.isAccessible()) {
        fireEvent(ureq, AccessEvent.ACCESS_OK_EVENT);
    } else {
        fireEvent(ureq, new AccessEvent(AccessEvent.ACCESS_FAILED));
        showError("error.accesscontrol");
    }
}
Also used : AccessResult(org.olat.resource.accesscontrol.AccessResult)

Aggregations

AccessResult (org.olat.resource.accesscontrol.AccessResult)24 RepositoryEntry (org.olat.repository.RepositoryEntry)12 ACService (org.olat.resource.accesscontrol.ACService)12 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 Identity (org.olat.core.id.Identity)6 ICourse (org.olat.course.ICourse)6 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)6 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 Roles (org.olat.core.id.Roles)4 INode (org.olat.core.util.nodes.INode)4 Visitor (org.olat.core.util.tree.Visitor)4 BCCourseNode (org.olat.course.nodes.BCCourseNode)4 BusinessGroup (org.olat.group.BusinessGroup)4 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)4 OLATResource (org.olat.resource.OLATResource)4 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)4 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)4 Offer (org.olat.resource.accesscontrol.Offer)3