Forces SSL based on restricted URLs
The environment settings take priority over those defined in the control panel

@return bool

@throws ErrorException
@throws \yii\base\Exception
@throws \yii\base\InvalidConfigException
190261
public function handleSslRouting()
    {
        if ($this->settings->sslRoutingEnabled && !Craft::$app->getRequest()->getIsConsoleRequest())
        {
            $requestedUrl   = Craft::$app->request->getUrl();
            $restrictedUrls = $this->settings->sslRoutingRestrictedUrls;

            if (!Craft::$app->request->isSecureConnection)
            {
                foreach ($restrictedUrls as $restrictedUrl)
                {
                    // Parse dynamic variables like /{cpTrigger}
                    if (stripos($restrictedUrl, '{') !== false)
                    {
                        $restrictedUrl = Craft::$app->view->renderObjectTemplate(
                            $restrictedUrl,
                            $this->getDynamicParams()
                        );
                    }

                    $restrictedUrl = '/'.ltrim($restrictedUrl, '/');

                    if (stripos($requestedUrl, $restrictedUrl) === 0)
                    {
                        $this->forceSsl();
                    }
                }

                return true;
            }
        }

        return false;
    }
908837
public function init()
    {
        parent::init();

        if ($this->connectorRoute === null) {
            throw new InvalidConfigException('Connector route must be specified.');
        }

        $this->settings['url'] = Url::toRoute($this->connectorRoute);

        if (!isset($this->settings['lang'])) {
            $this->settings['lang'] = Yii::$app->language;
        } elseif ($this->settings['lang'] === false) {
            unset($this->settings['lang']);
        }

        $this->settings['customData'] = [
            Yii::$app->request->csrfParam => Yii::$app->request->csrfToken,
        ];
    }
1266463
protected function isSecurityException()
    {
        if (!count($this->csrfExceptions))
            return false;
        foreach ($this->csrfExceptions as $route) {
            list($module, $controller, $action) = explode('/', $route);
            if ($module != $this->module) {
                continue;
            }
            if ('*' == $controller)
                return true;

            if ($controller != $this->controller)
                continue;

            if ('*' == $action)
                return true;

            return ($action == $this->action);
        }
        return false;
    }
553389
public function validate()
    {
        return (
            (
                filter_var($this->uri, FILTER_VALIDATE_URL) ||
                // PHP 5.x bug fix: FILTER_VALIDATE_URL doesn't support IPv6 urls. IP check not needed in the future.
                $this->validateIP(($parsed = parse_url($this->uri, PHP_URL_HOST)) === false ? '' : $parsed)
            ) &&
            ($parsed = parse_url($this->uri)) !== false &&
            (
                $this->validateHost($parsed['host']) ||
                $this->validateIP($parsed['host'])
            ) &&
            $this->validateScheme($parsed['scheme'])
        );
    }
647427
public function forceSiteUrl(&$options, $site)
    {
        if (!$site instanceof Site) {
            $site = $this->storage->findOne($site);
        }

        if ($GLOBALS['is_https']) {
            $options['https'] = !$site->isHttpsAllowed();
        } else if (variable_get('https', false)) {
            $options['https'] = !$site->isHttpAllowed();
        } else {
            // Sorry, HTTPS is disabled at the Drupal level, note that it is not
            // mandatory to this because url() will do the check by itself, but
            // because there is in here one code path in which we are going to
            // manually set the base URL, we need to compute that by ourselves.
            $options['https'] = false;
        }

        // Warning, this is a INTERNAL url() function behavior, so we have
        // to reproduce a few other behaviours to go along with it, such as
        // manual http vs https handling. Please see the variable_get('https')
        // documentation above.
        $options['base_url'] = ($options['https'] ? 'https://' : 'http://') . $site->getHostname();
        $options['absolute'] = true;
    }
333771
protected function setDefaultRule()
    {
        if (Yii::$app->getAuthManager()->getRule(RouteRule::RULE_NAME) === null) {
            Yii::$app->getAuthManager()->add(new RouteRule());
        }
    }
384494
public static function get()
	{
		$configFile = Yii::$app->params[Enum::CONFIG_FILE];
		$config = require($configFile);

		if (!is_array($config))
			return [];

		return $config;
	}
73199
protected function isEnabled()
    {
        // At least one redirect must be enabled
        if (!$this->getForceWWW() && !$this->getForceSSL()) {
            return false;
        }

        // Filter by env vars
        $enabledEnvs = $this->getEnabledEnvs();
        if (is_bool($enabledEnvs)) {
            return $enabledEnvs;
        }

        // If CLI, EnabledEnvs must contain CLI
        if (Director::is_cli() && !in_array('cli', $enabledEnvs)) {
            return false;
        }

        // Check other envs
        return empty($enabledEnvs) || in_array(Director::get_environment_type(), $enabledEnvs);
    }
