Searches for any group that is either the user's primary or contains the
        user as a member.
13548
def user_groups(self, ldap_user, group_search):
        
        groups = []

        try:
            user_uid = ldap_user.attrs["uid"][0]

            if "gidNumber" in ldap_user.attrs:
                user_gid = ldap_user.attrs["gidNumber"][0]
                filterstr = "(|(gidNumber={})(memberUid={}))".format(
                    self.ldap.filter.escape_filter_chars(user_gid),
                    self.ldap.filter.escape_filter_chars(user_uid),
                )
            else:
                filterstr = "(memberUid={})".format(
                    self.ldap.filter.escape_filter_chars(user_uid)
                )

            search = group_search.search_with_additional_term_string(filterstr)
            groups = search.execute(ldap_user.connection)
        except (KeyError, IndexError):
            pass

        return groups
1264726
private IEntityGroup primFind(String groupID, boolean lockable) throws GroupsException {
        IEntityGroup eg = null;
        Connection conn = null;
        try {
            conn = RDBMServices.getConnection();
            String sql = getFindGroupSql();
            PreparedStatement ps = conn.prepareStatement(sql);
            try {
                ps.setString(1, groupID);
                if (LOG.isDebugEnabled())
                    LOG.debug("RDBMEntityGroupStore.find(): " + ps + " (" + groupID + ")");
                ResultSet rs = ps.executeQuery();
                try {
                    while (rs.next()) {
                        eg =
                                (lockable)
                                        ? lockableInstanceFromResultSet(rs)
                                        : instanceFromResultSet(rs);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                ps.close();
            }
        } catch (Exception e) {
            LOG.error("RDBMEntityGroupStore.find(): ", e);
            throw new GroupsException("Error retrieving " + groupID + ": ", e);
        } finally {
            RDBMServices.releaseConnection(conn);
        }

        return eg;
    }
902783
def get_user_group(key)

      if !Setting.get('user_groups').blank?

        arr = ActiveSupport::JSON.decode(Setting.get('user_groups').gsub("\\", ''))

        if arr.has_key? key
          arr[key]
        else
          Array.new
        end

      end
    end
444894
@Override
    public boolean contains(IEntityGroup group, IGroupMember member) throws GroupsException {

        String groupContainerName = group.getLocalKey();
        String groupMemberName = member.getKey();

        if (!validKey(groupContainerName) || !validKey(groupMemberName)) {
            return false;
        }

        GcHasMember gcHasMember = new GcHasMember();
        gcHasMember.assignGroupName(groupContainerName);
        gcHasMember.addSubjectLookup(new WsSubjectLookup(null, "g:gsa", groupMemberName));
        WsHasMemberResults wsHasMemberResults = gcHasMember.execute();
        if (GrouperClientUtils.length(wsHasMemberResults.getResults()) == 1) {
            WsHasMemberResult wsHasMemberResult = wsHasMemberResults.getResults()[0];
            return StringUtils.equals(
                    "IS_MEMBER", wsHasMemberResult.getResultMetadata().getResultCode());
        }
        return false;
    }
23762
def is_member_of(self, group_name):
        """"""
        group_dn = 'cn=%s,cn=groups,cn=accounts,%s' % (group_name, self._base_dn)
        if str(group_dn).lower() in [str(i).lower() for i in self.member_of]:
            return True
        else:
            return False
1322115
def get_groups(self, username):
        """"""
        username = ldap.filter.escape_filter_chars(self._byte_p2(username))
        userdn = self._get_user(username, NO_ATTR)

        searchfilter = self.group_filter_tmpl % {
            'userdn': userdn,
            'username': username
        }

        groups = self._search(searchfilter, NO_ATTR, self.groupdn)
        ret = []
        for entry in groups:
            ret.append(self._uni(entry[0]))
        return ret
91101
def user_groups(self, ldap_user, group_search):
        
        group_info_map = {}  # Maps group_dn to group_info of groups we've found
        member_dn_set = {ldap_user.dn}  # Member DNs to search with next
        handled_dn_set = set()  # Member DNs that we've already searched with

        while len(member_dn_set) > 0:
            group_infos = self.find_groups_with_any_member(
                member_dn_set, group_search, ldap_user.connection
            )
            new_group_info_map = {info[0]: info for info in group_infos}
            group_info_map.update(new_group_info_map)
            handled_dn_set.update(member_dn_set)

            # Get ready for the next iteration. To avoid cycles, we make sure
            # never to search with the same member DN twice.
            member_dn_set = set(new_group_info_map.keys()) - handled_dn_set

        return group_info_map.values()
1088631
def CheckPermissions(self, username, subject):
    """"""

    if subject in self.authorized_users:
      return ((username in self.authorized_users[subject]) or
              self.group_access_manager.MemberOfAuthorizedGroup(
                  username, subject))

    # In case the subject is not found, the safest thing to do is to raise.
    # It's up to the users of this class to handle this exception and
    # grant/not grant permissions to the user in question.
    raise InvalidSubject("Subject %s was not found." % subject)
1285706
@Override
    public Iterator findParentGroups(IGroupMember gm) throws GroupsException {
        log.debug("Finding containing groups for member {}", gm.getKey());
        Collection groups = new ArrayList(10);
        IEntityGroup group = null;
        for (Iterator it = getGroupStore().findParentGroups(gm); it.hasNext(); ) {
            group = (IEntityGroup) it.next();
            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 containing groups", ce);
                }
            }
        }
        return groups.iterator();
    }
