Search in sources :

Example 21 with CalFacadeAccessException

use of org.bedework.calfacade.exc.CalFacadeAccessException in project bw-calendar-engine by Bedework.

the class Calendars method decomposeVirtualPath.

@Override
public Collection<BwCalendar> decomposeVirtualPath(final String vpath) throws CalFacadeException {
    vpathCalls++;
    if (debug && ((vpathCalls % 250) == 0)) {
        trace("Vpath calls: " + vpathCalls);
        trace(" Vpath hits: " + vpathHits);
        trace(" Vpath size: " + vpathCache.size());
    }
    if ((System.currentTimeMillis() - lastVpathFlush) > vpathFlushPeriod) {
        vpathCache.clear();
        lastVpathFlush = System.currentTimeMillis();
    }
    if (vpathCache.size() > maxVpathCached) {
        info("Flushing vpath cache - reached max size of " + maxVpathCached);
        vpathCache.clear();
    }
    final BwPrincipal pr = getPrincipal();
    final String cacheKey;
    if (pr.getUnauthenticated()) {
        cacheKey = "*|" + vpath;
    } else {
        cacheKey = pr.getPrincipalRef() + "|" + vpath;
    }
    List<BwCalendar> cols = vpathCache.get(cacheKey);
    if (cols != null) {
        vpathHits++;
        return cols;
    }
    cols = new ArrayList<>();
    /* See if the vpath is an actual path - generally the case for
     * personal calendar users.
     */
    BwCalendar startCol = getIdx(vpath);
    if ((startCol != null) && !startCol.getAlias()) {
        cols.add(startCol);
        vpathCache.put(cacheKey, cols);
        return cols;
    }
    final String[] pathEls = normalizeUri(vpath).split("/");
    if (pathEls.length == 0) {
        vpathCache.put(cacheKey, cols);
        return cols;
    }
    /* First, keep adding elements until we get a BwCalendar result.
     * This handles the user root not being accessible
     */
    startCol = null;
    String startPath = "";
    // Element 0 is a zero length string
    int pathi = 1;
    while (pathi < pathEls.length) {
        startPath = Util.buildPath(colPathEndsWithSlash, startPath, "/", pathEls[pathi]);
        pathi++;
        try {
            startCol = getIdx(startPath);
        } catch (final CalFacadeAccessException cfae) {
            startCol = null;
        }
        if (startCol != null) {
            // Found the start collection
            if (debug) {
                debug("Start vpath collection:" + startCol.getPath());
            }
            break;
        }
    }
    if (startCol == null) {
        // Bad vpath
        return null;
    }
    BwCalendar curCol = startCol;
    buildCollection: for (; ; ) {
        cols.add(curCol);
        if (debug) {
            debug("      vpath collection:" + curCol.getPath());
        }
        // Follow the chain of references for curCol until we reach a non-alias
        if (curCol.getInternalAlias()) {
            final BwCalendar nextCol = resolveAliasIdx(curCol, false, false);
            if (nextCol == null) {
                // Bad vpath
                curCol.setDisabled(true);
                curCol.setLastRefreshStatus("400");
                return null;
            }
            curCol = nextCol;
            continue buildCollection;
        }
        /* Not an alias - do we have any more path elements
       */
        if (pathi >= pathEls.length) {
            break buildCollection;
        }
        if (curCol.getCalType() != BwCalendar.calTypeFolder) {
            // Bad vpath
            return null;
        }
        /*
      for (BwCalendar col: getChildren(curCol)) {
        if (col.getName().equals(pathEls[pathi])) {
          // Found our child
          pathi++;
          curCol = col;
          continue buildCollection;
        }
      }
      */
        final BwCalendar col = getIdx(Util.buildPath(colPathEndsWithSlash, curCol.getPath(), "/", pathEls[pathi]));
        if (col == null) {
            /* Child not found - bad vpath */
            return null;
        }
        pathi++;
        curCol = col;
    }
    curCol.setAliasOrigin(startCol);
    vpathCache.put(cacheKey, cols);
    return cols;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException)

Example 22 with CalFacadeAccessException

use of org.bedework.calfacade.exc.CalFacadeAccessException in project bw-calendar-engine by Bedework.

the class OutboundSchedulingHandler method sendSchedule.

/* Send the meeting request. If recipient is non-null send only to that recipient
   * (used for REFRESH handling), otherwise send to recipients in event.
   */
