Search in sources :

Example 56 with CalFacadeException

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

the class ResourcesImpl method save.

private boolean save(final String path, final BwResource val, final boolean forNotification, final boolean returnIfExists) throws CalFacadeException {
    try {
        final BwCalendar coll = getCols().get(path);
        if (coll == null) {
            throw new CalFacadeException(CalFacadeException.collectionNotFound, path);
        }
        if (forNotification) {
            // We allow this for subscription only
            if (coll.getCalType() != BwCalendar.calTypeNotifications) {
                throw new CalFacadeException(CalFacadeException.badRequest, path);
            }
        } else if (getPrincipalInfo().getSubscriptionsOnly()) {
            throw new CalFacadeForbidden("User has read only access");
        }
        final BwResource r = getCal().getResource(val.getName(), coll, PrivilegeDefs.privAny);
        if (r != null) {
            if (returnIfExists) {
                return false;
            }
            throw new CalFacadeException(CalFacadeException.duplicateResource, val.getName());
        }
        final BwResourceContent rc = val.getContent();
        if (rc == null) {
            throw new CalFacadeException(CalFacadeException.missingResourceContent);
        }
        setupSharableEntity(val, getPrincipal().getPrincipalRef());
        val.setColPath(path);
        if ((coll.getCalType() == BwCalendar.calTypeCalendarCollection) || (coll.getCalType() == BwCalendar.calTypeExtSub)) {
            throw new CalFacadeException(CalFacadeException.badRequest, path);
        }
        checkAccess(coll, PrivilegeDefs.privBind, false);
        val.updateLastmod(getCurrentTimestamp());
        getCal().add(val);
        rc.setColPath(val.getColPath());
        rc.setName(val.getName());
        getCal().add(rc);
        touchCalendar(coll);
        return true;
    } catch (final CalFacadeException cfe) {
        getSvc().rollbackTransaction();
        throw cfe;
    }
}
Also used : BwResource(org.bedework.calfacade.BwResource) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwResourceContent(org.bedework.calfacade.BwResourceContent) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 57 with CalFacadeException

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

the class RestoreImpl method restoreEvent.

