use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class IcalTranslator method addToCalendar.
/* ====================================================================
Private methods
==================================================================== */
private void addToCalendar(final Calendar cal, final EventInfo val, final TreeSet<String> added) throws CalFacadeException {
String currentPrincipal = null;
BwPrincipal principal = cb.getPrincipal();
if (principal != null) {
currentPrincipal = principal.getPrincipalRef();
}
BwEvent ev = val.getEvent();
EventTimeZonesRegistry tzreg = new EventTimeZonesRegistry(this, ev);
if (!cb.getTimezonesByReference()) {
/* Add referenced timezones to the calendar */
addIcalTimezones(cal, ev, added, tzreg);
}
if (!ev.getSuppressed()) {
/* Add it to the calendar */
Component comp;
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
comp = VFreeUtil.toVFreeBusy(ev);
} else {
comp = VEventUtil.toIcalComponent(val, false, tzreg, currentPrincipal);
}
cal.getComponents().add((CalendarComponent) comp);
}
if (val.getNumOverrides() > 0) {
for (final EventInfo oei : val.getOverrides()) {
cal.getComponents().add((CalendarComponent) VEventUtil.toIcalComponent(oei, true, tzreg, currentPrincipal));
}
}
}
use of org.bedework.calfacade.BwPrincipal 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);
}
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class Sharing method unsubscribe.
@Override
public void unsubscribe(final BwCalendar col) throws CalFacadeException {
if (!col.getInternalAlias()) {
return;
}
final BwCalendar shared = getCols().resolveAlias(col, true, false);
if (shared == null) {
// Gone or no access - nothing to do now.
return;
}
final String sharerHref = shared.getOwnerHref();
final BwPrincipal sharee = getSvc().getPrincipal();
pushPrincipal(sharerHref);
try {
/* Get the invite property and locate and update this sharee */
final InviteType invite = getInviteStatus(shared);
UserType uentry = null;
final String invitee = principalToCaladdr(sharee);
if (invite != null) {
uentry = invite.finduser(invitee);
}
if (uentry == null) {
if (debug) {
trace("Cannot find invitee: " + invitee);
}
return;
}
uentry.setInviteStatus(AppleServerTags.inviteDeclined);
shared.setProperty(NamespaceAbbrevs.prefixed(AppleServerTags.invite), invite.toXml());
getCols().update(shared);
/* At this stage we need a message to notify the sharer -
change notification.
The name of the alias is the uid of the original invite
*/
final NotificationType note = new NotificationType();
note.setDtstamp(new DtStamp(new DateTime(true)).getValue());
// Create a reply object.
final InviteReplyType reply = new InviteReplyType();
reply.setHref(principalToCaladdr(sharee));
reply.setAccepted(false);
reply.setHostUrl(shared.getPath());
reply.setInReplyTo(col.getName());
reply.setSummary(col.getSummary());
note.setNotification(reply);
getSvc().getNotificationsHandler().add(note);
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
} finally {
popPrincipal();
}
/*
final BwPrincipal pr = caladdrToPrincipal(getPrincipalHref());
if (pr != null) {
pushPrincipal(shared.getOwnerHref());
NotificationType n = null;
try {
n = findInvite(pr, shared.getPath());
} finally {
popPrincipal();
}
if (n != null) {
InviteNotificationType in = (InviteNotificationType)n.getNotification();
Holder<AccessType> access = new Holder<AccessType>();
// Create a dummy reply object.
InviteReplyType reply = new InviteReplyType();
reply.setHref(getPrincipalHref());
reply.setAccepted(false);
reply.setHostUrl(shared.getPath());
reply.setInReplyTo(in.getUid());
updateSharingStatus(shared.getOwnerHref(), shared.getPath(), reply, access);
}
}
*/
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class Sharing method removeAccess.
private boolean removeAccess(final BwCalendar col, final String principalHref) throws CalFacadeException {
Acl acl = col.getCurrentAccess().getAcl();
try {
if (Util.isEmpty(acl.getAces())) {
return false;
}
final BwPrincipal pr = caladdrToPrincipal(principalHref);
acl = removeAccess(acl, pr.getAccount(), pr.getKind());
if (acl == null) {
// no change
return false;
}
getSvc().changeAccess(col, acl.getAces(), true);
if (!col.getInternalAlias()) {
return true;
}
final BwCalendar target = getSvc().getCalendarsHandler().resolveAlias(col, false, false);
if (target == null) {
return false;
}
/* Switch identity to the sharee then reget the handler
* and do the share
*/
pushPrincipal(target.getOwnerHref());
try {
return removeAccess(target, principalHref);
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
} finally {
popPrincipal();
}
} catch (final AccessException ae) {
throw new CalFacadeException(ae);
}
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class Users method createUser.
void createUser(final String val) throws CalFacadeException {
final BwPrincipal user = initUserObject(val);
setRoots(getSvc());
getCal().saveOrUpdate(user);
getSvc().initPrincipal(user);
initPrincipal(user, getSvc());
for (final CollectionInfo ci : BwCalendar.getAllCollectionInfo()) {
if (!ci.provision) {
continue;
}
getCal().getSpecialCalendar(user, ci.collectionType, true, PrivilegeDefs.privAny);
}
getSvc().postNotification(SysEvent.makePrincipalEvent(SysEvent.SysCode.NEW_USER, user, 0));
}
Aggregations