Allows the user to view / edit if the user is an admin or the user is trying to edit itself.

@param string $attribute
@param BaseUser $subject
@param TokenInterface $token

@return bool
341894
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        /** @var BaseUser $user */
        $user = $token->getUser();

        return $user instanceof BaseUser && ($user->hasRole('ROLE_ADMIN') || $user->getId() === $subject->getId());
    }
1109556
protected function supports($attribute, $subject)
    {
        if (null !== $subject) {
            return $subject instanceof Email && in_array($attribute, self::ATTRIBUTES);
        }

        return in_array($attribute, self::ATTRIBUTES);
    }
1373882
protected function voteOnAttribute($attribute, $subject,
                                       TokenInterface $token)
    {
        $granted = true;
        $uroles  = array();
        foreach ($token->getRoles() as $role) {
            $uroles[] = $role->getRole();
        }
        foreach ($this->subjectPrefixes as $prefix => $proles) {
            if (substr($subject, 0, strlen($prefix)) != $prefix) {
                continue;
            }
            $granted = false;
            if (count(array_intersect($uroles, $proles)) > 0) {
                return true;
            }
        }
        return $granted;
    }
1266485
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
    {
        $user = $token->getUser();

        if (!$user instanceof UserInterface) {
            return false;
        }

        $invitation = $subject;

        switch ($attribute) {
            case self::RESPOND:
                return $user->getUsername() == $invitation->getInvitee();
        }
    }
549985
public function canView(GroupableInterface $groupable, TokenInterface $token): bool
    {
        $user = $token->getUser();

        // Expirable entities can only be viewed by editors if expired.
        if ($groupable instanceof ExpirableInterface
            && $groupable->isExpired()) {
            $required_role = 'GROUP_ROLE_EDITOR';

        // Active entities can only be viewed by editors if not active.
        } elseif ($groupable instanceof ActiveInterface
            && !$groupable->isActive()) {
            $required_role = 'GROUP_ROLE_EDITOR';

        // Entity can be viewed by group users.
        } else {
            $required_role = 'GROUP_ROLE_USER';
        }

        // Iterate over groups and check access.
        foreach ($groupable->getGroups() as $group) {
            if ($this->decision_manager->decide($token, [$required_role], $group)) {
                return true;
            }
        }

        return false;
    }
1152478
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        return $this->supports($attribute, $subject) ? $this->containsRole($token, $subject) : false;
    }
664253
public function afterExecute(
        \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save $subject,
        $result
    ) {
        $productIds = $this->attributeHelper->getProductIds();
        if (! empty($productIds)) {
            $this->catalogResource->setModified($productIds);
        }
        return $result;
    }
902316
public function canView(GroupableInterface $media, TokenInterface $token): bool
    {
        $user = $token->getUser();
        if (0 == count($media->getGroups())) {
            return true;
        }

        return parent::canView($media, $token);
    }
671001
public function isGranted(UserInterface $user, $attributes, OwnedByUserModelInterface $model = null): bool
    {
        if (null !== $model && $user->getId() !== $model->getOwnedByUserId()) {
            $this->logger->info(
                'security.authorization.role: user and model owner are not the same {userId}, {ownerByUserId}',
                ['userId' => $user->getId(), 'ownerByUserId' => $model->getOwnedByUserId()]
            );

            return false;
        }

        $owningRoles = $this->getOwningRoles($user);
        $neededRoles = $this->getNeededRoles($attributes);

        $granted = $this->checkRoles($owningRoles, $neededRoles);

        $this->logger->info(
            'security.authorization.role: user {userId} granted {granted} for needed roles {neededRoles}',
            ['userId' => $user->getId(), 'granted' => $granted, 'neededRoles' => implode(', ', $neededRoles)]
        );

        return $granted;
    }
215281
public function isEasyAdminGranted(array $entityConfig, string $actionName, $subject = null)
    {
        try {
            $this->checksUserAccess($entityConfig, $actionName, $subject);
        } catch (AccessDeniedException $e) {
            return false;
        }

        return true;
    }
