Find the groups that this entity belongs to.

@param ent the entity in question
@return java.util.Iterator
974202
public java.util.Iterator findParentGroups(IEntity ent) throws GroupsException {
        String memberKey = ent.getKey();
        Integer type = EntityTypesLocator.getEntityTypes().getEntityIDFromType(ent.getLeafType());
        return findParentGroupsForEntity(memberKey, type.intValue());
    }
1074979
@Override
    public Set<Node> getGroupsForUser(Node user) {
        Set<Node> groups = new TreeSet<>();
        try {
            String query = "(& (objectClass=" + groupObjectClass + ") (" + groupMemberAttribut + "=" + ((LdapUser) user).getDn() + "))";
            SearchResult searchResult;
            Attributes attributes;
            SearchControls controls = new SearchControls();
            controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            NamingEnumeration<SearchResult> results = ctx.search("", query, controls);
            queryCount++;
            Node group;
            while (results.hasMore()) {
                searchResult = results.next();
                attributes = searchResult.getAttributes();
                group = getGroup(getAttributeOrNa(attributes, groupIdentifyer));
                group.setDn(searchResult.getNameInNamespace());
                groups.add(group);
            }
        } catch (NamingException ex) {
            handleNamingException(user, ex);
        }
        return groups;
    }
75409
@Override
    public EntityIdentifier[] searchForGroups(String query, SearchMethod method, Class leaftype)
            throws GroupsException {

        if (isTreeRefreshRequired()) {
            refreshTree();
        }

        log.debug(
                "Invoking searchForGroups():  query={}, method={}, leaftype=",
                query,
                method,
                leaftype.getName());

        // We only match the IPerson leaf type...
        final IEntityGroup root = getRootGroup();
        if (!leaftype.equals(root.getLeafType())) {
            return new EntityIdentifier[0];
        }

        // We need to escape regex special characters that appear in the query string...
        final String[][] specials =
                new String[][] {
                    /* backslash must come first! */
                    new String[] {"\\", "\\\\"},
                    new String[] {"[", "\\["},
                    /* closing ']' isn't needed b/c it's a normal character w/o a preceding '[' */
                    new String[] {"{", "\\{"},
                    /* closing '}' isn't needed b/c it's a normal character w/o a preceding '{' */
                    new String[] {"^", "\\^"},
                    new String[] {"$", "\\$"},
                    new String[] {".", "\\."},
                    new String[] {"|", "\\|"},
                    new String[] {"?", "\\?"},
                    new String[] {"*", "\\*"},
                    new String[] {"+", "\\+"},
                    new String[] {"(", "\\("},
                    new String[] {")", "\\)"}
                };
        for (String[] s : specials) {
            query = query.replace(s[0], s[1]);
        }

        // Establish the regex pattern to match on...
        String regex;
        switch (method) {
            case DISCRETE:
            case DISCRETE_CI:
                regex = query.toUpperCase();
                break;
            case STARTS_WITH:
            case STARTS_WITH_CI:
                regex = query.toUpperCase() + ".*";
                break;
            case ENDS_WITH:
            case ENDS_WITH_CI:
                regex = ".*" + query.toUpperCase();
                break;
            case CONTAINS:
            case CONTAINS_CI:
                regex = ".*" + query.toUpperCase() + ".*";
                break;
            default:
                String msg = "Unsupported search method:  " + method;
                throw new GroupsException(msg);
        }

        List<EntityIdentifier> rslt = new ArrayList<>();
        for (Map.Entry<String, List<String>> y : groupsTree.getKeysByUpperCaseName().entrySet()) {
            if (y.getKey().matches(regex)) {
                List<String> keys = y.getValue();
                for (String k : keys) {
                    rslt.add(new EntityIdentifier(k, IEntityGroup.class));
                }
            }
        }

        return rslt.toArray(new EntityIdentifier[rslt.size()]);
    }
388498
public Group<E> group(String name) {
        for (Group<E> group : this.groups()) {
            if (group.expr instanceof Expression.NamedGroup<?>) {
                Expression.NamedGroup<E> namedGroup = (Expression.NamedGroup<E>) group.expr;
                if (namedGroup.name.equals(name)) {
                    return group;
                }
            }
        }

        return null;
    }
