Search in sources :

Example 11 with AccessResult

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

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 12 with AccessResult

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

the class ACFrontendManager method isAccessible.

/**
 * The rule to access the repository entry:<br/>
 * -No offer, access is free<br/>
 * -Owners have always access to the resource<br/>
 * -Tutors have access to the resource<br/>
 * -Participants have access to the resource<br/>
 * @param entry
 * @param forId
 * @param knowMember give it if already know as a member
 * @return
 */
@Override
public AccessResult isAccessible(RepositoryEntry entry, Identity forId, Boolean knowMember, boolean allowNonInteractiveAccess) {
    if (!accessModule.isEnabled()) {
        return new AccessResult(true);
    }
    boolean member;
    if (knowMember == null) {
        member = repositoryService.isMember(forId, entry);
    } else {
        member = knowMember.booleanValue();
    }
    if (member) {
        return new AccessResult(true);
    }
    Date now = dateNow();
    List<Offer> offers = accessManager.findOfferByResource(entry.getOlatResource(), true, now);
    if (offers.isEmpty()) {
        if (methodManager.isValidMethodAvailable(entry.getOlatResource(), null)) {
            // not open for the moment: no valid offer at this date but some methods are defined
            return new AccessResult(false);
        } else {
            return new AccessResult(true);
        }
    }
    return isAccessible(forId, offers, allowNonInteractiveAccess);
}
Also used : Offer(org.olat.resource.accesscontrol.Offer) AccessResult(org.olat.resource.accesscontrol.AccessResult) Date(java.util.Date)

Example 13 with AccessResult

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

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)

Example 14 with AccessResult

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

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

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