protected void sendSchedule(final ScheduleResult sr, final EventInfo ei, final String recipient, final String fromAttUri, final boolean fromOrganizer) throws CalFacadeException {
    /* Recipients external to the system. */
    final BwEvent ev = ei.getEvent();
    final boolean freeBusyRequest = ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy;
    ev.updateDtstamp();
    if (recipient != null) {
        getRecipientInbox(ei, recipient, fromAttUri, sr, freeBusyRequest);
    } else if (ev.getRecipients() == null) {
        return;
    } else {
        for (final String recip : ev.getRecipients()) {
            getRecipientInbox(ei, recip, fromAttUri, sr, freeBusyRequest);
        }
    }
    /* As we go through the inbox info, we gather together those for the same
     * host but external to this system.
     *
     * We then send off one request to each external host.
     */
    final Map<String, Collection<UserInbox>> hostMap = new HashMap<>();
    for (final ScheduleRecipientResult sres : sr.recipientResults.values()) {
        final UserInbox ui = (UserInbox) sres;
        if (sr.ignored) {
            ui.setStatus(ScheduleStates.scheduleIgnored);
            continue;
        }
        if (ui.getStatus() == ScheduleStates.scheduleUnprocessed) {
            if (ui.getHost() != null) {
                /* Needs to be sent to an external destination. Add it
           * to the list of inboxes for that host.
           */
                Collection<UserInbox> inboxes = hostMap.get(ui.getHost().getHostname());
                if (inboxes == null) {
                    inboxes = new ArrayList<>();
                    hostMap.put(ui.getHost().getHostname(), inboxes);
                }
                inboxes.add(ui);
                continue;
            }
            /* Going to an internal destination */
            String deliveryStatus = null;
            try {
                if (freeBusyRequest) {
                    sres.freeBusy = getFreeBusy(null, ui.principal, ev.getDtstart(), ev.getDtend(), ev.getOrganizer(), ev.getUid(), null);
                    ui.setStatus(ScheduleStates.scheduleOk);
                } else if (!ui.principal.getPrincipalRef().equals(getPrincipal().getPrincipalRef())) {
                    if (addToInbox(ui.inboxPath, ui.principal, ei, fromOrganizer) == null) {
                        ui.setStatus(ScheduleStates.scheduleOk);
                        deliveryStatus = IcalDefs.deliveryStatusDelivered;
                    } else {
                        ui.setStatus(ScheduleStates.scheduleError);
                        deliveryStatus = IcalDefs.deliveryStatusFailed;
                    }
                } else {
                    // That's us
                    ui.setAttendeeScheduleStatus(null);
                    ui.setStatus(ScheduleStates.scheduleOk);
                }
            } catch (CalFacadeAccessException cae) {
                ui.setStatus(ScheduleStates.scheduleNoAccess);
                deliveryStatus = IcalDefs.deliveryStatusNoAccess;
            }
            if (fromOrganizer) {
                if (deliveryStatus != null) {
                    ui.setAttendeeScheduleStatus(deliveryStatus);
                }
            } else {
            // ev.getOrganizer().setScheduleStatus(deliveryStatus);
            }
        }
        if (debug) {
            trace("added recipient " + ui.recipient + " status = " + ui.getStatus());
        }
    }
    for (final Collection<UserInbox> inboxes : hostMap.values()) {
        /* Send any ischedule requests to external servers. */
        sendExternalRequest(sr, ei, inboxes);
    }
}
Also used : ScheduleRecipientResult(org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult) HashMap(java.util.HashMap) Collection(java.util.Collection) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException)

Example 23 with CalFacadeAccessException

use of org.bedework.calfacade.exc.CalFacadeAccessException in project bw-calendar-engine by Bedework.

the class OutboundSchedulingHandler method getInbox.

/* Return with deferred for external user.
   *
   * For an internal user - skips it if it's ourself - we don't want
   * our own message in our inbox. Otherwise checks that we have access
   * to send the message. If so sets the path of the inbox.
   */
private UserInbox getInbox(final ScheduleResult sr, final String recipient, final boolean freeBusyRequest) throws CalFacadeException {
    UserInbox ui = (UserInbox) sr.recipientResults.get(recipient);
    if (ui != null) {
        return ui;
    }
    ui = new UserInbox(recipient);
    sr.addRecipientResult(ui);
    final BwPrincipal principal = getSvc().getDirectories().caladdrToPrincipal(recipient);
    if (principal == null) {
        /* External to the system */
        ui.setHost(BwHosts.getHostForRecipient(recipient));
        final Host hi = ui.getHost();
        if (hi == null) {
            ui.setStatus(ScheduleStates.scheduleDeferred);
            return ui;
        }
        if (freeBusyRequest) {
            // All can handle that
            return ui;
        }
        if (!hi.getSupportsISchedule() && !hi.getSupportsCaldav() && !hi.getSupportsBedework()) {
            ui.setStatus(ScheduleStates.scheduleDeferred);
        }
        return ui;
    }
    try {
        if (principal.getPrincipalRef().equals(getPrincipal().getPrincipalRef())) {
            /* This is our own account. Let's not add it to our inbox.
         */
            ui.principal = getPrincipal();
            ui.setStatus(ScheduleStates.scheduleUnprocessed);
            return ui;
        }
        ui.principal = principal;
        final int priv;
        if (freeBusyRequest) {
            priv = PrivilegeDefs.privScheduleFreeBusy;
        } else {
            priv = PrivilegeDefs.privScheduleRequest;
        }
        final BwCalendar inbox = getSpecialCalendar(ui.principal, BwCalendar.calTypePendingInbox, true, priv);
        if (inbox == null) {
            ui.setStatus(ScheduleStates.scheduleNoAccess);
        } else {
            ui.inboxPath = inbox.getPath();
        }
    } catch (CalFacadeAccessException cae) {
        ui.setStatus(ScheduleStates.scheduleNoAccess);
    }
    return ui;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) Host(org.bedework.caldav.server.sysinterface.Host) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException)

