Search in sources :

Example 11 with BwPrincipal

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

the class Users method initUserObject.

BwPrincipal initUserObject(final String val) throws CalFacadeException {
    String account = val;
    if (account.endsWith("/")) {
        account = account.substring(0, account.length() - 1);
    }
    if (getSvc().getDirectories().isPrincipal(val)) {
        account = getSvc().getDirectories().accountFromPrincipal(val);
    }
    if (account == null) {
        throw new CalFacadeException("Bad user account " + val);
    }
    setRoots(getSvc());
    final BwPrincipal user = BwPrincipal.makeUserPrincipal();
    user.setAccount(account);
    user.setCategoryAccess(Access.getDefaultPersonalAccess());
    user.setLocationAccess(Access.getDefaultPersonalAccess());
    user.setContactAccess(Access.getDefaultPersonalAccess());
    user.setQuota(getSvc().getAuthProperties().getDefaultUserQuota());
    user.setPrincipalRef(Util.buildPath(colPathEndsWithSlash, userPrincipalRoot, "/", account));
    return user;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 12 with BwPrincipal

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

the class Users method getPrincipal.

@Override
public BwPrincipal getPrincipal(final String val) throws CalFacadeException {
    if (val == null) {
        return null;
    }
    final String href;
    if (val.endsWith("/")) {
        href = val.substring(0, val.length() - 1);
    } else {
        href = val;
    }
    final BwPrincipal p = mappedPrincipal(href);
    if (p != null) {
        return p;
    }
    setRoots(getSvc());
    if (!href.startsWith(principalRoot)) {
        return null;
    }
    if (href.startsWith(userPrincipalRoot)) {
        final BwPrincipal u = getSvc().getPrincipal(href);
        if (u != null) {
            principalMap.put(href, u);
        }
        return u;
    }
    if (href.startsWith(groupPrincipalRoot)) {
        final BwGroup g = getSvc().getDirectories().findGroup(href.substring(groupPrincipalRootLen));
        if (g != null) {
            principalMap.put(href, g);
        }
        return g;
    }
    return null;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwGroup(org.bedework.calfacade.BwGroup)

Example 13 with BwPrincipal

use of org.bedework.calfacade.BwPrincipal 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 14 with BwPrincipal

use of org.bedework.calfacade.BwPrincipal 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 15 with BwPrincipal

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

the class BwSysIntfImpl method getCalPrincipalInfo.

@Override
public CalPrincipalInfo getCalPrincipalInfo(final AccessPrincipal principal) throws WebdavException {
    try {
        if (principal == null) {
            return null;
        }
        final boolean thisPrincipal = principal.equals(getSvci().getPrincipal());
        if (thisPrincipal && (principalInfo != null)) {
            return principalInfo;
        }
        final BwPrincipal p = getSvci().getUsersHandler().getPrincipal(principal.getPrincipalRef());
        if (p == null) {
            return null;
        }
        if (p.getKind() != WhoDefs.whoTypeUser) {
            // XXX Cannot handle this yet
            return null;
        }
        // SCHEDULE - just get home path and get default cal from user prefs.
        final String userHomePath = Util.buildPath(true, getSvci().getPrincipalInfo().getCalendarHomePath(p));
        final String defaultCalendarPath = Util.buildPath(true, userHomePath + basicSysProperties.getUserDefaultCalendar());
        final String inboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserInbox());
        ;
        final String outboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserOutbox());
        final String notificationsPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getDefaultNotificationsName());
        final CalPrincipalInfo pi = new CalPrincipalInfo(p, null, null, userHomePath, defaultCalendarPath, inboxPath, outboxPath, notificationsPath, p.getQuota());
        if (thisPrincipal) {
            principalInfo = pi;
        }
        return pi;
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalPrincipalInfo(org.bedework.caldav.server.sysinterface.CalPrincipalInfo)

Aggregations

BwPrincipal (org.bedework.calfacade.BwPrincipal)59 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)22 BwCalendar (org.bedework.calfacade.BwCalendar)16 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)10 EventInfo (org.bedework.calfacade.svc.EventInfo)9 BwEvent (org.bedework.calfacade.BwEvent)7 ArrayList (java.util.ArrayList)6 BwPreferences (org.bedework.calfacade.svc.BwPreferences)6 Acl (org.bedework.access.Acl)5 BwGroup (org.bedework.calfacade.BwGroup)4 Component (net.fortuna.ical4j.model.Component)3 AccessException (org.bedework.access.AccessException)3 Ace (org.bedework.access.Ace)3 Privilege (org.bedework.access.Privilege)3 BwOrganizer (org.bedework.calfacade.BwOrganizer)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 File (java.io.File)2 Collection (java.util.Collection)2 NamingEnumeration (javax.naming.NamingEnumeration)2 Attribute (javax.naming.directory.Attribute)2