Search in sources :

Example 11 with CalFacadeForbidden

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

the class Sharing method reply.

@Override
public ReplyResult reply(final BwCalendar col, final InviteReplyType reply) throws CalFacadeException {
    final BwCalendar home = getCols().getHome();
    if (!home.getPath().equals(col.getPath())) {
        throw new CalFacadeForbidden("Not calendar home");
    }
    /* We must have at least read access to the shared collection */
    final BwCalendar sharerCol = getCols().get(Util.buildPath(colPathEndsWithSlash, reply.getHostUrl()));
    if (sharerCol == null) {
        // Bad hosturl
        throw new CalFacadeForbidden("Bad hosturl or no access");
    }
    final Holder<AccessType> access = new Holder<>();
    if (!updateSharingStatus(sharerCol.getOwnerHref(), sharerCol.getPath(), reply, access)) {
        return null;
    }
    /* Accepted */
    final AccessType at = access.value;
    final boolean sharedWritable = (at != null) && at.testReadWrite();
    /* This may be a change in access or a new sharing request. See if an alias
     * already exists to the shared collection. If it does we're done.
     * Otherwise we need to create an alias in the calendar home using the
     * reply summary as the display name */
    final List<BwCalendar> aliases = findAlias(sharerCol.getPath());
    if (!Util.isEmpty(aliases)) {
        final BwCalendar alias = aliases.get(0);
        alias.setSharedWritable(sharedWritable);
        getCols().update(alias);
        return ReplyResult.success(alias.getPath());
    }
    final BwCalendar alias = new BwCalendar();
    String summary = reply.getSummary();
    if ((summary == null) || (summary.length() == 0)) {
        summary = "Shared Calendar";
    }
    alias.setName(reply.getInReplyTo());
    alias.setSummary(summary);
    alias.setCalType(BwCalendar.calTypeAlias);
    // alias.setPath(home.getPath() + "/" + UUID.randomUUID().toString());
    alias.setAliasUri("bwcal://" + sharerCol.getPath());
    alias.setShared(true);
    alias.setSharedWritable(sharedWritable);
    final BwCalendar createdAlias = getCols().add(alias, home.getPath());
    return ReplyResult.success(createdAlias.getPath());
}
Also used : Holder(javax.xml.ws.Holder) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwCalendar(org.bedework.calfacade.BwCalendar) AccessType(org.bedework.caldav.util.sharing.AccessType)

Example 12 with CalFacadeForbidden

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

the class Sharing method publish.