1219732
@Override
    public EntityIdentifier[] searchForGroups(
            String query, IGroupConstants.SearchMethod method, Class leaftype)
            throws GroupsException {
        Set allIds = new HashSet();

        for (Iterator services = getComponentServices().values().iterator(); services.hasNext(); ) {
            IIndividualGroupService service = (IIndividualGroupService) services.next();
            EntityIdentifier[] ids = service.searchForGroups(query, method, leaftype);
            for (int i = 0; i < ids.length; i++) {
                try {
                    CompositeEntityIdentifier cei =
                            new CompositeEntityIdentifier(ids[i].getKey(), ids[i].getType());
                    cei.setServiceName(service.getServiceName());
                    allIds.add(cei);
                } catch (javax.naming.InvalidNameException ine) {
                }
            }
        }
        return (EntityIdentifier[]) allIds.toArray(new EntityIdentifier[allIds.size()]);
    }
1139535
Group getGroup(String id, AccessToken accessToken, String... attributes) {
        return getResource(id, accessToken, attributes);
    }
1372823
@Override
    public Set<Node> findGroups(final String cn) {
        QueryBuilder qb = new LdapQueryBuilder();
        if ("*".equals(cn)) {
            qb.append(LdapKeys.OBJECT_CLASS, groupObjectClass);
        } else {
            qb.append(LdapKeys.OBJECT_CLASS, groupObjectClass);
            qb.append(groupIdentifyer, cn + "*");
        }
        return findGroups(qb);
    }
700770
@Override
	public List<CPSpecificationOption> findByGroupId(long groupId) {
		return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}
523864
@Override
    public Iterator findMemberGroups(IEntityGroup eg) throws GroupsException {
        Map groups = new HashMap();
        IEntityGroup group = null;
        for (Iterator itr = findLocalMemberGroups(eg); itr.hasNext(); ) {
            group = (IEntityGroup) itr.next();
            groups.put(group.getKey(), group);
        }

        String[] memberGroupKeys = getGroupStore().findMemberGroupKeys(eg);
        for (int i = 0; i < memberGroupKeys.length; i++) {
            if (!groups.containsKey(memberGroupKeys[i])) {
                group = GroupService.findGroup(memberGroupKeys[i]);
                if (group != null) {
                    groups.put(group.getKey(), group);
                }
            }
        }
        return groups.values().iterator();
    }
298149
@Override
    public Iterator findMemberGroups(IEntityGroup group) throws GroupsException {

        if (isTreeRefreshRequired()) {
            refreshTree();
        }

        log.debug("Invoking findMemberGroups() for group:  {}", group.getLocalKey());

        List<IEntityGroup> rslt = new ArrayList<>();

        List<String> list = groupsTree.getChildren().get(group.getLocalKey());
        if (list != null) {
            // should only reach this code if its a SmartLdap managed group...
            for (String s : list) {
                rslt.add(groupsTree.getGroups().get(s));
            }
        }

        return rslt.iterator();
    }
1248384
protected void collectGroups(Group group, Set<String> groupSet) {

    Enumeration<? extends Principal> members = group.members();
    while (members.hasMoreElements()) {
      Principal member = members.nextElement();
      String name = member.getName();
      boolean added = groupSet.add(name);
      if (added && (member instanceof Group)) {
        collectGroups((Group) member, groupSet);
      }
    }
  }
1039613
public static IEntityGroup getRootGroup(Class<?> type) throws GroupsException {
        LOGGER.trace("Invoking getRootGroup for type='{}'", type);
        return instance().igetRootGroup(type);
    }
