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