Example 24 with CalFacadeAccessException

use of org.bedework.calfacade.exc.CalFacadeAccessException in project bw-calendar-engine by Bedework.

the class CalSys method getChildCollections.

/**
 * Get the next batch of child collection paths.
 *
 * @param path to parent
 * @param refs - null on first call.
 * @return next batch of hrefs or null for no more.
 * @throws CalFacadeException
 */
protected Refs getChildCollections(final String path, final Refs refs) throws CalFacadeException {
    if (debug) {
        debug("getChildCollections(" + path + ")");
    }
    Refs r = refs;
    if (r == null) {
        r = new Refs();
        r.batchSize = collectionBatchSize;
    }
    try (BwSvc bw = getAdminBw()) {
        final BwCalendar col = bw.getSvci().getCalendarsHandler().get(path);
        if ((col == null) || !hasAccess(col)) {
            if (debug) {
                if (col == null) {
                    debug("No collection");
                } else {
                    debug("No access");
                }
            }
            throw new CalFacadeAccessException();
        }
        r.refs = bw.getSvci().getAdminHandler().getChildCollections(path, r.index, r.batchSize);
        if (debug) {
            if (r.refs == null) {
                debug("getChildCollections(" + path + ") found none");
            } else {
                debug("getChildCollections(" + path + ") found " + r.refs.size());
            }
        }
        if (r.refs == null) {
            return null;
        }
        r.index += r.refs.size();
        return r;
    }
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException)

Example 25 with CalFacadeAccessException

use of org.bedework.calfacade.exc.CalFacadeAccessException in project bw-calendar-engine by Bedework.

the class CalSys method getChildEntities.

/**
 * Get the next batch of child entity names.
 *
 * @param path to parent
 * @param refs - null on first call.
 * @return next batch of hrefs or null for no more.
 * @throws CalFacadeException
 */
protected Refs getChildEntities(final String path, final Refs refs) throws CalFacadeException {
    if (debug) {
        debug("getChildEntities(" + path + ")");
    }
    Refs r = refs;
    if (r == null) {
        r = new Refs();
        r.batchSize = entityBatchSize;
    }
    try (BwSvc bw = getAdminBw()) {
        final BwCalendar col = bw.getSvci().getCalendarsHandler().get(path);
        if ((col == null) || !hasAccess(col)) {
            throw new CalFacadeAccessException();
        }
        r.refs = bw.getSvci().getAdminHandler().getChildEntities(path, r.index, r.batchSize);
        if (debug) {
            if (r.refs == null) {
                debug("getChildEntities(" + path + ") found none");
            } else {
                debug("getChildEntities(" + path + ") found " + r.refs.size());
            }
        }
        if (r.refs == null) {
            return null;
        }
        r.index += r.refs.size();
        return r;
    }
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException)

Aggregations

CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)29 BwCalendar (org.bedework.calfacade.BwCalendar)18 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)16 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)13 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)13 EventInfo (org.bedework.calfacade.svc.EventInfo)7 BwEvent (org.bedework.calfacade.BwEvent)6 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)6 ArrayList (java.util.ArrayList)5 TreeSet (java.util.TreeSet)3 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)3 Collection (java.util.Collection)2 CurrentAccess (org.bedework.access.Acl.CurrentAccess)2 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)2 FilterBase (org.bedework.caldav.util.filter.FilterBase)2 BwAttendee (org.bedework.calfacade.BwAttendee)2 BwCategory (org.bedework.calfacade.BwCategory)2 BwEventProxy (org.bedework.calfacade.BwEventProxy)2 BwPrincipal (org.bedework.calfacade.BwPrincipal)2 ScheduleResult (org.bedework.calfacade.ScheduleResult)2