Search in sources :

Example 26 with BwPrincipal

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

the class CardDAVDirImpl method getGroupMembers.

/* Find members for given group
   *
   */
private void getGroupMembers(final DirConfigProperties dirProps, final BwGroup group) throws CalFacadeException {
    LdapConfigProperties props = (LdapConfigProperties) dirProps;
    InitialLdapContext ctx = null;
    try {
        ctx = createLdapInitContext(props);
        BasicAttributes matchAttrs = new BasicAttributes(true);
        matchAttrs.put(props.getGroupIdAttr(), group.getAccount());
        String[] memberAttr = { props.getGroupMemberAttr() };
        ArrayList<String> mbrs = null;
        boolean beenHere = false;
        NamingEnumeration response = ctx.search(props.getGroupContextDn(), matchAttrs, memberAttr);
        while (response.hasMore()) {
            SearchResult sr = (SearchResult) response.next();
            Attributes attrs = sr.getAttributes();
            if (beenHere) {
                throw new CalFacadeException("org.bedework.ldap.groups.multiple.result");
            }
            beenHere = true;
            Attribute membersAttr = attrs.get(props.getGroupMemberAttr());
            mbrs = new ArrayList<String>();
            for (int m = 0; m < membersAttr.size(); m++) {
                mbrs.add(membersAttr.get(m).toString());
            }
        }
        // LDAP We need a way to search recursively for groups.
        /* Search for each user in the group */
        String memberContext = props.getGroupMemberContextDn();
        String memberSearchAttr = props.getGroupMemberSearchAttr();
        String[] idAttr = { props.getGroupMemberUserIdAttr(), props.getGroupMemberGroupIdAttr(), "objectclass" };
        for (String mbr : mbrs) {
            if (memberContext != null) {
                matchAttrs = new BasicAttributes(true);
                matchAttrs.put(memberSearchAttr, mbr);
                response = ctx.search(memberContext, matchAttrs, idAttr);
            } else {
                response = ctx.search(memberContext, null, idAttr);
            }
            if (response.hasMore()) {
                SearchResult sr = (SearchResult) response.next();
                Attributes attrs = sr.getAttributes();
                Attribute ocsAttr = attrs.get("objectclass");
                String userOc = props.getUserObjectClass();
                String groupOc = props.getGroupObjectClass();
                boolean isGroup = false;
                for (int oci = 0; oci < ocsAttr.size(); oci++) {
                    String oc = ocsAttr.get(oci).toString();
                    if (userOc.equals(oc)) {
                        break;
                    }
                    if (groupOc.equals(oc)) {
                        isGroup = true;
                        break;
                    }
                }
                BwPrincipal p = null;
                Attribute attr;
                if (isGroup) {
                    p = BwPrincipal.makeGroupPrincipal();
                    attr = attrs.get(props.getGroupMemberGroupIdAttr());
                } else {
                    p = BwPrincipal.makeUserPrincipal();
                    attr = attrs.get(props.getGroupMemberUserIdAttr());
                }
                if (attr.size() != 1) {
                    throw new CalFacadeException("org.bedework.ldap.groups.multiple.result");
                }
                p.setAccount(attr.get(0).toString());
                p.setPrincipalRef(makePrincipalUri(p.getAccount(), p.getKind()));
                group.addGroupMember(p);
            }
        }
    } catch (Throwable t) {
        if (debug) {
            error(t);
        }
        throw new CalFacadeException(t);
    } finally {
        // Close the context to release the connection
        if (ctx != null) {
            closeContext(ctx);
        }
    }
    for (BwGroup g : group.getGroups()) {
        getGroupMembers(props, g);
    }
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BwGroup(org.bedework.calfacade.BwGroup) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) SearchResult(javax.naming.directory.SearchResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) InitialLdapContext(javax.naming.ldap.InitialLdapContext) LdapConfigProperties(org.bedework.calfacade.configs.LdapConfigProperties)

Example 27 with BwPrincipal

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

the class OrganizerSchedulingHandler method schedule.

@Override
public ScheduleResult schedule(final EventInfo ei, final String recipient, final String fromAttUri, final boolean iSchedule) throws CalFacadeException {
    /* A request (that is we are (re)sending a meeting request) or a publish
     *
     * <p>We handle the following iTIP methods<ul>
     * <li>ADD</li>
     * <li>CANCEL</li>
     * <li>DECLINECOUNTER</li>
     * <li>PUBLISH</li>
     * <li>REQUEST</li>
     * </ul>
     *
     * <p>That is, messages from organizer to attendee(s)
     *
     * <pre>
     * Do the usual checks and init
     * For each recipient
     *    If internal to system, add to their inbox
     *    otherwise add to list of external recipients
     *
     * If any external recipients - leave in outbox with unprocessed status.
     * </pre>
     */
    final ScheduleResult sr = new ScheduleResult();
    final BwEvent ev = ei.getEvent();
    try {
        if (!Icalendar.itipRequestMethodType(ev.getScheduleMethod())) {
            sr.errorCode = CalFacadeException.schedulingBadMethod;
            return sr;
        }
        /* For each recipient within this system add the event to their inbox.
       *
       * If there are any external users add it to the outbox and it will be
       * mailed to the recipients.
       */
        final int outAccess;
        final boolean freeBusyRequest = ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy;
        if (freeBusyRequest) {
            // freebusy
            outAccess = PrivilegeDefs.privScheduleFreeBusy;
        } else {
            outAccess = PrivilegeDefs.privScheduleRequest;
        }
        if (!initScheduleEvent(ei, false, iSchedule)) {
            return sr;
        }
        /* Do this here to check we have access. We might need the outbox later
       */
        BwCalendar outBox = null;
        final BwPrincipal currentUser = getPrincipal();
        if (!currentUser.getUnauthenticated()) {
            outBox = getSpecialCalendar(getPrincipal(), BwCalendar.calTypeOutbox, true, outAccess);
        }
        sendSchedule(sr, ei, recipient, fromAttUri, true);
        if ((sr.errorCode != null) || sr.ignored) {
            return sr;
        }
        // if (freeBusyRequest && !imipFreeBusyOk) {
        if (freeBusyRequest) {
            // Don't ever email freebusy requests
            return sr;
        }
        if (!iSchedule && // We have something to mail
        (outBox != null) && (!Util.isEmpty(sr.externalRcs))) {
            sr.errorCode = addToOutBox(ei, outBox, sr.externalRcs);
        }
        return sr;
    } catch (final Throwable t) {
        getSvc().rollbackTransaction();
        if (t instanceof CalFacadeException) {
            throw (CalFacadeException) t;
        }
        throw new CalFacadeException(t);
    }
}
Also used : ScheduleResult(org.bedework.calfacade.ScheduleResult) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 28 with BwPrincipal

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