363994
def _gather_group_members(group, groups, users):
    '''
    
    '''
    _group = __salt__['group.info'](group)

    if not _group:
        log.warning('Group %s does not exist, ignoring.', group)
        return

    for member in _group['members']:
        if member not in users:
            users[member] = groups[group]
1254437
def http_basic_auth_group_member_required(groups):
    """"""

    if isinstance(groups, six.string_types):
        # Check user is in a group
        return auth.set_authentication_predicate(http_basic_auth_check_user, [auth.user_in_group, groups])
    else:
        # Check user is in many group
        return auth.set_authentication_predicate(http_basic_auth_check_user, [auth.user_in_any_group, groups])
818421
def member(self, user, objects=False):
        
        try:
            member = self.search(uid=user, objects=objects)[0]
        except IndexError:
            return None
        if objects:
            return member
        return member[1]
359817
def search(self, **kw):
        """"""
        q = db.select(self.table).condition('status', 'active')
        for k, v in kw:
            q.condition(k, v)
        data = q.execute()
        users = []
        for user in data:
            users.append(self.load(user, self.model))
        return users
263298
def member_of?(group)
      if group.is_a? Group
        groups.include? group
      else
        member_of? Group.new(group)
      end
    end
780631
def has_membership(self, user, role):
        
        targetRecord = AuthMembership.objects(creator=self.client, user=user).first()
        if targetRecord:
            return role in [i.role for i in targetRecord.groups]
        return False
620152
def is_user(self, organisation_id):
        """"""
        return (self._has_role(organisation_id, self.roles.user) or
                self.is_org_admin(organisation_id))
633571
def get_user_group_perms(user_or_group, obj):
    
    user, group = get_identity(user_or_group)

    if user and not user.is_active:
        return [], []
    user_model = get_user_model()
    ctype = ContentType.objects.get_for_model(obj)

    group_model = get_group_obj_perms_model(obj)
    group_rel_name = group_model.permission.field.related_query_name()
    if user:
        user_rel_name = user_model.groups.field.related_query_name()
        group_filters = {user_rel_name: user}
    else:
        group_filters = {'pk': group.pk}
    if group_model.objects.is_generic():
        group_filters.update({
            '{}__content_type'.format(group_rel_name): ctype,
            '{}__object_pk'.format(group_rel_name): obj.pk,
        })
    else:
        group_filters['{}__content_object'.format(group_rel_name)] = obj

    user_perms, group_perms = [], []

    if user:
        perms_qs = Permission.objects.filter(content_type=ctype)
        if user.is_superuser:
            user_perms = list(chain(perms_qs.values_list("codename", flat=True)))
        else:
            model = get_user_obj_perms_model(obj)
            related_name = model.permission.field.related_query_name()
            user_filters = {'{}__user'.format(related_name): user}
            if model.objects.is_generic():
                user_filters.update({
                    '{}__content_type'.format(related_name): ctype,
                    '{}__object_pk'.format(related_name): obj.pk,
                })
            else:
                user_filters['{}__content_object'.format(related_name)] = obj

            user_perms_qs = perms_qs.filter(**user_filters)
            user_perms = list(chain(user_perms_qs.values_list("codename", flat=True)))

    group_perms_qs = Group.objects.filter(**group_filters)
    group_perms = list(chain(group_perms_qs.order_by("pk").values_list(
        "pk", "name", "{}__permission__codename".format(group_rel_name))))

    group_perms = _group_groups(group_perms)

    return user_perms, group_perms