Returns an <code>IGroupMember</code> representing either a group or a portal entity. If the
parm <code>type</code> is the group type, the <code>IGroupMember</code> is an <code>
IEntityGroup</code> else it is an <code>IEntity</code>.
437910
private IGroupMember igetGroupMember(String key, Class<?> type) throws GroupsException {
        return compositeGroupService.getGroupMember(key, type);
    }
571148
public static IGroupMember getGroupMember(String key, Class<?> type) throws GroupsException {
        /*
         * WARNING:  The 'type' parameter is not the leafType;  you're obligated
         * to say whether you want a group or a non-group (i.e. some type of
         * entity).  In fact, the underlying implementation blindly instantiates
         * whatever you tell it to.
         */

        LOGGER.trace("Invoking getEntity for key='{}', type='{}'", key, type);
        return instance().igetGroupMember(key, type);
    }
1189102
@SuppressWarnings("unchecked")
    @Override
    public Set<JsonEntityBean> search(String entityType, String searchTerm) {

        Set<JsonEntityBean> results = new HashSet<>();

        EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
        if (entityEnum == null) {
            throw new IllegalArgumentException(
                    String.format("Parameter entityType has an unknown value of [%s]", entityType));
        }

        EntityIdentifier[] identifiers;

        Class identifierType;

        // if the entity type is a group, use the group service's findGroup method
        // to locate it
        if (entityEnum.isGroup()) {
            identifiers =
                    GroupService.searchForGroups(
                            searchTerm,
                            GroupService.SearchMethod.CONTAINS_CI,
                            entityEnum.getClazz());
            identifierType = IEntityGroup.class;
        }

        // otherwise use the getGroupMember method
        else {
            identifiers =
                    GroupService.searchForEntities(
                            searchTerm,
                            GroupService.SearchMethod.CONTAINS_CI,
                            entityEnum.getClazz());
            identifierType = entityEnum.getClazz();
        }

        for (int i = 0; i < identifiers.length; i++) {
            if (identifiers[i].getType().equals(identifierType)) {
                IGroupMember entity = GroupService.getGroupMember(identifiers[i]);
                if (entity != null) {
                    JsonEntityBean jsonBean = getEntity(entity);
                    results.add(jsonBean);
                } else {
                    log.warn("Grouper member entity of " + identifiers[i].getKey() + " is null.");
                }
            }
        }

        return results;
    }
1365081
public static boolean isAdmin(IGroupMember member) {
        IEntityGroup adminGroup = null;

        try {
            adminGroup =
                    GroupService.getDistinguishedGroup(PORTAL_ADMINISTRATORS_DISTINGUISHED_GROUP);
        } catch (GroupsException ge) {
            // cannot determine whether or not the user is an admin.
            cLog.error(
                    "Administrative group not found, cannot determine "
                            + "user's admininstrative membership.",
                    ge);
        }

        return (null != adminGroup && adminGroup.deepContains(member));
    }
1177176
protected IEntityGroup findGroupWithCache(CompositeEntityIdentifier ent)
            throws GroupsException {
        try {
            IEntityGroup group = getGroupFromCache(ent.getKey());
            if (group == null) {
                group = primFindGroup(ent.getLocalKey());
                if (group != null) {
                    cacheAdd(group);
                }
            }
            return group;
        } catch (CachingException ce) {
            throw new GroupsException("Problem retrieving group " + ent.getKey(), ce);
        }
    }
1118568
@Override
    @SuppressWarnings("unchecked")
    public Iterator findEntitiesForGroup(IEntityGroup group) throws GroupsException {

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Searching Grouper for members of the group with key: " + group.getKey());
        }

        try {

            // execute a search for members of the specified group
            GcGetMembers getGroupsMembers = new GcGetMembers();
            getGroupsMembers.addGroupName(group.getLocalKey());
            getGroupsMembers.assignIncludeSubjectDetail(true);
            WsGetMembersResults results = getGroupsMembers.execute();

            if (results == null
                    || results.getResults() == null
                    || results.getResults().length == 0
                    || results.getResults()[0].getWsSubjects() == null) {
                LOGGER.debug("No members found for Grouper group with key " + group.getLocalKey());
                return Collections.<IGroupMember>emptyList().iterator();
            }

            WsSubject[] gInfos = results.getResults()[0].getWsSubjects();
            final List<IGroupMember> members = new ArrayList<IGroupMember>(gInfos.length);

            // add each result to the member list
            for (WsSubject gInfo : gInfos) {

                // if the member is not a group (aka person)
                if (!StringUtils.equals(gInfo.getSourceId(), "g:gsa")) {

                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(
                                "creating leaf member:"
                                        + gInfo.getId()
                                        + " and name: "
                                        + gInfo.getName()
                                        + " from group: "
                                        + group.getLocalKey());
                    }
                    // use the name instead of id as it shows better in the display
                    IGroupMember member = new EntityImpl(gInfo.getName(), IPerson.class);
                    members.add(member);
                }
            }

            // return an iterator for the assembled group
            return members.iterator();

        } catch (Exception e) {
            LOGGER.warn(
                    "Exception while attempting to retrieve "
                            + "member entities of group with key "
                            + group.getKey()
                            + " from Grouper web services: "
                            + e.getMessage());
            return Collections.<IGroupMember>emptyList().iterator();
        }
    }