@Override
public void publish(final BwCalendar col) throws CalFacadeException {
    if (!col.getCanAlias()) {
        throw new CalFacadeForbidden("Cannot publish");
    }
    // Mark the collection as shared and published
    col.setQproperty(AppleServerTags.publishUrl, col.getPath());
    try {
        getCols().update(col);
        /* Set access to read for everybody */
        setAccess(col, new AddPrincipal(null, true));
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 13 with CalFacadeForbidden

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

the class Sharing method updateSharingStatus.

/* ====================================================================
   *                   Private methods
   * ==================================================================== */
/* This requires updating the shared calendar to reflect the accept/decline
   * status
   */
private boolean updateSharingStatus(final String sharerHref, final String path, final InviteReplyType reply, final Holder<AccessType> access) throws CalFacadeException {
    pushPrincipal(sharerHref);
    try {
        final BwCalendar col = getCols().get(path);
        if (col == null) {
            // Bad hosturl?
            throw new CalFacadeForbidden(CalFacadeException.shareTargetNotFound);
        }
        /* See if we have an outstanding invite for this user */
        final QName qn = new QName(AppleServerTags.inviteNotification.getNamespaceURI(), AppleServerTags.inviteNotification.getLocalPart() + reply.getInReplyTo());
        final String pname = NamespaceAbbrevs.prefixed(qn);
        final String xmlInvite = col.getProperty(pname);
        if (xmlInvite == null) {
            // No invite
            if (debug) {
                trace("No invite notification on collection with name: " + pname);
            }
            throw new CalFacadeForbidden(CalFacadeException.noInvite);
        }
        /* Remove the invite */
        col.setProperty(pname, null);
        /* Get the invite property and locate and update this sharee */
        final InviteType invite = getInviteStatus(col);
        UserType uentry = null;
        final String invitee = getSvc().getDirectories().normalizeCua(reply.getHref());
        if (invite != null) {
            uentry = invite.finduser(invitee);
        }
        if (uentry == null) {
            if (debug) {
                trace("Cannot find invitee: " + invitee);
            }
            throw new CalFacadeForbidden(CalFacadeException.noInviteeInUsers);
        }
        if (reply.testAccepted()) {
            uentry.setInviteStatus(AppleServerTags.inviteAccepted);
        } else {
            uentry.setInviteStatus(AppleServerTags.inviteDeclined);
        }
        access.value = uentry.getAccess();
        col.setProperty(NamespaceAbbrevs.prefixed(AppleServerTags.invite), invite.toXml());
        getCols().update(col);
        /* Now send the sharer the reply as a notification */
        final NotificationType note = new NotificationType();
        note.setDtstamp(new DtStamp(new DateTime(true)).getValue());
        final InviteReplyType irt = (InviteReplyType) reply.clone();
        note.setNotification(irt);
        /* Fill in the summary (the sharer's summary) on the reply. */
        irt.setSummary(reply.getSummary());
        getSvc().getNotificationsHandler().add(note);
        return irt.testAccepted();
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    } finally {
        popPrincipal();
    }
}
Also used : DtStamp(net.fortuna.ical4j.model.property.DtStamp) QName(javax.xml.namespace.QName) NotificationType(org.bedework.caldav.util.notifications.NotificationType) InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) InviteType(org.bedework.caldav.util.sharing.InviteType) InviteReplyType(org.bedework.caldav.util.sharing.InviteReplyType) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwCalendar(org.bedework.calfacade.BwCalendar) UserType(org.bedework.caldav.util.sharing.UserType) DateTime(net.fortuna.ical4j.model.DateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 14 with CalFacadeForbidden

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

the class InScheduler method processEntityQueuedEvent.

private ProcessMessageResult processEntityQueuedEvent(final EntityQueuedEvent msg) {
    /* These are events that are placed in the inbox.
     */
    EventInfo ei = null;
    try (final CalSvcI svci = getSvci(msg.getOwnerHref())) {
        if (debug) {
            trace("InSchedule inbox entry for principal " + msg.getOwnerHref());
        }
        ei = getInboxEvent(svci, msg.getName());
        if (ei == null) {
            // Event deleted from inbox.
            if (debug) {
                trace("InSchedule event deleted from inbox");
            }
            return ProcessMessageResult.NO_ACTION;
        }
        final BwEvent ev = ei.getEvent();
        final int method = ev.getScheduleMethod();
        if (debug) {
            trace("InSchedule event for " + msg.getOwnerHref() + " " + msg.getName() + " with method " + ScheduleMethods.methods[method] + "\n" + ev);
            if (ev.getSuppressed()) {
                for (final EventInfo oei : ei.getOverrides()) {
                    trace("Override: " + oei.getEvent());
                }
            }
        }
        InProcessor proc = null;
        switch(method) {
            case Icalendar.methodTypeCancel:
                proc = new InCancel(svci);
                break;
            case Icalendar.methodTypeRequest:
            case Icalendar.methodTypePollStatus:
                proc = new InRequest(svci);
                break;
            case Icalendar.methodTypeReply:
                proc = new InReply(svci);
                break;
            case Icalendar.methodTypeRefresh:
                proc = new InRefresh(svci);
                break;
            default:
                warn("InSchedule: unhandled method for " + ev.getOwnerHref() + " " + method);
        }
        if (proc == null) {
            deleteEvent(ei, false, false);
            return ProcessMessageResult.PROCESSED;
        }
        final ProcessResult pr = proc.process(ei);
        if (debug) {
            trace("InSchedule " + pr.sr);
        }
        if (!pr.noInboxChange) {
            proc.pendingToInbox(ei, ev.getOwnerHref(), pr.attendeeAccepting, pr.removeInboxEntry);
        }
        deleteEvent(ei, false, false);
        return ProcessMessageResult.PROCESSED;
    } catch (final CalFacadeForbidden cff) {
        if (debug) {
            trace("Forbidden exception" + cff);
        }
        if (ei != null) {
            try {
                deleteEvent(ei, false, false);
            } catch (final Throwable ignored) {
            }
        }
        return ProcessMessageResult.FAILED_NORETRIES;
    } catch (final CalFacadeStaleStateException csse) {
        if (debug) {
            trace("Stale state exception");
        }
        rollback(getSvc());
        return ProcessMessageResult.STALE_STATE;
    } catch (final Throwable t) {
        rollback(getSvc());
        error(t);
    }
    return ProcessMessageResult.FAILED;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) InRequest(org.bedework.inoutsched.processors.InRequest) InRefresh(org.bedework.inoutsched.processors.InRefresh) ProcessResult(org.bedework.inoutsched.processors.InProcessor.ProcessResult) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwEvent(org.bedework.calfacade.BwEvent) InReply(org.bedework.inoutsched.processors.InReply) CalFacadeStaleStateException(org.bedework.calfacade.exc.CalFacadeStaleStateException) CalSvcI(org.bedework.calsvci.CalSvcI) InProcessor(org.bedework.inoutsched.processors.InProcessor) InCancel(org.bedework.inoutsched.processors.InCancel)

Aggregations

CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)14 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)9 BwCalendar (org.bedework.calfacade.BwCalendar)5 EventInfo (org.bedework.calfacade.svc.EventInfo)4 InviteType (org.bedework.caldav.util.sharing.InviteType)3 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 QName (javax.xml.namespace.QName)2 DateTime (net.fortuna.ical4j.model.DateTime)2 DtStamp (net.fortuna.ical4j.model.property.DtStamp)2 NotificationType (org.bedework.caldav.util.notifications.NotificationType)2 InviteNotificationType (org.bedework.caldav.util.sharing.InviteNotificationType)2 UserType (org.bedework.caldav.util.sharing.UserType)2 BwEvent (org.bedework.calfacade.BwEvent)2 BwPreferences (org.bedework.calfacade.svc.BwPreferences)2 UpdateResult (org.bedework.calfacade.svc.EventInfo.UpdateResult)2 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)2 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1