Search in sources :

Example 6 with CurrentAccess

use of org.bedework.access.Acl.CurrentAccess in project bw-calendar-engine by Bedework.

the class CalintfImpl method getResource.

/* ====================================================================
   *                       resources
   * ==================================================================== */
@Override
public BwResource getResource(final String name, final BwCalendar coll, final int desiredAccess) throws CalFacadeException {
    final BwResource res = entityDao.getResource(name, coll, desiredAccess);
    if (res == null) {
        return null;
    }
    final CurrentAccess ca = checkAccess(res, desiredAccess, true);
    if (!ca.getAccessAllowed()) {
        return null;
    }
    return res;
}
Also used : BwResource(org.bedework.calfacade.BwResource) CurrentAccess(org.bedework.access.Acl.CurrentAccess)

Example 7 with CurrentAccess

use of org.bedework.access.Acl.CurrentAccess in project bw-calendar-engine by Bedework.

the class CoreCalendars method checkAccess.

BwCalendar checkAccess(final CalendarWrapper col, final int desiredAccess, final boolean alwaysReturnResult) throws CalFacadeException {
    if (col == null) {
        return null;
    }
    final boolean noAccessNeeded = desiredAccess == privNone;
    final CurrentAccess ca = ac.checkAccess(col, desiredAccess, alwaysReturnResult || noAccessNeeded);
    if (!noAccessNeeded && !ca.getAccessAllowed()) {
        return null;
    }
    return col;
}
Also used : CurrentAccess(org.bedework.access.Acl.CurrentAccess)

Example 8 with CurrentAccess

use of org.bedework.access.Acl.CurrentAccess in project bw-calendar-engine by Bedework.

the class CoreCalendars method getSynchCols.

@Override
public Set<BwCalendar> getSynchCols(final String path, final String token) throws CalFacadeException {
    @SuppressWarnings("unchecked") final List<BwCalendar> cols = dao.getSynchCollections(fixPath(path), token);
    final Set<BwCalendar> res = new TreeSet<>();
    for (final BwCalendar col : cols) {
        final BwCalendar wcol = wrap(col);
        final CurrentAccess ca = ac.checkAccess(wcol, privAny, true);
        if (!ca.getAccessAllowed()) {
            continue;
        }
        res.add(wcol);
    }
    return res;
}
Also used : TreeSet(java.util.TreeSet) CurrentAccess(org.bedework.access.Acl.CurrentAccess) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 9 with CurrentAccess

use of org.bedework.access.Acl.CurrentAccess in project bw-calendar-engine by Bedework.

the class CoreEvents method doRecurrence.

/* Retrieves the overides for a recurring event and if required,
   * retrieves the instances.
   *
   * The overrides we retrieve are optionally limited by date.
   *
   * The CalDAV spec requires that we retrieve all overrides which fall within
   * the given date range AND all instances in that date range including
   * overriden instances that WOULD have fallen in that range had they not been
   * overriden.
   *
   * Thus we need to search both overrides and instances - unless no date range
   * is given in which case all overrides will appear along with the instances.
   *
   * If the calendars parameter is non-null, as it usually will be for a call
   * from getEvents, we limit the result to instances that appear within that
   * set of calendars. This handles the case of an overriden instance moved to a
   * different calendar, for example the trash.
   */
