Search in sources :

Example 6 with BwPrincipal

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));
        }
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) StartEndComponent(org.bedework.calfacade.base.StartEndComponent) Component(net.fortuna.ical4j.model.Component)

Example 7 with BwPrincipal

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

Example 8 with BwPrincipal

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);
      }
    }
    */
}
Also used : DtStamp(net.fortuna.ical4j.model.property.DtStamp) BwPrincipal(org.bedework.calfacade.BwPrincipal) 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) 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 9 with BwPrincipal

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);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) AccessException(org.bedework.access.AccessException) Acl(org.bedework.access.Acl) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 10 with BwPrincipal

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));
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal)

Aggregations

BwPrincipal (org.bedework.calfacade.BwPrincipal)59 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)22 BwCalendar (org.bedework.calfacade.BwCalendar)16 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)10 EventInfo (org.bedework.calfacade.svc.EventInfo)9 BwEvent (org.bedework.calfacade.BwEvent)7 ArrayList (java.util.ArrayList)6 BwPreferences (org.bedework.calfacade.svc.BwPreferences)6 Acl (org.bedework.access.Acl)5 BwGroup (org.bedework.calfacade.BwGroup)4 Component (net.fortuna.ical4j.model.Component)3 AccessException (org.bedework.access.AccessException)3 Ace (org.bedework.access.Ace)3 Privilege (org.bedework.access.Privilege)3 BwOrganizer (org.bedework.calfacade.BwOrganizer)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 File (java.io.File)2 Collection (java.util.Collection)2 NamingEnumeration (javax.naming.NamingEnumeration)2 Attribute (javax.naming.directory.Attribute)2