Search in sources :

Example 11 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getCollections.

@Override
public Collection<CalDAVCollection> getCollections(final CalDAVCollection col) throws WebdavException {
    try {
        final BwCalendar bwCol = unwrap(col);
        boolean isUserHome = false;
        List<Integer> provisionedTypes = null;
        /* Is this the calendar home? If so we have to ensure all
         provisioned collections exist */
        if (getPrincipal() != null) {
            final String userHomePath = Util.buildPath(true, getSvci().getPrincipalInfo().getCalendarHomePath(getPrincipal()));
            if (Util.buildPath(true, bwCol.getPath()).equals(userHomePath)) {
                isUserHome = true;
                provisionedTypes = new ArrayList<>();
                for (final BwCalendar.CollectionInfo ci : BwCalendar.getAllCollectionInfo()) {
                    if (ci.provision) {
                        provisionedTypes.add(ci.collectionType);
                    }
                }
            }
        }
        final CalendarsI ci = getSvci().getCalendarsHandler();
        final Collection<BwCalendar> bwch = ci.getChildren(bwCol);
        final Collection<CalDAVCollection> ch = new ArrayList<>();
        if (bwch == null) {
            return ch;
        }
        for (final BwCalendar c : bwch) {
            if (bedeworkExtensionsEnabled() || !c.getName().startsWith(".")) {
                ci.resolveAlias(c, true, false);
                ch.add(new BwCalDAVCollection(this, c));
            }
            if (isUserHome && !c.getAlias()) {
                provisionedTypes.remove(new Integer(c.getCalType()));
            }
        }
        if (isUserHome && !provisionedTypes.isEmpty()) {
            // Need to add some
            for (final int colType : provisionedTypes) {
                final BwCalendar pcol = ci.getSpecial(currentPrincipal, colType, true, PrivilegeDefs.privAny);
                ch.add(new BwCalDAVCollection(this, pcol));
            }
        }
        return ch;
    } catch (final CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) CalendarsI(org.bedework.calsvci.CalendarsI) CalDAVCollection(org.bedework.caldav.server.CalDAVCollection) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException)

Example 12 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getCollection.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#getCollection(java.lang.String)
   */