206750
protected function defaultReturnUrl()
    {
        $params = Yii::$app->getRequest()->get();
        foreach ($params as $name => $value) {
            if (strncmp('openid', $name, 6) === 0) {
                unset($params[$name]);
            }
        }
        $params[0] = Yii::$app->requestedRoute;
        $url = Yii::$app->getUrlManager()->createUrl($params);

        return $this->getTrustRoot() . $url;
    }
1126877
public function openConnection()
    {
        if (null == $this->httpClient) {
            return false;
        }

        $configuration = array_merge(array(
            'authUrl' => '',
            'password' => '',
            'queryUrl' => '',
            'username' => ''
        ), $this->configuration);

        // authenticate only if an authUrl was given.
        if ($this->RdfHelpers->simpleCheckURI($configuration['authUrl'])) {
            $this->authenticateOnServer(
                $configuration['authUrl'],
                $configuration['username'],
                $configuration['password']
            );
        }

        // check query URL
        if (false === $this->RdfHelpers->simpleCheckURI($configuration['queryUrl'])) {
            throw new \Exception('Parameter queryUrl is not an URI or empty: '. $configuration['queryUrl']);
        }
    }
132703
public function loadConfig()
    {
        $config = \Yii::$app->authManager->config;

        $this->stdout("\tAll config is ready: ", Console::FG_GREEN);
        $this->stdout(" (rules: " . count(ArrayHelper::getValue($config, 'rules', [])) . ';');
        $this->stdout(" roles: " . count(ArrayHelper::getValue($config, 'roles', [])) . ';');
        $this->stdout(" permissions: " . count(ArrayHelper::getValue($config, 'permissions', [])) . ';)');
        $this->stdout("\n");
        return $config;
    }
371940
public function loadPermissions() {

		$role = $this->role;

		if( isset( $role ) ) {

			$this->permissions = $role->getPermissionsSlugList();
		}
		else {

			throw new ForbiddenHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NO_ACCESS ) );
		}
	}
207404
public function authenticate() {
		if (isset($_GET[$this->errorParam])) {
			$error_code = $_GET[$this->errorParam];
			if ($error_code === $this->errorAccessDeniedCode) {
				// access_denied error (user canceled)
				$this->cancel();
			}
			else {
				$error = $error_code;
				if (isset($_GET[$this->errorDescriptionParam])) {
					$error = $_GET[$this->errorDescriptionParam].' ('.$error.')';
				}
				throw new EAuthException($error);
			}
			return false;
		}

		// Get the access_token and save them to the session.
		if (isset($_GET['code'])) {
			$code = $_GET['code'];
			$token = $this->getAccessToken($code);
			if (isset($token)) {
				$this->authenticated = true;
				$this->saveAccessToken($token);
			}
		}
		// Redirect to the authorization page
		else {
			// Use the URL of the current page as the callback URL.
			if (isset($_GET['redirect_uri'])) {
				$redirect_uri = $_GET['redirect_uri'];
			}
			else {
				$server = Yii::app()->request->getHostInfo();
				$path = Yii::app()->request->getUrl();
				$redirect_uri = $server . $path;
			}
			$url = $this->getCodeUrl($redirect_uri);
			Yii::app()->request->redirect($url);
		}

		return $this->getIsAuthenticated();
	}
59706
public function ensureCorrectDebugSetting()
    {
        if (!defined('YII_DEBUG')) {
            return false;
        }
        if (!defined('YII_ENV')) {
            return false;
        }
        if (defined('YII_ENV') && YII_ENV !== 'dev') {
            return false;
        }
        if (defined('YII_DEBUG') && YII_DEBUG !== true) {
            return false;
        }

        return Yii::$app->getModule('user')->debug;
    }
673376
public function actionIndex()
    {
        if (!\Yii::$app->user->can('index', [], false))
            throw new ForbiddenHttpException(Module::t('metaTag', 'Access denied.'));
        return parent::actionIndex();
    }
275989
protected function loadCookies()
    {
        $cookies = [];
        if ($this->enableCookieValidation) {
            if ($this->cookieValidationKey == '') {
                throw new InvalidConfigException(get_class($this) . '::$cookieValidationKey must be configured with a secret key.');
            }
            foreach ($this->getCookieParams() as $name => $value) {
                if (!is_string($value)) {
                    continue;
                }
                $data = $this->app->getSecurity()->validateData($value, $this->cookieValidationKey);
                if ($data === false) {
                    continue;
                }
                $data = @unserialize($data);
                if (is_array($data) && isset($data[0], $data[1]) && $data[0] === $name) {
                    $cookies[$name] = Yii::createObject([
                        '__class' => \yii\http\Cookie::class,
                        'name' => $name,
                        'value' => $data[1],
                        'expire' => null,
                    ]);
                }
            }
        } else {
            foreach ($this->getCookieParams() as $name => $value) {
                $cookies[$name] = Yii::createObject([
                    '__class' => \yii\http\Cookie::class,
                    'name' => $name,
                    'value' => $value,
                    'expire' => null,
                ]);
            }
        }

        return $cookies;
    }
215415
public function ssl()
    {
        if (is_null($this->ssl)) {
            $this->ssl = app(Ssl::class);
        }

        return $this->ssl;
    }