Search in sources :

Example 26 with WebdavException

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

the class BwCalDAVResource method setBinaryContent.

@Override
public void setBinaryContent(final InputStream val) throws WebdavException {
    BwResource r = getRsrc();
    BwResourceContent rc = r.getContent();
    if (rc == null) {
        if (!isNew()) {
            intf.getFileContent(this);
            rc = r.getContent();
        }
        if (rc == null) {
            rc = new BwResourceContent();
            r.setContent(rc);
        }
    }
    try {
        /* If this is a notification we need to unprefix the data */
        final InputStream str;
        if (!isNotification()) {
            str = val;
        } else {
            final NotificationType note = Parser.fromXml(val);
            note.getNotification().unprefixHrefs(intf.getUrlHandler());
            str = new ByteArrayInputStream(note.toXml(true).getBytes());
        }
        final ByteArrayOutputStream outBuff = new ByteArrayOutputStream();
        byte[] inBuffer = new byte[1000];
        long clen = 0;
        int chunkSize;
        int maxSize = intf.getAuthProperties().getMaxUserEntitySize();
        long oldSize = r.getContentLength();
        while (clen <= maxSize) {
            chunkSize = str.read(inBuffer);
            if (chunkSize < 0) {
                break;
            }
            outBuff.write(inBuffer, 0, chunkSize);
            clen += chunkSize;
        }
        if (clen > maxSize) {
            throw new WebdavForbidden(CaldavTags.maxResourceSize);
        }
        rc.setValue(intf.getBlob(outBuff.toByteArray()));
        r.setContentLength(clen);
        if (!intf.updateQuota(getOwner(), clen - oldSize)) {
            throw new WebdavForbidden(WebdavTags.quotaNotExceeded);
        }
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BwResource(org.bedework.calfacade.BwResource) NotificationType(org.bedework.caldav.util.notifications.NotificationType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwResourceContent(org.bedework.calfacade.BwResourceContent) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 27 with WebdavException

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

the class BwSysIntfImpl method deleteFile.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#deleteFile(org.bedework.caldav.server.CalDAVResource)
   */
@Override
public void deleteFile(final CalDAVResource val) throws WebdavException {
    try {
        updateQuota(val.getOwner(), -val.getQuotaSize());
        getSvci().getResourcesHandler().delete(Util.buildPath(false, val.getParentPath(), "/", val.getName()));
    } 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) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 28 with WebdavException

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

the class BwSysIntfImpl method tzidFromTzdef.

@Override
public String tzidFromTzdef(final String val) throws WebdavException {
    try {
        // Ensure open
        getSvci();
        StringReader sr = new StringReader(val);
        Icalendar ic = trans.fromIcal(null, sr);
        if ((ic == null) || // No components other than timezones
        (ic.size() != 0) || (ic.getTimeZones().size() != 1)) {
            if (debug) {
                debug("Not single timezone");
            }
            throw new WebdavForbidden(CaldavTags.calendarTimezone, "Not single timezone");
        }
        /* This should be the only timezone ion the Calendar object
       */
        TimeZone tz = ic.getTimeZones().iterator().next().tz;
        return tz.getID();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : TimeZone(net.fortuna.ical4j.model.TimeZone) Icalendar(org.bedework.icalendar.Icalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) StringReader(java.io.StringReader) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 29 with WebdavException

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

the class BwSysIntfImpl method getFiles.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#getFiles(org.bedework.caldav.server.CalDAVCollection)
   */
@Override
public Collection<CalDAVResource> getFiles(final CalDAVCollection coll) throws WebdavException {
    try {
        Collection<BwResource> bwrs = getSvci().getResourcesHandler().getAll(coll.getPath());
        if (bwrs == null) {
            return null;
        }
        Collection<CalDAVResource> rs = new ArrayList<CalDAVResource>();
        for (BwResource r : bwrs) {
            rs.add(new BwCalDAVResource(this, r));
        }
        return rs;
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : CalDAVResource(org.bedework.caldav.server.CalDAVResource) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) BwResource(org.bedework.calfacade.BwResource) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 30 with WebdavException

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

the class BwSysIntfImpl method init.

@Override
public String init(final HttpServletRequest req, final String account, final boolean service, final boolean calWs, final boolean synchWs, final boolean notifyWs, final boolean socketWs, final String opaqueData) throws WebdavException {
    try {
        this.calWs = calWs;
        this.synchWs = synchWs;
        final HttpReqInfo reqi = new HttpReqInfo(req);
        // In case we reinit
        principalInfo = null;
        if (req != null) {
            urlHandler = new UrlHandler(req, !calWs);
        } else {
            urlHandler = new UrlHandler("", null, true);
        }
        // final HttpSession session = req.getSession();
        // final ServletContext sc = session.getServletContext();
        // final String appName = sc.getInitParameter("bwappname");
        // if ((appName == null) || (appName.length() == 0)) {
        // throw new WebdavException("bwappname is not set in web.xml");
        // }
        // Notification service calling?
        final String id;
        final String notePr = reqi.notePr();
        if (notifyWs) {
            id = doNoteHeader(reqi.note(), notePr);
        } else if (socketWs) {
            final String tkn = reqi.socketToken();
            if ((tkn == null) || !tkn.equals(getSystemProperties().getSocketToken())) {
                throw new WebdavForbidden();
            }
            id = reqi.socketPr();
        } else {
            id = account;
        }
        doBedeworkExtensions(reqi.bedeworkExtensions());
        /* Find the mbean and get the config */
        // ObjectName mbeanName = new ObjectName(CalDAVConf.getServiceName(appName));
        // Call to set up ThreadLocal variables
        boolean publicAdmin = false;
        boolean adminCreateEprops = false;
        if (!notifyWs && (opaqueData != null)) {
            final String[] vals = opaqueData.split("\t");
            for (final String val : vals) {
                if (val.startsWith("public-admin=")) {
                    publicAdmin = Boolean.valueOf(val.substring(13));
                    continue;
                }
                if (val.startsWith("adminCreateEprops=")) {
                    adminCreateEprops = Boolean.valueOf(val.substring(18));
                }
            }
        }
        getSvci(id, reqi.runAs(), service, publicAdmin, reqi.clientId(), adminCreateEprops);
        authProperties = svci.getAuthProperties();
        sysProperties = configs.getSystemProperties();
        basicSysProperties = configs.getBasicSystemProperties();
        svci.postNotification(new HttpEvent(SysCode.CALDAV_IN));
        reqInTime = System.currentTimeMillis();
        currentPrincipal = svci.getUsersHandler().getUser(id);
        if (notifyWs && (notePr != null)) {
            final String principalToken = reqi.principalToken();
            if (principalToken == null) {
                throw new WebdavUnauthorized();
            }
            final BwPreferences prefs = svci.getPrefsHandler().get();
            if ((prefs == null) || (prefs.getNotificationToken() == null) || !principalToken.equals(prefs.getNotificationToken())) {
                throw new WebdavUnauthorized();
            }
        }
        return id;
    } catch (final WebdavException we) {
        throw we;
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) UrlHandler(org.bedework.webdav.servlet.shared.UrlHandler) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) WebdavUnauthorized(org.bedework.webdav.servlet.shared.WebdavUnauthorized) HttpEvent(org.bedework.sysevents.events.HttpEvent)

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