Search in sources :

Example 6 with CalFacadeAccessException

use of org.bedework.calfacade.exc.CalFacadeAccessException 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 7 with CalFacadeAccessException

use of org.bedework.calfacade.exc.CalFacadeAccessException 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 8 with CalFacadeAccessException

use of org.bedework.calfacade.exc.CalFacadeAccessException 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)

Example 9 with CalFacadeAccessException

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

the class AccessUtil method checkAccess.

@Override
public CurrentAccess checkAccess(final BwShareableDbentity<?> ent, final int desiredAccess, final boolean alwaysReturnResult) throws CalFacadeException {
    if (ent == null) {
        return null;
    }
    if (ent instanceof CalendarWrapper) {
        final CalendarWrapper col = (CalendarWrapper) ent;
        final CurrentAccess ca = col.getCurrentAccess(desiredAccess);
        if (ca != null) {
            if (debug) {
                debug("Access " + desiredAccess + " already checked for " + cb.getPrincipal().getPrincipalRef() + " and allowed=" + ca.getAccessAllowed());
            }
            if (!ca.getAccessAllowed() && !alwaysReturnResult) {
                throw new CalFacadeAccessException();
            }
            return ca;
        }
    }
    if (debug) {
        final String cname = ent.getClass().getName();
        final String ident;
        if (ent instanceof BwCalendar) {
            ident = ((BwCalendar) ent).getPath();
        } else {
            ident = String.valueOf(ent.getId());
        }
        debug("Check access by " + cb.getPrincipal().getPrincipalRef() + " for object " + cname.substring(cname.lastIndexOf(".") + 1) + " ident=" + ident + " desiredAccess = " + desiredAccess);
    }
    try {
        final long startTime = System.currentTimeMillis();
        CurrentAccess ca = null;
        final AccessPrincipal owner = cb.getPrincipal(ent.getOwnerHref());
        if (debug) {
            debug("After getPrincipal - took: " + (System.currentTimeMillis() - startTime));
        }
        if (owner == null) {
            error("Principal(owner) " + ent.getOwnerHref() + " does not exist");
            if (!alwaysReturnResult) {
                throw new CalFacadeAccessException();
            }
            return new CurrentAccess(false);
        }
        PrivilegeSet maxPrivs = null;
        char[] aclChars = null;
        if (ent instanceof BwCalendar) {
            final BwCalendar cal = (BwCalendar) ent;
            final String path = cal.getPath();
            /* I think this was wrong. For superuser we want to see the real
         * access but they are going to be allowed access whatever.
        if (userRootPath.equals(path)) {
          ca = new CurrentAccess();

          if (getSuperUser()) {
            ca.privileges = PrivilegeSet.makeDefaultOwnerPrivileges();
          } else {
            ca.privileges = PrivilegeSet.makeDefaultNonOwnerPrivileges();
          }
        } else if (path.equals(userHomePathPrefix + account)){
          // Accessing user home directory
          if (getSuperUser()) {
            ca = new CurrentAccess();

            ca.privileges = PrivilegeSet.makeDefaultOwnerPrivileges();
          } else {
            // Set the maximumn access
            maxPrivs = PrivilegeSet.userHomeMaxPrivileges;
          }
        }
         */
            if (!cb.getSuperUser()) {
                if (cb.getUserHomePath().equals(path)) {
                    ca = new CurrentAccess();
                    ca = Acl.defaultNonOwnerAccess;
                } else if (path.equals(Util.buildPath(colPathEndsWithSlash, cb.getUserHomePath(), "/", owner.getAccount()))) {
                    // Accessing user home directory
                    // Set the maximumn access
                    maxPrivs = PrivilegeSet.userHomeMaxPrivileges;
                }
            }
        }
        if (maxPrivs == null) {
            maxPrivs = cb.getMaximumAllowedPrivs();
        } else if (cb.getMaximumAllowedPrivs() != null) {
            maxPrivs = PrivilegeSet.filterPrivileges(maxPrivs, cb.getMaximumAllowedPrivs());
        }
        if (ca == null) {
            /* Not special. getAclChars provides merged access for the current
         * entity.
         */
            aclChars = getAclChars(ent);
            if (aclChars == null) {
                error("Unable to fetch aclchars for " + ent);
                if (!alwaysReturnResult) {
                    throw new CalFacadeAccessException();
                }
                return new CurrentAccess(false);
            }
            if (debug) {
                debug("aclChars = " + new String(aclChars));
            }
            if (desiredAccess == privAny) {
                ca = access.checkAny(cb, cb.getPrincipal(), owner, aclChars, maxPrivs);
            } else if (desiredAccess == privRead) {
                ca = access.checkRead(cb, cb.getPrincipal(), owner, aclChars, maxPrivs);
            } else if (desiredAccess == privWrite) {
                ca = access.checkReadWrite(cb, cb.getPrincipal(), owner, aclChars, maxPrivs);
            } else {
                ca = access.evaluateAccess(cb, cb.getPrincipal(), owner, desiredAccess, aclChars, maxPrivs);
            }
        }
        if ((cb.getPrincipal() != null) && cb.getSuperUser()) {
            /* Override rather than just create a readable access as code further
         * up expects a valid filled in object.
         */
            if (debug && !ca.getAccessAllowed()) {
                debug("Override for superuser");
            }
            ca = Acl.forceAccessAllowed(ca);
        }
        if (ent instanceof CalendarWrapper) {
            final CalendarWrapper col = (CalendarWrapper) ent;
            col.setCurrentAccess(ca, desiredAccess);
        }
        if (debug) {
            debug("access allowed: " + ca.getAccessAllowed());
        }
        if (!ca.getAccessAllowed() && !alwaysReturnResult) {
            throw new CalFacadeAccessException();
        }
        return ca;
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : PrivilegeSet(org.bedework.access.PrivilegeSet) CurrentAccess(org.bedework.access.Acl.CurrentAccess) CalendarWrapper(org.bedework.calfacade.wrappers.CalendarWrapper) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) AccessPrincipal(org.bedework.access.AccessPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 10 with CalFacadeAccessException

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

the class CalintfHelper method getEntityCollection.

protected BwCalendar getEntityCollection(final String path, final int nonSchedAccess, final boolean scheduling, final boolean alwaysReturn) throws CalFacadeException {
    final int desiredAccess;
    if (!scheduling) {
        desiredAccess = nonSchedAccess;
    } else {
        desiredAccess = privAny;
    }
    final BwCalendar cal = getCollection(path, desiredAccess, alwaysReturn | scheduling);
    if (cal == null) {
        return null;
    }
    if (!cal.getCalendarCollection()) {
        throwException(new CalFacadeAccessException());
    }
    if (!scheduling) {
        return cal;
    }
    CurrentAccess ca;
    final AccessUtilI access = ac.getAccessUtil();
    if ((cal.getCalType() == BwCalendar.calTypeInbox) || (cal.getCalType() == BwCalendar.calTypePendingInbox)) {
        ca = access.checkAccess(cal, privScheduleDeliver, true);
        if (!ca.getAccessAllowed()) {
            // try old style
            ca = access.checkAccess(cal, privScheduleRequest, alwaysReturn);
        }
    } else if (cal.getCalType() == BwCalendar.calTypeOutbox) {
        ca = access.checkAccess(cal, privScheduleSend, true);
        if (!ca.getAccessAllowed()) {
            // try old style
            ca = access.checkAccess(cal, privScheduleReply, alwaysReturn);
        }
    } else {
        throw new CalFacadeAccessException();
    }
    if (!ca.getAccessAllowed()) {
        return null;
    }
    return cal;
}
Also used : AccessUtilI(org.bedework.calfacade.util.AccessUtilI) CurrentAccess(org.bedework.access.Acl.CurrentAccess) 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