@SuppressWarnings("unchecked")
private void doRecurrence(final CoreEventInfo cei, final RecurringRetrievalMode recurRetrieval) throws CalFacadeException {
    final BwEvent master = cei.getEvent();
    final Set<String> overrides = new HashSet<>();
    final CurrentAccess ca = cei.getCurrentAccess();
    // Always fetch all overrides
    final Collection<BwEventAnnotation> ovs = dao.eventQuery(BwEventAnnotation.class, null, null, null, master, // overrides
    true, // recurRetrieval);
    null);
    if (ovs != null) {
        for (final BwEventAnnotation override : ovs) {
            final CoreEventInfo ocei = makeOverrideProxy(override, ca);
            cei.addOverride(ocei);
            overrides.add(ocei.getEvent().getRecurrenceId());
        }
    }
    if ((recurRetrieval == null) || (recurRetrieval.mode != Rmode.expanded)) {
        return;
    }
    /* Create a list of all instance date/times before overrides. */
    final int maxYears;
    final int maxInstances;
    maxYears = getAuthprops().getMaxYears();
    maxInstances = getAuthprops().getMaxInstances();
    final RecurPeriods rp = RecurUtil.getPeriods(master, maxYears, maxInstances);
    if (rp.instances.isEmpty()) {
        // No instances for an alleged recurring event.
        return;
    // throw new CalFacadeException(CalFacadeException.noRecurrenceInstances);
    }
    final String stzid = master.getDtstart().getTzid();
    final boolean dateOnly = master.getDtstart().getDateType();
    /* Emit all instances that aren't overridden. */
    final TreeSet<CoreEventInfo> ceis = new TreeSet<>();
    for (final Period p : rp.instances) {
        String dtval = p.getStart().toString();
        if (dateOnly) {
            dtval = dtval.substring(0, 8);
        }
        final BwDateTime rstart = BwDateTime.makeBwDateTime(dateOnly, dtval, stzid);
        if (overrides.contains(rstart.getDate())) {
            // Overrides built separately - skip this instance.
            continue;
        }
        final String recurrenceId = rstart.getDate();
        dtval = p.getEnd().toString();
        if (dateOnly) {
            dtval = dtval.substring(0, 8);
        }
        final BwDateTime rend = BwDateTime.makeBwDateTime(dateOnly, dtval, stzid);
        final BwRecurrenceInstance inst = new BwRecurrenceInstance(rstart, rend, recurrenceId, master, null);
        final CoreEventInfo instcei = makeInstanceProxy(inst, ca);
        if (instcei != null) {
            // if (debug) {
            // debugMsg("Ev: " + proxy);
            // }
            ceis.add(instcei);
        }
    }
    cei.setInstances(ceis);
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) Period(net.fortuna.ical4j.model.Period) BwEvent(org.bedework.calfacade.BwEvent) BwRecurrenceInstance(org.bedework.calfacade.BwRecurrenceInstance) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) TreeSet(java.util.TreeSet) CurrentAccess(org.bedework.access.Acl.CurrentAccess) RecurPeriods(org.bedework.icalendar.RecurUtil.RecurPeriods) HashSet(java.util.HashSet)

Example 10 with CurrentAccess

use of org.bedework.access.Acl.CurrentAccess in project bw-calendar-engine by Bedework.

the class CalSuites method wrap.

private BwCalSuiteWrapper wrap(final BwCalSuite cs, final boolean alwaysReturn) throws CalFacadeException {
    final CurrentAccess ca = checkAccess(cs, PrivilegeDefs.privAny, alwaysReturn);
    if ((ca == null) || !ca.getAccessAllowed()) {
        return null;
    }
    final BwCalSuiteWrapper w = new BwCalSuiteWrapper(cs, ca);
    final BwAdminGroup agrp = cs.getGroup();
    if (agrp == null) {
        return w;
    }
    final BwPrincipal eventsOwner = getSvc().getUsersHandler().getPrincipal(agrp.getOwnerHref());
    if (eventsOwner == null) {
        return w;
    }
    final BwCalendar home = getCols().getHome(eventsOwner, false);
    if (home == null) {
        return w;
    }
    w.setResourcesHome(home.getPath());
    return w;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) CurrentAccess(org.bedework.access.Acl.CurrentAccess) BwCalSuiteWrapper(org.bedework.calfacade.svc.wrappers.BwCalSuiteWrapper) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup) BwCalendar(org.bedework.calfacade.BwCalendar)

Aggregations

CurrentAccess (org.bedework.access.Acl.CurrentAccess)10 BwCalendar (org.bedework.calfacade.BwCalendar)6 TreeSet (java.util.TreeSet)3 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)3 BwEvent (org.bedework.calfacade.BwEvent)3 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)2 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Period (net.fortuna.ical4j.model.Period)1 AccessPrincipal (org.bedework.access.AccessPrincipal)1 PrivilegeSet (org.bedework.access.PrivilegeSet)1 BwDateTime (org.bedework.calfacade.BwDateTime)1 BwEventProxy (org.bedework.calfacade.BwEventProxy)1 BwPrincipal (org.bedework.calfacade.BwPrincipal)1 BwRecurrenceInstance (org.bedework.calfacade.BwRecurrenceInstance)1 BwResource (org.bedework.calfacade.BwResource)1 CalFacadeBadRequest (org.bedework.calfacade.exc.CalFacadeBadRequest)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)1