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());
}
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);
}
}
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();
}
}
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;
}
Aggregations