hasAccess()

check if access is allowed for that action and user

@param mixed[] $url    URL accessed by user
@param mixed[] $user   user's session data
@return bool        true in case of action should be skip or false otherwise
762206
public function hasAccess(array $url, array $user): bool
    {
        if (!empty($url['action']) && !empty($url['controller'])) {
            $controllerName = Utils::normalizeControllerName($url);
            if ($this->isSkipAction($controllerName, $url['action'])) {
                return true;
            }
        }

        if (!empty($url['controller']) && $this->isSkipController($url['controller'])) {
            return true;
        }

        if (!empty($url['action']) && $this->isSkipControllerActions($url['controller'], $url['action'])) {
            return true;
        }

        return false;
    }
1369991
public function checkAccess($p = P, $do = P_DO, $user_id = 0)
    {
        // Guest module can be opened by anyone
        if ($p === 'guest') {
            return true;
        }

        // Only logged-in Users can proceed further
        if (!$this->isLogged()) {
            return false;
        }

        // Get User id
        if (!$user_id) {
            $user_id = USER_ID;
        }

        // Check maybe User have group with full access
        $group_id = $this->getUserData('group_id', $user_id);
        if (self::getInstance()->getGroupData('full_access', $group_id)) {
            return true;
        }

        // Check or init cache
        if (!self::$access) {
            $group_access_collection = new GroupAccessRepository();
            $group_access_collection->setWhereGroupId((int)$group_id);
            foreach ($group_access_collection->getAsArrayOfObjectData() as $group_access) {
                /** @var GroupAccess $group_access */
                self::$access[$group_access['p']][$group_access['do']] = true;
            }
        }

        // Check access for exact admin panel page and action
        return isset(self::$access[$p][$do]);
    }
1286028
public function checkAccessToken($access_token = null)
    {
        $token = is_null($access_token) ? $this->access_token : $access_token;
        if (is_null($token)) return false;

        $rs = $this->api('getUserSettings', array('access_token' => $token));
        return isset($rs['response']);
    }
636715
static public function jiraGet($url, $user, array $parameterList = [])
    {
        return self::json(
            $url,
            $parameterList,
            self::HTTP_METHOD_GET,
            [
                'Authorization: Basic ' . $user
            ]
        );
    }
590359
private function userAttemptBruteForceLock(User $user)
    {
        if ($this->userAttemptBruteForceLockHasExceeded($user)) {
            return true;
        }
        
        $this->attempts = $user->login_attempt + 1;
        
        if ($this->attempts >= $this->allowedAttempts) {
            $user->updateAttributes(['login_attempt_lock_expiration' => time() + $this->lockoutTime]);
        }
        
        $user->updateAttributes(['login_attempt' => $this->attempts]);
    }
644172
protected function checkAccess($action = null)
    {
        $allowed = false;

        $ip = Yii::$app->getRequest()->getUserIP();
        foreach ($this->allowedIPs as $filter) {
            if ($filter === '*' || $filter === $ip || (($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos))) {
                $allowed = true;
                break;
            }
        }
        if ($allowed === false) {
            foreach ($this->allowedHosts as $hostname) {
                $filter = gethostbyname($hostname);
                if ($filter === $ip) {
                    $allowed = true;
                    break;
                }
            }
        }
        if ($allowed === false) {
            if (!$this->disableIpRestrictionWarning) {
                Yii::warning('Access to debugger is denied due to IP address restriction. The requesting IP address is ' . $ip, __METHOD__);
            }

            return false;
        }

        if ($this->checkAccessCallback !== null && call_user_func($this->checkAccessCallback, $action) !== true) {
            if (!$this->disableCallbackRestrictionWarning) {
                Yii::warning('Access to debugger is denied due to checkAccessCallback.', __METHOD__);
            }

            return false;
        }

        return true;
    }
609150
public static Boolean canAccess(String url) {
		return ContextUtils.getAuthorizationEngine(ContextUtils.getRequest())
				.check(url) == null;
	}
1015012
public function is_available(User $user)
    {
        return $this->app->getAclForUser($user)->has_right(\ACL::ORDER_MASTER);
    }