@Override
public void restoreEvent(final EventInfo ei) throws Throwable {
    try {
        startTransaction();
        final UpdateEventResult uer = getCal().addEvent(ei, // scheduling
        false, false);
        if (!uer.addedUpdated) {
            throw new CalFacadeException(uer.errorCode);
        }
        if (uer.failedOverrides != null) {
            error("Following overrides failed for event ");
            error(ei.getEvent().toString());
            for (final BwEventProxy proxy : uer.failedOverrides) {
                error(proxy.toString());
            }
        }
    } finally {
        endTransaction();
    }
}
Also used : BwEventProxy(org.bedework.calfacade.BwEventProxy) UpdateEventResult(org.bedework.calcorei.CoreEventsI.UpdateEventResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 58 with CalFacadeException

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

the class RestoreImpl method fixSharee.

@Override
public FixAliasResult fixSharee(final BwCalendar col, final String shareeHref, final AccessType a) throws CalFacadeException {
    /* First ensure this alias is not circular */
    final Set<String> paths = new TreeSet<>();
    BwCalendar curCol = col;
    while (curCol.getInternalAlias()) {
        if (paths.contains(curCol.getPath())) {
            return FixAliasResult.circular;
        }
        paths.add(curCol.getPath());
        try {
            curCol = getCols().resolveAliasIdx(curCol, false, false);
        } catch (final CalFacadeAccessException ignored) {
            // but we can still check for circularity and broken aliases.
            break;
        }
        if (curCol == null) {
            return FixAliasResult.broken;
        }
    }
    // See if we are in the invite list
    final InviteType invite = getSvc().getSharingHandler().getInviteStatus(col);
    final String shareeCua = getSvc().getDirectories().userToCaladdr(shareeHref);
    UserType uentry = invite.finduser(shareeCua);
    if (uentry != null) {
        // Already in list of sharers
        return FixAliasResult.ok;
    }
    /* Now fix the sharing invite info */
    uentry = new UserType();
    uentry.setHref(shareeCua);
    uentry.setInviteStatus(AppleServerTags.inviteAccepted);
    // uentry.setCommonName(...);
    uentry.setAccess(a);
    // uentry.setSummary(s.getSummary());
    invite.getUsers().add(uentry);
    try {
        col.setQproperty(AppleServerTags.invite, invite.toXml());
        getCols().update(col);
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    return FixAliasResult.reshared;
}
Also used : TreeSet(java.util.TreeSet) InviteType(org.bedework.caldav.util.sharing.InviteType) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) UserType(org.bedework.caldav.util.sharing.UserType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 59 with CalFacadeException

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

the class Sharing method unpublish.

@Override
public void unpublish(final BwCalendar col) throws CalFacadeException {
    if (col.getPublick() || (col.getQproperty(AppleServerTags.publishUrl) == null)) {
        throw new CalFacadeForbidden("Not published");
    }
    /* Remove access to all */
    final Acl acl = removeAccess(col.getCurrentAccess().getAcl(), null, WhoDefs.whoTypeAll);
    // Mark the collection as published
    col.removeQproperty(AppleServerTags.publishUrl);
    try {
        getCols().update(col);
        if (acl != null) {
            getSvc().changeAccess(col, acl.getAces(), true);
        }
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) Acl(org.bedework.access.Acl) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 60 with CalFacadeException

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

the class Sharing method setAccess.

private void setAccess(final BwCalendar col, final AddPrincipal ap) throws CalFacadeException {
    try {
        final String whoHref;
        final int whoKind;
        if (ap.pr != null) {
            whoHref = ap.pr.getPrincipalRef();
            whoKind = ap.pr.getKind();
        } else {
            // Read to all
            whoHref = null;
            whoKind = WhoDefs.whoTypeAll;
        }
        Acl acl = col.getCurrentAccess().getAcl();
        final AceWho who = AceWho.getAceWho(whoHref, whoKind, false);
        final Collection<Privilege> desiredPriv;
        if (ap.forRead) {
            desiredPriv = readPrivs;
        } else {
            desiredPriv = readWritePrivs;
        }
        /*
      boolean removeCurrentPrivs = false;

      for (Ace a: ainfo.acl.getAces()) {
        if (a.getWho().equals(who)) {
          if (a.getHow().equals(desiredPriv)) {
            // Already have that access
            return null;
          }

          removeCurrentPrivs = true;
        }
      }

      if (removeCurrentPrivs) {
        ainfo.acl = ainfo.acl.removeWho(who);
      }
      */
        Acl removed = acl.removeWho(who);
        if (removed != null) {
            acl = removed;
        }
        final BwPrincipal owner = getUsers().getPrincipal(col.getOwnerHref());
        final AceWho ownerWho = AceWho.getAceWho(owner.getAccount(), owner.getKind(), false);
        removed = acl.removeWho(ownerWho);
        if (removed != null) {
            acl = removed;
        }
        final Collection<Ace> aces = new ArrayList<>();
        aces.addAll(acl.getAces());
        aces.add(Ace.makeAce(who, desiredPriv, null));
        aces.add(Ace.makeAce(ownerWho, allPrivs, null));
        getSvc().changeAccess(col, aces, true);
        if (!col.getInternalAlias()) {
            return;
        }
        final BwCalendar target = getSvc().getCalendarsHandler().resolveAlias(col, false, false);
        if (target != null) {
            /* Switch identity to the sharee then reget the handler
         * and do the share
         */
            pushPrincipal(target.getOwnerHref());
            try {
                setAccess(target, ap);
            } catch (final CalFacadeException cfe) {
                throw cfe;
            } catch (final Throwable t) {
                throw new CalFacadeException(t);
            } finally {
                popPrincipal();
            }
        }
    } catch (final AccessException ae) {
        throw new CalFacadeException(ae);
    }
}
Also used : Ace(org.bedework.access.Ace) ArrayList(java.util.ArrayList) Acl(org.bedework.access.Acl) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) AccessException(org.bedework.access.AccessException) AceWho(org.bedework.access.AceWho) Privilege(org.bedework.access.Privilege)

Aggregations

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)298 BwCalendar (org.bedework.calfacade.BwCalendar)55 BwEvent (org.bedework.calfacade.BwEvent)55 EventInfo (org.bedework.calfacade.svc.EventInfo)37 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)32 ArrayList (java.util.ArrayList)28 BwString (org.bedework.calfacade.BwString)26 BwDateTime (org.bedework.calfacade.BwDateTime)24 IndexException (org.bedework.util.indexing.IndexException)23 BwPrincipal (org.bedework.calfacade.BwPrincipal)22 TreeSet (java.util.TreeSet)19 BwAttendee (org.bedework.calfacade.BwAttendee)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)16 Calendar (net.fortuna.ical4j.model.Calendar)15 DateTime (net.fortuna.ical4j.model.DateTime)15 Period (net.fortuna.ical4j.model.Period)13 BwCategory (org.bedework.calfacade.BwCategory)13 StringReader (java.io.StringReader)12 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)12 BwEventProxy (org.bedework.calfacade.BwEventProxy)12