Search in sources :

Example 1 with BwShareableContainedDbentity

use of org.bedework.calfacade.base.BwShareableContainedDbentity in project bw-calendar-engine by Bedework.

the class AccessUtil method getAclChars.

/* ====================================================================
   *                   Private methods
   * ==================================================================== */
/* If the entity is not a collection we merge the access in with the container
   * access then return the merged aces. We do this because we call getPathInfo
   * with a collection entity. That method will recurse up to the root.
   *
   * For a calendar we just use the access for the calendar.
   *
   * The calendar/container access might be cached in the pathInfoTable.
   */
private char[] getAclChars(final BwShareableDbentity<?> ent) throws CalFacadeException {
    if ((!(ent instanceof BwEventProperty)) && (ent instanceof BwShareableContainedDbentity)) {
        BwCalendar container;
        if (ent instanceof BwCalendar) {
            container = (BwCalendar) ent;
        } else {
            container = getParent((BwShareableContainedDbentity<?>) ent);
        }
        if (container == null) {
            return null;
        }
        final String path = container.getPath();
        CalendarWrapper wcol = (CalendarWrapper) container;
        String aclStr;
        char[] aclChars = null;
        /* Get access for the parent first if we have one */
        BwCalendar parent = getParent(wcol);
        if (parent != null) {
            aclStr = new String(merged(getAclChars(parent), parent.getPath(), wcol.getAccess()));
        } else if (wcol.getAccess() != null) {
            aclStr = wcol.getAccess();
        } else {
            // At root
            throw new CalFacadeException("Collections must have default access set at root");
        }
        if (aclStr != null) {
            aclChars = aclStr.toCharArray();
        }
        if (ent instanceof BwCalendar) {
            return aclChars;
        }
        return merged(aclChars, path, ent.getAccess());
    }
    /* This is a way of making other objects sort of shareable.
     * The objects are locations, sponsors and categories.
     * (also calsuite)
     *
     * We store the default access in the owner principal and manipulate that to give
     * us some degree of sharing.
     *
     * In effect, the owner becomes the container for the object.
     */
    String aclString = null;
    String entAccess = ent.getAccess();
    BwPrincipal owner = (BwPrincipal) cb.getPrincipal(ent.getOwnerHref());
    if (ent instanceof BwCategory) {
        aclString = owner.getCategoryAccess();
    } else if (ent instanceof BwLocation) {
        aclString = owner.getLocationAccess();
    } else if (ent instanceof BwContact) {
        aclString = owner.getContactAccess();
    }
    if (aclString == null) {
        if (entAccess == null) {
            if (ent.getPublick()) {
                return Access.getDefaultPublicAccess().toCharArray();
            }
            return Access.getDefaultPersonalAccess().toCharArray();
        }
        return entAccess.toCharArray();
    }
    if (entAccess == null) {
        return aclString.toCharArray();
    }
    try {
        Acl acl = Acl.decode(entAccess.toCharArray());
        acl = acl.merge(aclString.toCharArray(), "/owner");
        return acl.getEncoded();
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) BwShareableContainedDbentity(org.bedework.calfacade.base.BwShareableContainedDbentity) BwCategory(org.bedework.calfacade.BwCategory) BwEventProperty(org.bedework.calfacade.BwEventProperty) BwCalendar(org.bedework.calfacade.BwCalendar) BwContact(org.bedework.calfacade.BwContact) Acl(org.bedework.access.Acl) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) CalendarWrapper(org.bedework.calfacade.wrappers.CalendarWrapper)

Example 2 with BwShareableContainedDbentity

use of org.bedework.calfacade.base.BwShareableContainedDbentity in project bw-calendar-engine by Bedework.

the class ContainerPathRule method field.

public void field(String name) throws Throwable {
    if (name.equals("path")) {
        /* If the top is an override skip this - container is set already. */
        BwEventAnnotation ann = null;
        BwEvent e = null;
        if (top() instanceof EventInfo) {
            EventInfo ei = (EventInfo) getTop(EventInfo.class, name);
            e = ei.getEvent();
            if (e instanceof BwEventProxy) {
                ann = ((BwEventProxy) e).getRef();
                if (ann.getOverride()) {
                    // Overrides have everything set already
                    return;
                }
            }
        }
        BwCalendar cal = globals.rintf.getCalendar(stringFld());
        if (cal == null) {
            error("No calendar for path " + stringFld());
        }
        if (top() instanceof BwShareableContainedDbentity) {
            BwShareableContainedDbentity scde = (BwShareableContainedDbentity) top();
            scde.setColPath(stringFld());
        } else if (top() instanceof EventInfo) {
            if (ann != null) {
                /* Could be target or master */
                String match = getDigester().getMatch();
                if (match.contains("/target/")) {
                    ann.getTarget().setColPath(stringFld());
                } else if (match.contains("/master/")) {
                    ann.getMaster().setColPath(stringFld());
                } else {
                    ann.setColPath(stringFld());
                }
            }
            e.setColPath(stringFld());
        } else {
            handleException(new Exception("Unexpected stack top "));
        }
    } else {
        unknownTag(name);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwShareableContainedDbentity(org.bedework.calfacade.base.BwShareableContainedDbentity) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Aggregations

BwCalendar (org.bedework.calfacade.BwCalendar)2 BwShareableContainedDbentity (org.bedework.calfacade.base.BwShareableContainedDbentity)2 Acl (org.bedework.access.Acl)1 BwCategory (org.bedework.calfacade.BwCategory)1 BwContact (org.bedework.calfacade.BwContact)1 BwEvent (org.bedework.calfacade.BwEvent)1 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)1 BwEventProperty (org.bedework.calfacade.BwEventProperty)1 BwEventProxy (org.bedework.calfacade.BwEventProxy)1 BwLocation (org.bedework.calfacade.BwLocation)1 BwPrincipal (org.bedework.calfacade.BwPrincipal)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 EventInfo (org.bedework.calfacade.svc.EventInfo)1 CalendarWrapper (org.bedework.calfacade.wrappers.CalendarWrapper)1