1134518
private void getGroups(Entity entity, LdapEntry ldapEntry, GroupMembershipControl grpMbrshipCtrl) throws WIMException {
        if (grpMbrshipCtrl == null) {
            return;
        }

        int level = grpMbrshipCtrl.getLevel();
        List<String> propNames = grpMbrshipCtrl.getProperties();
        String[] bases = null;
        List<String> searchBases = grpMbrshipCtrl.getSearchBases();
        int size = searchBases.size();
        String[] grpBases = iLdapConfigMgr.getGroupSearchBases();
        if (size == 0) {
            // New:: Default search bases to top level nodes if no group level search bases are defined
            if (grpBases.length != 0)
                bases = grpBases;
            else
                bases = iLdapConfigMgr.getTopLdapNodes();
        } else {
            List<String> baseList = new ArrayList<String>(size);
            for (int i = 0; i < size; i++) {
                String uName = searchBases.get(i);
                String dn = getDN(uName, null, null, true, false);
                baseList.add(dn);
            }
            bases = baseList.toArray(new String[0]);
        }
        bases = NodeHelper.getTopNodes(bases);
        if (iLdapConfigMgr.getMembershipAttribute() != null) {
            if (iLdapConfigMgr.isRacf())
                getGroupsByMembershipRacf(entity, ldapEntry, bases, level, propNames, null);
            else {
                getGroupsByMembership(entity, ldapEntry, bases, level, propNames, null);
            }
        } else {
            // If operational attribute "ibm-allGroups" is specified in groupMemberIdMap, then get groups using operational attr "ibm-allGroups"
            if (LdapConstants.IDS_LDAP_SERVER.equalsIgnoreCase(iLdapConfigMgr.getLdapType()) && iLdapConfigMgr.isLdapOperationalAttributeSet())
                getGroupsByOperationalAttribute(entity, ldapEntry, bases, level, propNames);
            else {
                getGroupsByMember(entity, ldapEntry, bases, level, propNames, null);
            }
        }
    }
1356120
protected Iterator findLocalMemberGroups(IEntityGroup eg) throws GroupsException {
        Collection groups = new ArrayList(10);
        IEntityGroup group = null;
        for (Iterator it = getGroupStore().findMemberGroups(eg); it.hasNext(); ) {
            group = (IEntityGroup) it.next();
            if (group == null) {
                log.warn(
                        "A null IEntityGroup object was part of a list groupStore.findMemberGroups");
                continue;
            }
            group.setLocalGroupService(this);
            groups.add(group);
            if (cacheInUse()) {
                try {
                    if (getGroupFromCache(group.getEntityIdentifier().getKey()) == null) {
                        cacheAdd(group);
                    }
                } catch (CachingException ce) {
                    throw new GroupsException("Problem finding member groups", ce);
                }
            }
        }
        return groups.iterator();
    }
1031080
public List<Group> getGroups() {
        List<Group> allGroups = new ArrayList<Group>();

        if (root != null) {
            getGroups(root, allGroups);
        }

        return allGroups;
    }
795937
@Override
    public Iterator findEntitiesForGroup(IEntityGroup group) throws GroupsException {

        if (isTreeRefreshRequired()) {
            refreshTree();
        }

        log.debug("Invoking findEntitiesForGroup() for group:  {}", group.getLocalKey());

        // We only deal w/ group-group relationships here...
        // return findMemberGroups(group);

        List<IEntity> rslt = new ArrayList<IEntity>();
        if (displayPersonMembers) {
            List<String> list = groupsTree.getPersonChildren().get(group.getLocalKey());
            if (list != null) {
                // should only reach this code if its a SmartLdap managed group...
                for (String s : list) {
                    rslt.add(persons.get(s));
                }
            }
        }
        return rslt.iterator();
    }
9631
private List<String> getGroups(String dn) throws WIMException {
        List<String> grpList = new ArrayList<String>();
        String filter = iLdapConfigMgr.getGroupMemberFilter(dn);
        String[] searchBases = iLdapConfigMgr.getGroupSearchBases();
        for (int i = 0; i < searchBases.length; i++) {
            String searchBase = searchBases[i];
            NamingEnumeration<SearchResult> nenu = iLdapConn.search(searchBase, filter, SearchControls.SUBTREE_SCOPE,
                                                                    LDAP_ATTR_OBJECTCLASS_ARRAY);
            while (nenu.hasMoreElements()) {
                SearchResult thisEntry = nenu.nextElement();
                if (thisEntry == null) {
                    continue;
                }
                String entryName = thisEntry.getName();
                if (entryName == null || entryName.trim().length() == 0) {
                    continue;
                }
                grpList.add(LdapHelper.prepareDN(entryName, searchBase));
            }
        }
        return grpList;
    }