Search in sources :

Example 6 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.

the class Views method addCollection.

/* (non-Javadoc)
   * @see org.bedework.calsvci.ViewsI#addCollection(java.lang.String, java.lang.String)
   */
@Override
public boolean addCollection(final String name, final String path) throws CalFacadeException {
    BwPreferences prefs = getSvc().getPrefsHandler().get();
    checkOwnerOrSuper(prefs);
    BwView view = find(name);
    if (view == null) {
        return false;
    }
    view.addCollectionPath(path);
    getSvc().getPrefsHandler().update(prefs);
    return true;
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwView(org.bedework.calfacade.svc.BwView)

Example 7 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.

the class Views method find.

@Override
public BwView find(String val) throws CalFacadeException {
    if (val == null) {
        BwPreferences prefs = getSvc().getPrefsHandler().get();
        val = prefs.getPreferredView();
        if (val == null) {
            return null;
        }
    }
    /* val may be a name in which case it's for the current user or it
     * may be a fully qualified path referencing another users views.
     */
    if (!val.startsWith("/")) {
        // This user
        Collection<BwView> views = getAll();
        for (BwView view : views) {
            if (view.getName().equals(val)) {
                return view;
            }
        }
        return null;
    }
    /* Other user - we expect a path of th eform
     *  /user/<id>/<bedework-resource-name>/views/<view-name>
     */
    String[] pathEls = val.split("/");
    BasicSystemProperties bsp = getBasicSyspars();
    if ((pathEls.length != 5) || !bsp.getBedeworkResourceDirectory().equals(pathEls[2]) || !"views".equals(pathEls[3])) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    if (bsp.getUserCalendarRoot().equals(pathEls[0])) {
        sb.append(BwPrincipal.userPrincipalRoot);
    } else {
        return null;
    }
    // user id
    sb.append(pathEls[1]);
    BwPrincipal pr = getPrincipal(sb.toString());
    if (pr == null) {
        return null;
    }
    Collection<BwView> views = getAll(pr);
    String viewName = pathEls[4];
    for (BwView view : views) {
        if (view.getName().equals(viewName)) {
            return view;
        }
    }
    return null;
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwPrincipal(org.bedework.calfacade.BwPrincipal) BasicSystemProperties(org.bedework.calfacade.configs.BasicSystemProperties) BwView(org.bedework.calfacade.svc.BwView)

Example 8 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.

the class Preferences method fetch.

/**
 * Fetch the preferences for the given principal from the db
 *
 * @param principal
 * @return the preferences for the current user
 * @throws CalFacadeException
 */
private BwPreferences fetch(final BwPrincipal principal) throws CalFacadeException {
    BwPreferences prefs = getSvc().getPreferences(principal.getPrincipalRef());
    BwPrincipalInfo pinfo = principal.getPrincipalInfo();
    if (pinfo == null) {
        return prefs;
    }
    if (getSvc().getDirectories().mergePreferences(prefs, pinfo)) {
        update(prefs);
    }
    return prefs;
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwPrincipalInfo(org.bedework.calfacade.BwPrincipalInfo)

Example 9 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method updateQuota.

boolean updateQuota(final AccessPrincipal principal, final long inc) throws WebdavException {
    try {
        BwPrincipal p = getSvci().getUsersHandler().getPrincipal(principal.getPrincipalRef());
        if (p == null) {
            // No quota - fail
            return false;
        }
        if (p.getKind() != WhoDefs.whoTypeUser) {
            // No quota - fail
            return false;
        }
        BwPreferences prefs = getPrefs();
        long used = prefs.getQuotaUsed() + inc;
        prefs.setQuotaUsed(used);
        getSvci().getUsersHandler().update(p);
        return // Decreasing usage - let it pass
        (inc < 0) || (used <= p.getQuota());
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwPreferences(org.bedework.calfacade.svc.BwPreferences) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 10 with BwPreferences

use of org.bedework.calfacade.svc.BwPreferences 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

BwPreferences (org.bedework.calfacade.svc.BwPreferences)28 BwView (org.bedework.calfacade.svc.BwView)7 BwCalendar (org.bedework.calfacade.BwCalendar)6 BwPrincipal (org.bedework.calfacade.BwPrincipal)6 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)5 EventInfo (org.bedework.calfacade.svc.EventInfo)5 BwEvent (org.bedework.calfacade.BwEvent)4 File (java.io.File)2 BwCategory (org.bedework.calfacade.BwCategory)2 UpdateResult (org.bedework.calfacade.svc.EventInfo.UpdateResult)2 SchedulingIntf (org.bedework.calsvc.scheduling.SchedulingIntf)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 TreeSet (java.util.TreeSet)1 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)1 UpdateEventResult (org.bedework.calcorei.CoreEventsI.UpdateEventResult)1 HibSession (org.bedework.calcorei.HibSession)1 BaseNotificationType (org.bedework.caldav.util.notifications.BaseNotificationType)1 NotificationType (org.bedework.caldav.util.notifications.NotificationType)1 ResourceChangeType (org.bedework.caldav.util.notifications.ResourceChangeType)1 UpdatedType (org.bedework.caldav.util.notifications.UpdatedType)1