408440
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        if ($request->isXmlHttpRequest()) {
            /** @var User $user */
            $user = $token->getUser();
            $roles = $token->getRoles();
            $outputRoles = array();

            foreach ($roles as $role) {
                $outputRoles[] = $this->translator->trans('roles.' . $role->getRole(), array(), 'CodeLoversAngularBundle');
            }

            $output = $this->generator->getUserData($request, $token);

            // notify listeners to allow output modification
            $event = new LoginEvent($user);
            $event->setOutput($output);

            $this->dispatcher->dispatch(AuthEvents::LOGIN_SUCCESS, $event);

            return new JsonResponse($event->getOutput());
        } else {
            if ($targetPath = $request->getSession()->get('_security.target_path')) {
                $url = $targetPath;
            } else {
                $url = $this->getDefaultUrl();
            }

            return new RedirectResponse($url);
        }
    }
256461
public function isGranted(UserInterface $user, $attributes, OwnedByUserModelInterface $model = null): bool
    {
        foreach ($this->authorizations as $authorization) {
            if ($authorization->isGranted($user, $attributes, $model)) {
                return true;
            }
        }

        return false;
    }
1137014
protected function isCreator($subject, UserInterface $user)
    {
        return $subject instanceof BlameableInterface &&
               $subject->getCreatedBy() === $user->getUsername();
    }
312790
public function isGranted(DefinitionInterface $definition, $subject = null): bool
    {
        if ($this->isControlled($definition)) {
            return $this->authChecker->isGranted($this->getExpression($definition), $subject);
        }

        return true;
    }
1338954
public function verify( $user, $token ) {

		// Check Token
		if( $user->isVerifyTokenValid( $token ) ) {

			$modelClass	= static::$modelClass;

			// Find existing user
			$userToUpdate = $modelClass::findById( $user->id );

			// User need admin approval
			if( Yii::$app->core->isUserApproval() ) {

				$userToUpdate->verify();
			}
			// Direct approval and activation
			else {

				$userToUpdate->status = User::STATUS_ACTIVE;
			}

			$userToUpdate->unsetVerifyToken();

			$userToUpdate->update();

			return true;
		}

		return false;
	}
251017
public function login(&$subject, $token)
    {
        global $logger;
        global $app;
        try {
            if($app->getConfiguration()->isPreventMultipleLogins()) {
                list($authInfo, $roles, $tokens,$hashedSessionId) = $this->authenticate($token, true);
                $app->getSessionManager()->getActiveSession()->setAttribute('sessionHash', $hashedSessionId); 
            } else
                list($authInfo, $roles, $tokens) = $this->authenticate($token);
        } catch (AuthenticationException $aex) {
            $logger->error($aex->getMessage(), array($aex->getMessage()));
            throw $aex;
        }
        $loggedInSubj = $this->_createSubject($token, $authInfo, $subject, $roles);
        $this->_logAnalytics($app, $loggedInSubj);

        // Generate unique token to prevent XSRF.
        $app->getSessionManager()->getActiveSession()->setAttribute('nonce', $this->_generateCSRFToken(32)); 
            //sha1(uniqid(mt_rand(), true))); 
        $app->getSessionManager()->getActiveSession()->setAttribute(DefaultSubjectContext::AUTHENTICATED_SESSION_KEY, true);
        if(!empty($tokens)) {
            // FIXME: No token swapping done here - left to the application
            //$app->getSessionManager()->getActiveSession()->setAttribute('sharedKey', $tokens['token']); 
            //$app->getSessionManager()->getActiveSession()->setAttribute('secretKey', $tokens['secret']); 
            // FIXME: No token swapping done here - left to the application
            //// TODO : Fix Hack for storing account level tokens when logging in.
            //$session = $app->getSessionManager()->getActiveSession();
            //$session->setAttribute('accountSharedKey', $tokens['token']);
            //$session->setAttribute('accountSecretKey', $tokens['secret']);
        }
        return $loggedInSubj;

    }
1204616
public function can_edit(field_controller $field, int $instanceid = 0) : bool {
        if ($instanceid) {
            $context = $this->get_instance_context($instanceid);
            return (!$field->get_configdata_property('locked') ||
                    has_capability('moodle/course:changelockedcustomfields', $context));
        } else {
            $context = $this->get_parent_context();
            return (!$field->get_configdata_property('locked') ||
                guess_if_creator_will_have_course_capability('moodle/course:changelockedcustomfields', $context));
        }
    }