the class SchedulingBase method findUserAttendee.

/**
 * Find the attendee in this event which corresponds to the current user
 *
 * @param ev
 * @return attendee or null.
 * @throws CalFacadeException
 */
protected BwAttendee findUserAttendee(final BwEvent ev) throws CalFacadeException {
    Directories dir = getSvc().getDirectories();
    String thisPref = getPrincipal().getPrincipalRef();
    for (BwAttendee att : ev.getAttendees()) {
        BwPrincipal p = dir.caladdrToPrincipal(att.getAttendeeUri());
        if (p == null) {
            continue;
        }
        if (thisPref.equals(p.getPrincipalRef())) {
            return att;
        }
    }
    return null;
}
Also used : Directories(org.bedework.calfacade.ifs.Directories) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwAttendee(org.bedework.calfacade.BwAttendee)

Example 29 with BwPrincipal

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

the class CmdUtilHelper method newMember.

public BwPrincipal newMember(final String account, final boolean user) throws Throwable {
    if (user) {
        BwPrincipal p = getSvci().getUsersHandler().getUser(account);
        if (p == null) {
            p = addUser(account);
        }
        /* Ensure the authorised user exists - create an entry if not
       *
       * @param val      BwUser account
       */
        BwAuthUser au = getSvci().getUserAuth().getUser(p.getAccount());
        if ((au != null) && au.isUnauthorized()) {
            pstate.addError("Unauthorised user " + account);
            return null;
        }
        if (au == null) {
            au = BwAuthUser.makeAuthUser(p.getPrincipalRef(), UserAuth.publicEventUser);
            getSvci().getUserAuth().addUser(au);
        }
        return p;
    }
    // group
    final BwPrincipal p = findGroup(account);
    if (p == null) {
        pstate.addError("Unknown group " + account);
    }
    return p;
}
Also used : BwAuthUser(org.bedework.calfacade.svc.BwAuthUser) BwPrincipal(org.bedework.calfacade.BwPrincipal)

Example 30 with BwPrincipal

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

the class BwSysIntfImpl method getFreeBusy.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.sysinterface.SysIntf#getFreeBusy(org.bedework.caldav.server.CalDAVCollection, int, org.bedework.caldav.util.TimeRange)
   */
@Override
public CalDAVEvent getFreeBusy(final CalDAVCollection col, final int depth, final TimeRange timeRange) throws WebdavException {
    try {
        BwCalendar bwCol = unwrap(col);
        int calType = bwCol.getCalType();
        if (!bwCol.getCollectionInfo().allowFreeBusy) {
            throw new WebdavForbidden(WebdavTags.supportedReport);
        }
        Collection<BwCalendar> cals = new ArrayList<BwCalendar>();
        if (calType == BwCalendar.calTypeCalendarCollection) {
            cals.add(bwCol);
        } else if (depth == 0) {
        /* Cannot return anything */
        } else {
            for (BwCalendar ch : getSvci().getCalendarsHandler().getChildren(bwCol)) {
                // For depth 1 we only add calendar collections
                if ((depth > 1) || (ch.getCalType() == BwCalendar.calTypeCalendarCollection)) {
                    cals.add(ch);
                }
            }
        }
        AccessPrincipal owner = col.getOwner();
        String orgUri;
        if (owner instanceof BwPrincipal) {
            orgUri = getSvci().getDirectories().principalToCaladdr((BwPrincipal) owner);
        } else {
            BwPrincipal p = BwPrincipal.makeUserPrincipal();
            p.setAccount(owner.getAccount());
            orgUri = getSvci().getDirectories().principalToCaladdr(p);
        }
        BwOrganizer org = new BwOrganizer();
        org.setOrganizerUri(orgUri);
        BwEvent fb;
        if (cals.isEmpty()) {
            // Return an empty object
            fb = new BwEventObj();
            fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
            fb.setDtstart(getBwDt(timeRange.getStart()));
            fb.setDtend(getBwDt(timeRange.getEnd()));
        } else {
            fb = getSvci().getScheduler().getFreeBusy(cals, (BwPrincipal) currentPrincipal, getBwDt(timeRange.getStart()), getBwDt(timeRange.getEnd()), org, // uid
            null, null);
        }
        EventInfo ei = new EventInfo(fb);
        return new BwCalDAVEvent(this, ei);
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) AccessPrincipal(org.bedework.access.AccessPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

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