94397
public function authorize($user, Request $request)
    {
        if ($request->is('userAdmin')) {
            return true;
        }

        $user = user();
        $path = $this->requestPath($request);
        $cacheKey = 'permissions_' . intval($user->id);
        $permissions = Cache::read($cacheKey, 'permissions');

        if ($permissions === false) {
            $permissions = [];
            Cache::write($cacheKey, [], 'permissions');
        }

        if (!isset($permissions[$path])) {
            $allowed = $user->isAllowed($path);
            $permissions[$path] = $allowed;
            Cache::write($cacheKey, $permissions, 'permissions');
        } else {
            $allowed = $permissions[$path];
        }

        return $allowed;
    }
63082
protected function doesCurrentUserHaveAccess()
    {
        // Admins have access by default
        if (Craft::$app->user->getIsAdmin())
        {
            return true;
        }

        // User has the right permission
        if (Craft::$app->user->checkPermission(Patrol::MAINTENANCE_MODE_BYPASS_PERMISSION))
        {
            return true;
        }

        return false;
    }
328119
public function isAccessible($url)
    {
        $context = $this->getContext($url);

        return is_resource(@fopen($url, 'r', null, $context));
    }
421373
public function checkAccess($action, $resource)
    {
        if ((is_null($resource) || is_null($resource->getId())) && (empty($action) || in_array(strtolower($action), array('list', 'create', 'post')))) {
            return true;
        }

        if (!is_null($resource)) {
            $query = $this->createQueryBuilder();
            $query->andWhere($query->getRootAliases()[0] . '.id = ' . $this->addNamedParameter('id', $resource, $query));
            $result = $this->getOneOrNullResultFromQueryBuilder($query);
            if ($result) {
                return true;
            } else {
                $this->throwException('Access for this resource has been denied', 'access-denied');
            }
        }
    }
1073060
public function has_access($condition, $driver = null, $user = null)
	{
		if (is_null($user))
		{
			$groups = $this->get_groups();
			$user = reset($groups);
		}
		return parent::has_access($condition, $driver, $user);
	}
1082921
public function checkAccessAction($action) {
    $method = $this->request->httpMethod();
    $apiActions = Config::inst()->get(get_class($this), 'api_allowed_actions');
    $isAllowed = false;
    if ($apiActions === null) {
      // all actions + methods are allowed, use default check
      return parent::checkAccessAction($action);
    } else if ($apiActions === true) {
      return true;
    }
    if (is_array($apiActions)) {
      foreach($apiActions as $apiAction => $permission) {
        preg_match("/^(.+?):(.+)$/", $apiAction, $matches);
        if ((!isset($matches[1]))||(!isset($matches[2]))) {
          return user_error("Ensure that `api_allowed_actions` fulfills the following pattern: `\$method:\$action` => `\$permission`");
        }
        $allowedMethod = strtoupper($matches[1]);
        $allowedAction = $matches[2];
        if ((($allowedMethod === $method)||($allowedMethod === "*")) && ($allowedAction === $action)) {
          if ($permission === true) {
            // wildcard
            $isAllowed = true;
          } else if ($permission === '->') {
            $isAllowed = true;
          } else if (substr($permission,0,2) === '->') {
            // use method
            $permissionMethod = substr($permission,2);
            if (!$this->hasMethod($permissionMethod)) {
              return user_error("Permission method `$permissionMethod` doesn't exists on `$this->class`");
            } else {
              $isAllowed = $this->{$permissionMethod}();
            }
          } else {
            $isAllowed = Permission::check($permission);
          }
        }
      }
    }
    return $isAllowed;
  }
762566
protected function can(string $action, ?Authorizable $user = null): bool
    {
        return ! \is_null($user)
                    ? $this->acl->canAs($user, $action)
                    : $this->acl->can($action);
    }
716723
public function canAccess($controller, $action, $module = null) {
        $module = is_array($module)?null:$module;
        $rights = $this->getRightsFromMap($controller, $action, $module);
        if ('*' == $rights[0]) {
            return true;
        }
        if ('@' == $rights[0]) {
            return !\mpf\WebApp::get()->user()->isGuest();
        }
        $hasRights = false;
        foreach ($rights as $right) {
            $hasRights = $hasRights || \mpf\WebApp::get()->user()->hasRight($right);
        }
        return $hasRights;
    }
132442
protected static function validateUserAndPass($url)
    {
        $parsedURL = parse_url($url);

        // Validate user (disallow slashes)
        if (!empty($parsedURL['user']) && strstr($parsedURL['user'], '\\')) {
            return false;
        }
        if (!empty($parsedURL['pass']) && strstr($parsedURL['pass'], '\\')) {
            return false;
        }

        return true;
    }