860046
def get_type_id(context, **kw):
    
    portal_type = kw.get("portal_type", None)
    if portal_type:
        return portal_type

    # Override by provided marker interface
    if IAnalysisRequestPartition.providedBy(context):
        return "AnalysisRequestPartition"
    elif IAnalysisRequestRetest.providedBy(context):
        return "AnalysisRequestRetest"
    elif IAnalysisRequestSecondary.providedBy(context):
        return "AnalysisRequestSecondary"

    return api.get_portal_type(context)
81225
@Override
    public IEntityGroup newGroup(Class type) throws GroupsException {
        throwExceptionIfNotInternallyManaged();
        IEntityGroup group = groupFactory.newInstance(type);
        group.setLocalGroupService(this);
        if (cacheInUse()) {
            cacheAdd(group);
        }
        return group;
    }
966740
@Override
    public Iterator findMembers(IEntityGroup eg) throws GroupsException {
        Collection members = new ArrayList(10);
        Iterator it = null;

        for (it = findMemberGroups(eg); it.hasNext(); ) {
            members.add(it.next());
        }
        for (it = findMemberEntities(eg); it.hasNext(); ) {
            members.add(it.next());
        }

        return members.iterator();
    }
271546
@Override
    public boolean isUserDeepMemberOfGroupName(String userName, String groupName) {
        final EntityIdentifier[] results =
                GroupService.searchForGroups(
                        groupName, GroupService.SearchMethod.DISCRETE, IPerson.class);
        if (results == null || results.length == 0) {
            return false;
        }

        if (results.length > 1) {
            this.logger.warn(
                    results.length
                            + " groups were found for '"
                            + groupName
                            + "'. The first result will be used.");
        }

        final IGroupMember group = GroupService.getGroupMember(results[0]);

        final IEntity entity = GroupService.getEntity(userName, IPerson.class);
        if (entity == null) {
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("No user found for key '" + userName + "'");
            }

            return false;
        }

        return group.asGroup().deepContains(entity);
    }