@Override
public CalDAVCollection getCollection(final String path) throws WebdavException {
    try {
        BwCalendar col = getSvci().getCalendarsHandler().get(path);
        if (col == null) {
            return null;
        }
        getSvci().getCalendarsHandler().resolveAlias(col, true, false);
        return new BwCalDAVCollection(this, col);
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 13 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getPrincipals.

@Override
public Collection<CalPrincipalInfo> getPrincipals(String resourceUri, final PrincipalPropertySearch pps) throws WebdavException {
    List<CalPrincipalInfo> principals = null;
    if (pps.applyToPrincipalCollectionSet) {
        /* I believe it's valid (if unhelpful) to return nothing
       */
        return new ArrayList<>();
    }
    if (!resourceUri.endsWith("/")) {
        resourceUri += "/";
    }
    try {
        String proot = BwPrincipal.principalRoot;
        if (!proot.endsWith("/")) {
            proot += "/";
        }
        if (!resourceUri.equals(proot)) {
            return new ArrayList<>();
        }
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
    /* If we don't support any of the properties in the searches we don't match.
     *
     * Currently we only support calendarUserAddressSet or calendarHomeSet.
     *
     * For calendarUserAddressSet the value to match must be a valid CUA
     *
     * For calendarHomeSet it must be a valid home uri
     */
    final List<WebdavProperty> props = new ArrayList<>();
    String cutype = null;
    for (final WebdavProperty prop : pps.props) {
        if (debug) {
            debug("Try to match " + prop);
        }
        final String pval = prop.getPval();
        if (CaldavTags.calendarUserAddressSet.equals(prop.getTag())) {
            principals = and(principals, getCalPrincipalInfo(caladdrToPrincipal(pval)));
        } else if (CaldavTags.calendarHomeSet.equals(prop.getTag())) {
            final String path = getUrlHandler().unprefix(pval);
            final CalDAVCollection col = getCollection(path);
            if (col != null) {
                principals = and(principals, getCalPrincipalInfo(col.getOwner()));
            }
        } else if (CaldavTags.calendarUserType.equals(prop.getTag())) {
            cutype = pval;
        } else if (WebdavTags.displayname.equals(prop.getTag())) {
            // Store for directory search
            props.add(prop);
        }
    }
    try {
        if (props.size() != 0) {
            // Directory search
            final Holder<Boolean> truncated = new Holder<>();
            if (principals == null) {
                principals = new ArrayList<>();
            }
            final List<BwPrincipalInfo> pis = getSvci().getDirectories().find(props, pps.pr.props, cutype, truncated);
            if (pis != null) {
                for (final BwPrincipalInfo pi : pis) {
                    principals.add(getCalPrincipalInfo(pi));
                }
            }
        }
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
    if (principals == null) {
        return new ArrayList<>();
    }
    return principals;
}
Also used : Holder(javax.xml.ws.Holder) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalDAVCollection(org.bedework.caldav.server.CalDAVCollection) WebdavProperty(org.bedework.webdav.servlet.shared.WebdavProperty) CalPrincipalInfo(org.bedework.caldav.server.sysinterface.CalPrincipalInfo) BwPrincipalInfo(org.bedework.calfacade.BwPrincipalInfo)

Example 14 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method doNoteHeader.

/* ====================================================================
   *                         Private methods
   * ==================================================================== */
private String doNoteHeader(final String hdr, final String account) throws WebdavException {
    if (hdr == null) {
        return account;
    }
    try {
        final String[] hparts = hdr.split(":");
        if (hparts.length != 2) {
            throw new WebdavBadRequest();
        }
        final String id = hparts[0];
        final NotificationProperties nprops = configs.getNotificationProps();
        final String token = hparts[1];
        if (id == null) {
            throw new WebdavBadRequest();
        }
        if (!id.equals(nprops.getNotifierId()) || (token == null) || !token.equals(nprops.getNotifierToken())) {
            throw new WebdavBadRequest();
        }
        if (account != null) {
            return account;
        }
        return id;
    } catch (final WebdavException wde) {
        throw wde;
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) NotificationProperties(org.bedework.calfacade.configs.NotificationProperties) WebdavException(org.bedework.webdav.servlet.shared.WebdavException)

Example 15 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method requestFreeBusy.

@Override
public Collection<SchedRecipientResult> requestFreeBusy(final CalDAVEvent val, final boolean iSchedule) throws WebdavException {
    try {
        ScheduleResult sr;
        BwEvent ev = getEvent(val);
        if (currentPrincipal != null) {
            ev.setOwnerHref(currentPrincipal.getPrincipalRef());
        }
        if (Icalendar.itipReplyMethodType(ev.getScheduleMethod())) {
            sr = getSvci().getScheduler().scheduleResponse(getEvinfo(val));
        } else {
            sr = getSvci().getScheduler().schedule(getEvinfo(val), null, null, iSchedule);
        }
        return checkStatus(sr);
    } catch (CalFacadeAccessException cfae) {
        if (debug) {
            error(cfae);
        }
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Duplicate-guid");
        }
        throw new WebdavException(cfe);
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) ScheduleResult(org.bedework.calfacade.ScheduleResult) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

WebdavException (org.bedework.webdav.servlet.shared.WebdavException)55 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)32 BwEvent (org.bedework.calfacade.BwEvent)20 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)20 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)13 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)11 BwCalendar (org.bedework.calfacade.BwCalendar)10 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)10 ArrayList (java.util.ArrayList)9 EventInfo (org.bedework.calfacade.svc.EventInfo)9 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)8 BwDateTime (org.bedework.calfacade.BwDateTime)7 BwString (org.bedework.calfacade.BwString)6 DateDatetimePropertyType (ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType)4 TextPropertyType (ietf.params.xml.ns.icalendar_2.TextPropertyType)3 Holder (javax.xml.ws.Holder)3 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)3 SysiIcalendar (org.bedework.caldav.server.SysiIcalendar)3 CalPrincipalInfo (org.bedework.caldav.server.sysinterface.CalPrincipalInfo)3 BwCategory (org.bedework.calfacade.BwCategory)3