Search in sources :

Example 11 with BwGroup

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

the class GroupsDbImpl method removeMember.

/* (non-Javadoc)
   * @see org.bedework.calfacade.ifs.Groups#removeMember(org.bedework.calfacade.BwGroup, org.bedework.calfacade.BwPrincipal)
   */
@Override
public void removeMember(final BwGroup group, final BwPrincipal val) throws CalFacadeException {
    BwGroup g = findGroup(group.getAccount());
    if (g == null) {
        throw new CalFacadeException("Group " + group + " does not exist");
    }
    g.removeGroupMember(val);
    cb.removeMember(group, val, false);
}
Also used : BwGroup(org.bedework.calfacade.BwGroup) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 12 with BwGroup

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

the class UserGroupsLdapImpl method findGroup.

/* Search for a group to ensure it exists
   *
   */
private BwGroup findGroup(final DirConfigProperties dirProps, final String groupName) throws CalFacadeException {
    LdapConfigProperties props = (LdapConfigProperties) dirProps;
    InitialLdapContext ctx = null;
    try {
        ctx = createLdapInitContext(props);
        BasicAttributes matchAttrs = new BasicAttributes(true);
        matchAttrs.put(props.getGroupIdAttr(), groupName);
        String[] idAttr = { props.getGroupIdAttr() };
        BwGroup group = null;
        NamingEnumeration response = ctx.search(props.getGroupContextDn(), matchAttrs, idAttr);
        while (response.hasMore()) {
            if (group != null) {
                throw new CalFacadeException("org.bedework.ldap.groups.multiple.result");
            }
            group = new BwGroup();
            group.setAccount(groupName);
            group.setPrincipalRef(makePrincipalUri(groupName, WhoDefs.whoTypeGroup));
        }
        return group;
    } catch (Throwable t) {
        if (debug) {
            error(t);
        }
        throw new CalFacadeException(t);
    } finally {
        // Close the context to release the connection
        if (ctx != null) {
            closeContext(ctx);
        }
    }
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BwGroup(org.bedework.calfacade.BwGroup) InitialLdapContext(javax.naming.ldap.InitialLdapContext) NamingEnumeration(javax.naming.NamingEnumeration) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) LdapConfigProperties(org.bedework.calfacade.configs.LdapConfigProperties)

Example 13 with BwGroup

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

the class UserGroupsLdapImpl method getGroups.

/* Return all groups for principal == null or all groups for which principal
   * is a member
   *
   */
private Collection<BwGroup> getGroups(final DirConfigProperties dirProps, final BwPrincipal principal) throws CalFacadeException {
    final ArrayList<BwGroup> groups = new ArrayList<>();
    final LdapConfigProperties props = (LdapConfigProperties) dirProps;
    if (props.getGroupMemberAttr() == null) {
        warn("No group member attribute set - assuming no groups");
        return groups;
    }
    InitialLdapContext ctx = null;
    String member = null;
    if (principal != null) {
        if (principal.getKind() == WhoDefs.whoTypeUser) {
            member = getUserEntryValue(props, principal);
        } else if (principal.getKind() == WhoDefs.whoTypeGroup) {
            member = getGroupEntryValue(props, principal);
        }
    }
    try {
        try {
            ctx = createLdapInitContext(props);
        } catch (final Throwable t) {
            warn("*******************************************");
            warn("No group information available");
            error(t);
            return groups;
        }
        final BasicAttributes matchAttrs = new BasicAttributes(true);
        if (member != null) {
            matchAttrs.put(props.getGroupMemberAttr(), member);
        }
        final String[] idAttr = { props.getGroupIdAttr() };
        final NamingEnumeration response = ctx.search(props.getGroupContextDn(), matchAttrs, idAttr);
        while (response.hasMore()) {
            final SearchResult sr = (SearchResult) response.next();
            final Attributes attrs = sr.getAttributes();
            final Attribute nmAttr = attrs.get(props.getGroupIdAttr());
            if (nmAttr.size() != 1) {
                throw new CalFacadeException("org.bedework.ldap.groups.multiple.result");
            }
            final BwGroup group = new BwGroup();
            group.setAccount(nmAttr.get(0).toString());
            group.setPrincipalRef(makePrincipalUri(group.getAccount(), WhoDefs.whoTypeGroup));
            groups.add(group);
        }
        return groups;
    } catch (final Throwable t) {
        if (debug) {
            error(t);
        }
        throw new CalFacadeException(t);
    } finally {
        // Close the context to release the connection
        if (ctx != null) {
            closeContext(ctx);
        }
    }
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BwGroup(org.bedework.calfacade.BwGroup) Attribute(javax.naming.directory.Attribute) ArrayList(java.util.ArrayList) 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) InitialLdapContext(javax.naming.ldap.InitialLdapContext) LdapConfigProperties(org.bedework.calfacade.configs.LdapConfigProperties)

Example 14 with BwGroup

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

the class MemberRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    /* Top should be the principal info, underneath is the actual entity -
     */
    PrincipalHref oi = (PrincipalHref) pop();
    try {
        if (oi.prefix == null) {
            error("Unable to handle principal type " + oi.getKind());
        }
        oi.href = Util.buildPath(false, oi.prefix, "/", oi.account);
    } catch (Throwable t) {
        error("Unable to get user principal root", t);
        return;
    }
    BwPrincipal pr = globals.principalsTbl.get(oi);
    if (top() instanceof BwGroup) {
        BwGroup gr = (BwGroup) top();
        if (pr == null) {
            if (gr instanceof BwAdminGroup) {
                ArrayList<PrincipalHref> m = globals.adminGroupMembers.get(gr.getAccount());
                if (m == null) {
                    m = new ArrayList<PrincipalHref>();
                    globals.adminGroupMembers.put(gr.getAccount(), m);
                }
                m.add(oi);
            } else {
                error("Cannot handle group " + gr);
            }
            return;
        }
        gr.addGroupMember(pr);
        return;
    }
    error("Unknown class for member " + top());
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwGroup(org.bedework.calfacade.BwGroup) PrincipalHref(org.bedework.dumprestore.restore.PrincipalHref) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Example 15 with BwGroup

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

the class AdminGroupsDbImpl method removeMember.

@Override
public void removeMember(final BwGroup group, final BwPrincipal val) throws CalFacadeException {
    final BwGroup ag = findGroup(group.getAccount());
    if (ag == null) {
        throw new CalFacadeException(CalFacadeException.groupNotFound, group.getAccount());
    }
    ag.removeGroupMember(val);
    cb.removeMember(group, val, true);
}
Also used : BwGroup(org.bedework.calfacade.BwGroup) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwGroup (org.bedework.calfacade.BwGroup)19 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)10 NamingEnumeration (javax.naming.NamingEnumeration)6 BasicAttributes (javax.naming.directory.BasicAttributes)6 InitialLdapContext (javax.naming.ldap.InitialLdapContext)6 LdapConfigProperties (org.bedework.calfacade.configs.LdapConfigProperties)6 TreeSet (java.util.TreeSet)5 Attribute (javax.naming.directory.Attribute)4 Attributes (javax.naming.directory.Attributes)4 SearchResult (javax.naming.directory.SearchResult)4 BwPrincipal (org.bedework.calfacade.BwPrincipal)4 HibSession (org.bedework.calcorei.HibSession)3 ArrayList (java.util.ArrayList)2 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)1 PrincipalHref (org.bedework.dumprestore.restore.PrincipalHref)1