714927
@Override
    public Iterator findMemberGroups(IEntityGroup group) throws GroupsException {
        Connection conn = null;
        Collection groups = new ArrayList();
        IEntityGroup eg = null;
        String serviceName = group.getServiceName().toString();
        String localKey = group.getLocalKey();

        try {
            conn = RDBMServices.getConnection();
            String sql = getFindMemberGroupsSql();
            PreparedStatement ps = conn.prepareStatement(sql);
            try {
                ps.setString(1, localKey);
                ps.setString(2, serviceName);
                if (LOG.isDebugEnabled())
                    LOG.debug(
                            "RDBMEntityGroupStore.findMemberGroups(): "
                                    + ps
                                    + " ("
                                    + localKey
                                    + ", "
                                    + serviceName
                                    + ")");
                ResultSet rs = ps.executeQuery();
                try {
                    while (rs.next()) {
                        eg = instanceFromResultSet(rs);
                        groups.add(eg);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                ps.close();
            }
        } catch (Exception sqle) {
            LOG.error("RDBMEntityGroupStore.findMemberGroups(): " + sqle);
            throw new GroupsException("Problem retrieving member groups: " + sqle);
        } finally {
            RDBMServices.releaseConnection(conn);
        }

        return groups.iterator();
    }
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();
    }
38958
private String getGroupKey() {
        EntityIdentifier[] groups = null;
        try {
            groups =
                    GroupService.searchForGroups(
                            groupName, IGroupConstants.SearchMethod.DISCRETE, IPerson.class);
        } catch (GroupsException e1) {
            throw new RuntimeException(
                    "An exception occurred searching for " + "the group " + groupName + ".", e1);
        }
        if (groups == null || groups.length == 0)
            throw new RuntimeException(
                    "Group with name '"
                            + groupName
                            + "' not found for "
                            + this.getClass().getName()
                            + ". All evaluations will return false.");

        return groups[0].getKey();
    }
1114424
private Entity createEntityFromLdapEntry(Object parentDO, String propName, LdapEntry ldapEntry, List<String> propNames) throws WIMException {
        final String METHODNAME = "createEntityFromLdapEntry";

        String outEntityType = ldapEntry.getType();
        Entity outEntity = null;
        // For changed entities, when change type is delete, it is possible that
        // the type of entity (which maps to the LDAP entry's objectclass is not
        // available.
        if (outEntityType != null) {
            if (outEntityType.equalsIgnoreCase(SchemaConstants.DO_PERSON))
                outEntity = new Person();
            else if (outEntityType.equalsIgnoreCase(SchemaConstants.DO_PERSON_ACCOUNT))
                outEntity = new PersonAccount();
            else if (outEntityType.equalsIgnoreCase(SchemaConstants.DO_GROUP))
                outEntity = new Group();
            else
                outEntity = new Entity();
        } else {
            outEntity = new Entity();
        }

        if (parentDO instanceof Root) {
            if (SchemaConstants.DO_ENTITIES.equalsIgnoreCase(propName))
                ((Root) parentDO).getEntities().add(outEntity);
        } else if (parentDO instanceof Entity) {
            if (SchemaConstants.DO_GROUP.equalsIgnoreCase(propName)) {
                /*
                 * May get back plain entities if objectclass for group entity and
                 * group filters don't match up identically.
                 */
                if (outEntity instanceof Group) {
                    ((Entity) parentDO).getGroups().add((Group) outEntity);
                } else {
                    if (tc.isDebugEnabled()) {
                        Tr.debug(tc, METHODNAME + " Expected group entity. Group will excluded from group membership. Entity is " + outEntity, ldapEntry);
                    }
                }
            } else if (SchemaConstants.DO_MEMBERS.equalsIgnoreCase(propName)) {
                ((Group) parentDO).getMembers().add(outEntity);
            } else if (SchemaConstants.DO_CHILDREN.equalsIgnoreCase(propName)) {
                ((Entity) parentDO).getChildren().add(outEntity);
            }
        }

        IdentifierType outId = new IdentifierType();
        outEntity.setIdentifier(outId);
        outId.setUniqueName(ldapEntry.getUniqueName());
        outId.setExternalId(ldapEntry.getExtId());
        outId.setExternalName(ldapEntry.getDN());
        outId.setRepositoryId(reposId);

        String changeType = ldapEntry.getChangeType();
        if (changeType != null) {
            outEntity.setChangeType(changeType);
            if (SchemaConstants.CHANGETYPE_DELETE.equals(changeType) == false) {
                populateEntity(outEntity, propNames, ldapEntry.getAttributes());
            }
        } else {
            populateEntity(outEntity, propNames, ldapEntry.getAttributes());
        }
        return outEntity;
    }
466703
public Query queryUsersForGroup(String groupId) {
        Query q = queryEntitiesRequest(HttpMethod.GET, null, null, organizationId,
                applicationId, "groups", groupId, "users");
        return q;
    }
1305132
@Override
    public EntityIdentifier[] searchForGroups(
            final String query,
            final SearchMethod method,
            @SuppressWarnings("unchecked") final Class leaftype) {

        // only search for groups
        if (leaftype != IPerson.class) {
            return new EntityIdentifier[] {};
        }

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Searching Grouper for groups matching query: " + query);
        }

        // result groups.
        List<EntityIdentifier> groups = new ArrayList<EntityIdentifier>();

        try {

            // TODO: searches need to be performed against the group display
            // name rather than the group key

            GcFindGroups groupSearch = new GcFindGroups();
            WsQueryFilter filter = new WsQueryFilter();
            // is this an exact search or fuzzy
            if ((method == SearchMethod.DISCRETE_CI) || (method == SearchMethod.DISCRETE)) {
                filter.setQueryFilterType("FIND_BY_GROUP_NAME_EXACT");
            } else {
                filter.setQueryFilterType("FIND_BY_GROUP_NAME_APPROXIMATE");
            }
            filter.setGroupName(query);
            groupSearch.assignQueryFilter(filter);
            WsFindGroupsResults results = groupSearch.execute();

            if (results != null && results.getGroupResults() != null) {
                for (WsGroup g : results.getGroupResults()) {
                    if (validKey(g.getName())) {
                        if (LOGGER.isTraceEnabled()) {
                            LOGGER.trace("Retrieved group: " + g.getName());
                        }
                        groups.add(new EntityIdentifier(g.getName(), IEntityGroup.class));
                    }
                }
            }

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Returning " + groups.size() + " results for query " + query);
            }

            return groups.toArray(new EntityIdentifier[groups.size()]);

        } catch (Exception e) {
            LOGGER.warn(
                    "Exception while attempting to retrieve "
                            + "search results for query "
                            + query
                            + " and entity type "
                            + leaftype.getCanonicalName()
                            + " : "
                            + e.getMessage());
            return new EntityIdentifier[] {};
        }
    }
1135209
protected IEntityGroup createUportalGroupFromGrouperGroup(WsGroup wsGroup) {
        IEntityGroup iEntityGroup = new EntityGroupImpl(wsGroup.getName(), IPerson.class);

        // need to set the group name and description to the actual
        // display name and description
        iEntityGroup.setName(wsGroup.getDisplayName());
        iEntityGroup.setDescription(wsGroup.getDescription());
        return iEntityGroup;
    }