Ensure the user is mapped to any applicable groups.
@param array $data
@param Member $member
14752
public function updateMemberGroups($data, Member $member)
    {
        if (isset($data['memberof'])) {
            $ldapGroups = is_array($data['memberof']) ? $data['memberof'] : [$data['memberof']];
            foreach ($ldapGroups as $groupDN) {
                foreach (LDAPGroupMapping::get() as $mapping) {
                    if (!$mapping->DN) {
                        $this->getLogger()->debug(
                            sprintf(
                                'LDAPGroupMapping ID %s is missing DN field. Skipping',
                                $mapping->ID
                            )
                        );
                        continue;
                    }

                    // the user is a direct member of group with a mapping, add them to the SS group.
                    if ($mapping->DN == $groupDN) {
                        $group = $mapping->Group();
                        if ($group && $group->exists()) {
                            $group->Members()->add($member, [
                                'IsImportedFromLDAP' => '1'
                            ]);
                            $mappedGroupIDs[] = $mapping->GroupID;
                        }
                    }

                    // the user *might* be a member of a nested group provided the scope of the mapping
                    // is to include the entire subtree. Check all those mappings and find the LDAP child groups
                    // to see if they are a member of one of those. If they are, add them to the SS group
                    if ($mapping->Scope == 'Subtree') {
                        $childGroups = $this->getNestedGroups($mapping->DN, ['dn']);
                        if (!$childGroups) {
                            continue;
                        }

                        foreach ($childGroups as $childGroupDN => $childGroupRecord) {
                            if ($childGroupDN == $groupDN) {
                                $group = $mapping->Group();
                                if ($group && $group->exists()) {
                                    $group->Members()->add($member, [
                                        'IsImportedFromLDAP' => '1'
                                    ]);
                                    $mappedGroupIDs[] = $mapping->GroupID;
                                }
                            }
                        }
                    }
                }
            }
        }

        // Lookup the previous mappings and see if there is any mappings no longer present.
        $unmappedGroups = $member->Groups()->alterDataQuery(function (DataQuery $query) {
            // join with the Group_Members table because we only want those group members assigned by this module.
            $query->leftJoin("Group_Members", '"Group_Members"."GroupID" = "Group"."ID"');
            $query->where('"Group_Members"."IsImportedFromLDAP" = 1');
        });

        // Don't remove associations which have just been added and we know are already correct!
        if (!empty($mappedGroupIDs)) {
            $unmappedGroups = $unmappedGroups->filter("GroupID:NOT", $mappedGroupIDs);
        }

        // Remove the member from any previously mapped groups, where the mapping
        // has since been removed in the LDAP data source
        if ($unmappedGroups->count()) {
            foreach ($unmappedGroups as $group) {
                $group->Members()->remove($member);
            }
        }
    }
958491
public function remove( $member )
    {
        if( false !== $key = array_search( $member, $this->members, true ) ) {
            unset( $this->members[$key] );
        }
        return $this;
    }
1014820
public function flushMemberCache($memberIDs = null)
    {
        if (!$this->cacheService) {
            return;
        }

        // Hard flush, e.g. flush=1
        if (!$memberIDs) {
            $this->cacheService->clear();
        }

        if ($memberIDs && is_array($memberIDs)) {
            foreach ([self::VIEW, self::EDIT, self::DELETE] as $type) {
                foreach ($memberIDs as $memberID) {
                    $key = $this->generateCacheKey($type, $memberID);
                    $this->cacheService->delete($key);
                }
            }
        }
    }
1233667
public function onMethodVerificationFailure(Member $member, $method)
    {
        $context = [
            'method' => get_class($method),
        ];
        if ($lockOutAfterCount = $member->config()->get('lock_out_after_incorrect_logins')) {
            // Add information about how many attempts have been made
            $context['attempts'] = $member->FailedLoginCount;
            $context['attempt_limit'] = $lockOutAfterCount;
        }

        $this->getAuditLogger()->info(sprintf(
            '"%s" (ID: %s) failed to verify using MFA method',
            $member->Email ?: $member->Title,
            $member->ID
        ), $context);
    }
1283971
protected function addMembers(array $members, array $managers, GroupInterface $entity) {
    foreach ($members as $account_uuid) {
      $account = $this->userStorage->loadByProperties([
        'uuid' => $account_uuid,
      ]);

      if (($account = current($account)) && !$entity->getMember($account)) {
        $values = [];
        // If the user should have the manager role, grant it to him now.
        if (in_array($account_uuid, $managers)) {
          $values = ['group_roles' => [$entity->bundle() . '-group_manager']];
        }
        $entity->addMember($account, $values);
      }
    }
  }
257450
public function view(User $user, MemberCategory $member)
    {
        return $this->allowOnTeam($user, $member->team_id);
    }
1301855
final public function whereIn(string $memberExpression, array $values)
    {
        return $this->where($memberExpression, ConditionOperator::IN, $values);
    }
799968
public function mapMemberExpression(NestedMember $member) : MemberMapping
    {
        try {
            $subclassMappings = $this->findSubclassMappings(
                $this->rootEntityMapper,
                $member
            );

            $nestedRelations = $this->mapMemberExpressionsToRelations(
                $this->rootEntityMapper,
                $member->getPartsExceptLast(),
                $finalMapper
            );

            return $this->mapFinalMember($finalMapper, $subclassMappings, $nestedRelations, $member->getLastPart());
        } catch (BaseException $inner) {
            if ($inner instanceof MemberExpressionMappingException && $inner->getPrevious()) {
                $inner = $inner->getPrevious();
            }

            throw new MemberExpressionMappingException(
                sprintf(
                    'Could not map member expression \'%s\' of entity type %s: %s',
                    $member->asString(), $this->rootEntityMapper->getObjectType(), $inner->getMessage()
                ),
                1,
                $inner
            );
        }
    }
922477
public static void ensureMemberAccess(Class<?> currentClass,
                                          Class<?> memberClass,
                                          Object target,
                                          int modifiers)
        throws IllegalAccessException
    {
        if (target == null && Modifier.isProtected(modifiers)) {
            int mods = modifiers;
            mods = mods & (~Modifier.PROTECTED);
            mods = mods | Modifier.PUBLIC;

            /*
             * See if we fail because of class modifiers
             */
            Reflection.ensureMemberAccess(currentClass,
                                          memberClass,
                                          target,
                                          mods);
            try {
                /*
                 * We're still here so class access was ok.
                 * Now try with default field access.
                 */
                mods = mods & (~Modifier.PUBLIC);
                Reflection.ensureMemberAccess(currentClass,
                                              memberClass,
                                              target,
                                              mods);
                /*
                 * We're still here so access is ok without
                 * checking for protected.
                 */
                return;
            } catch (IllegalAccessException e) {
                /*
                 * Access failed but we're 'protected' so
                 * if the test below succeeds then we're ok.
                 */
                if (isSubclassOf(currentClass, memberClass)) {
                    return;
                } else {
                    throw e;
                }
            }
        } else {
            Reflection.ensureMemberAccess(currentClass,
                                          memberClass,
                                          target,
                                          modifiers);
        }
    }
1029737
protected function userHasAccess($member)
    {
        if (!$member) {
            if (!Security::getCurrentUser()) {
                return false;
            }
            $member = Security::getCurrentUser();
        }

        if (Permission::checkMember($member, "ADMIN")) {
            return true;
        }

        // This method primarily "protects" access to a WorkflowInstance, but assumes access only to be granted to
        // users assigned-to that WorkflowInstance. However; lowly authors (users entering items into a workflow) are
        // not assigned - but we still wish them to see their submitted content.
        $inWorkflowGroupOrUserTables = ($member->inGroups($this->Groups()) || $this->Users()->find('ID', $member->ID));
        // This method is used in more than just the ModelAdmin. Check for the current controller to determine where
        // canView() expectations differ
        if ($this->getTarget() && Controller::curr()->getAction() == 'index' && !$inWorkflowGroupOrUserTables) {
            if ($this->getVersionedConnection($this->getTarget()->ID, $member->ID)) {
                return true;
            }
            return false;
        }
        return $inWorkflowGroupOrUserTables;
    }
1210447
public function canView($member = null)
    {
        if (parent::canView($member)) {
            return true;
        }

        if (Subsite::all_accessible_sites()->count() > 0) {
            return true;
        }

        return false;
    }
527294
public function srem($key, $member) {
        try {
            return $this->getRedis()->sRem($key, $member);
        } catch (RedisException $ex) {
            throw new ConnectException();
        }
    }
17078
public function sismembers($key, $member) {
        try {
            return $this->getRedis()->sIsMember($key, $member);
        } catch (RedisException $ex) {
            throw new ConnectException();
        }
    }
494554
public function hasStaticMember($member)
    {
        if (is_string($this->$member)) {
            $tokens = token_get_all('<?php '.$this->$member);

            return
                count($tokens) === 2 &&
                is_array($tokens[1]) &&
                in_array($tokens[1][0], [T_CONSTANT_ENCAPSED_STRING, T_DNUMBER, T_LNUMBER]);
        }

        return false;
    }
1065448
public function set($member, $value)
    {
        $member = '_'.$member;
        $members = get_object_vars($this);
        if (array_key_exists($member, $members)) {
            if (is_array($this->$member)) {
                $this->{$member}[] = $value;
            } else {
                $this->$member = $value;
            }

            return TRUE;
        }

        return FALSE;
    }
877390
public void setMemberAccounts(java.util.Collection<String> memberAccounts) {
        if (memberAccounts == null) {
            this.memberAccounts = null;
            return;
        }

        this.memberAccounts = new java.util.ArrayList<String>(memberAccounts);
    }
514296
protected function actionLink($action, $member = null)
    {
        if (!$member) {
            $member = Member::currentUser();
        }
        if (!$member) {
            return false;
        }

        /**
         * @todo: How do we handle "DataObject" instances that don't have a Link to reject/spam/delete?? This may
         * we have to make CMS a hard dependency instead.
         */
        // if (!$this->Parent()->hasMethod('Link')) {
        //     return false;
        // }

        $url = Controller::join_links(
            Director::baseURL(),
            'comments',
            $action,
            $this->ID
        );

        // Limit access for this user
        $token = $this->getSecurityToken();
        return $token->addToUrl($url, $member);
    }