If HTTP_AUTHORIZATION does not exist tries to get it from
getallheaders() when available.
@param Collection $env The application Collection
@return Collection
341903
public static function determineAuthorization($env): Collection
    {
        $authorization = $env->get('HTTP_AUTHORIZATION');

        if (null === $authorization && \is_callable('getallheaders')) {
            $headers = \getallheaders();
            $headers = \array_change_key_case($headers, CASE_LOWER);

            if (isset($headers['authorization'])) {
                $env->set('HTTP_AUTHORIZATION', $headers['authorization']);
            }
        }

        return $env;
    }
234983
def _get_collection_for_user(self, collection_id, user):
        """"""
        collection_query = Collection.objects.filter(pk=collection_id)
        if not collection_query.exists():
            raise exceptions.ValidationError('Collection id does not exist')

        collection = collection_query.first()
        if not user.has_perm('add_collection', obj=collection):
            if user.is_authenticated:
                raise exceptions.PermissionDenied()
            else:
                raise exceptions.NotFound()

        return collection
15861
public function getCoreErrors($env = null)
    {
        $env = $env ?: $this->running_env;
        return isset($this->errors[$env]) ? $this->errors[$env] : 0;
    }
158379
public function getCollection(string $identifier): Collection
    {
        if (!$this->hasCollection($identifier)) {
            throw BlockException::noCollection($identifier);
        }

        return $this->collections->get($identifier);
    }
153025
public static function get($params = array())
	{
		$object = new static;
		$data   = $object->request('GET', $object->getUrl(), $params);
		$data   = $object->stripResponseData($data);

		// Initialise a collection
		$collection = self::newCollection();

		if (isset($data[0]) && is_array($data[0])) {
			// This should be a collection
			$collection->setItems($data);
		}

		return $collection;
	}
912581
public function getAllPermissions(): Collection
    {
        $user = auth()->user();

        if ($user->hasRole($this->roleRepository::ROLE_PA)) {
            $permissions = $this->permissionRepository->makeQuery()
                ->select('id', 'name', 'action', 'created_at')
                ->where('name', '!=', 'admin.acl.role')
                ->get();
        } elseif ($user->isSuperAdmin()) {
            $permissions = $this->permissionRepository->makeQuery()
                ->select('id', 'name', 'action', 'created_at')->get();
        } else {
            $permissions = collect([]);
        }

        return $permissions->sortBy('name')->groupBy('name');
    }
75113
public function all(array $params = array())
    {
        $endpoint = '/admin/custom_collections.json';
        $response = $this->request($endpoint, 'GET', $params);
        return $this->createCollection(CustomCollection::class, $response['custom_collections']);
    }
996144
public function getCallback($env = null)
    {
        $env = $env ?: $this->running_env;
        return isset($this->callbacks[$env]) ? $this->callbacks[$env] : null;
    }
1287697
public static function createFromEnv(array $env)
    {
        // cache
        if (isset($env['__request_object'])) {
            return $env['__request_object'];
        }

        if (isset($env['PATH_INFO'])) {
            $path = $env['PATH_INFO'];
        } elseif (isset($env['REQUEST_URI'])) {
            $path = $env['REQUEST_URI'];
        } elseif (isset($env['_SERVER']['PATH_INFO'])) {
            $path = $env['_SERVER']['PATH_INFO'];
        } elseif (isset($env['_SERVER']['REQUEST_URI'])) {
            $path = $env['_SERVER']['REQUEST_URI'];
        } else {
            // XXX: check path or throw exception
            $path = '/';
        }

        $requestMethod = 'GET';
        if (isset($env['REQUEST_METHOD'])) {
            $requestMethod = $env['REQUEST_METHOD'];
        } else if (isset($env['_SERVER']['REQUEST_METHOD'])) { // compatibility for superglobal
            $requestMethod = $env['_SERVER']['REQUEST_METHOD'];
        }

        // create request object with request method and path,
        // we can assign other parameters later.
        $request = new self($requestMethod, $path);
        if (function_exists('getallheaders')) {
            $request->headers = getallheaders();
        } else {
            // TODO: filter array keys by their prefix, consider adding an extension function for this.
            $request->headers = self::createHeadersFromServerGlobal($env);
        }

        if (isset($env['_SERVER'])) {
            $request->serverParameters = $env['_SERVER'];
        } else {
            $request->serverParameters = $env;
        }
        $request->parameters = $env['_REQUEST'];
        $request->queryParameters = $env['_GET'];
        $request->bodyParameters = $env['_POST'];
        $request->cookieParameters = $env['_COOKIE'];
        $request->sessionParameters = $env['_SESSION'];

        return $env['__request_object'] = $request;
    }
795542
def authorization_middleware(environ, start_response=None):
    '''
    '''
    key = 'http.authorization'
    c = environ.get(key)
    if c is None:
        code = 'HTTP_AUTHORIZATION'
        if code in environ:
            environ[key] = parse_authorization_header(environ[code])
1162368
public function all()
    {
        $endpoint = '/admin/policies.json';
        $response = $this->request($endpoint);
        return $this->createCollection(Policy::class, $response['policies']);
    }
217331
public static function create($method, $path, array $env = array())
    {
        $request = new self($method, $path);

        if (function_exists('getallheaders')) {
            $request->headers = getallheaders();
        } else {
            // TODO: filter array keys by their prefix, consider adding an extension function for this.
            $request->headers = self::createHeadersFromServerGlobal($env);
        }

        if (isset($env['_SERVER'])) {
            $request->serverParameters = $env['_SERVER'];
        } else {
            $request->serverParameters = $env;
        }
        $request->parameters = isset($env['_REQUEST']) ? $env['_REQUEST'] : array();
        $request->queryParameters = isset($env['_GET']) ? $env['_GET'] : array();
        $request->bodyParameters = isset($env['_POST']) ? $env['_POST'] : array();
        $request->cookieParameters = isset($env['_COOKIE']) ? $env['_COOKIE'] : array();
        $request->sessionParameters = isset($env['_SESSION']) ? $env['_SESSION'] : array();

        return $request;
    }
1247398
public static function env()
    {
        return function () {
            // Use credentials from environment variables, if available
            $key = getenv(self::ENV_KEY);
            $secret = getenv(self::ENV_SECRET);
            if ($key && $secret) {
                return Promise\promise_for(
                    new Credentials($key, $secret, getenv(self::ENV_SESSION) ?: NULL)
                );
            }

            return self::reject('Could not find environment variable '
                . 'credentials in ' . self::ENV_KEY . '/' . self::ENV_SECRET);
        };
    }
1299918
private function _authenticate($env)
    {
        switch (strtolower($this->authN_type)) {

            case 'cas':
                // Use CAS authentication.
                $casAuth = new UsfAuthCAS($env['auth.config.cas']);
                $casAuth->auth();

                //Add the username and attributes to the Slim environment
                $env['principal.name'] = $casAuth->getPrincipal();
                $env['principal.attributes'] = $casAuth->getAttributes();
                $env['principal.entitlements'] = $casAuth->getEntitlements();

                //Authorization check
                if (!$casAuth->isAuthorized($this->authZ_roles)) {
                    $this->_denyAccess();
                }

                break;

            case 'token':
                // Use the USF Token Auth library.
                $tokenAuth = new UsfAuthToken(
                    $env['auth.config.token']['app_id'],
                    $env['auth.config.token']['token_url']
                );

                $tokenAuth->setRequestMethod($env['REQUEST_METHOD']);
                $tokenAuth->setReferrer($env['HTTP_REFERER']);

                // Setup CORS headers
                $cors_config = $this->_corsConfig($env);
                $tokenAuth->setCorsConfig($cors_config);

                //Validate request token
                $tokenAuth->validateRequest($env['HTTP_X_AUTH_TOKEN']);

                //Add the username and attributes to the Slim environment
                $env['principal.name'] = $tokenAuth->getPrincipal();
                $env['principal.attributes'] = $tokenAuth->getAttributes();
                $env['principal.entitlements'] = $tokenAuth->getEntitlements();

                //Authorization check
                if (!$tokenAuth->isAuthorized($this->authZ_roles)) {
                    $this->_denyAccess();
                }

                //Add CORS headers
                $tokenAuth->addCorsHeaders();
                break;

            case 'hmac':
                // HMAC authentication: https://github.com/acquia/http-hmac-spec
                $hmacAuth = new UsfAuthHmac($env['auth.hmac.keyRegistry']);
                if (!empty($env['auth.hmac.timeout'])) {
                    $hmacAuth->setTimeout($env['auth.hmac.timeout']);
                }

                $hmacAuth->setRequestWrapper(new Slim2Request($this->app->request));

                try {
                    $hmacAuth->authenticate();
                } catch (Exception $exception) {
                    throw new Exception(
                        'Resource '.$this->app->request->getResourceUri().' using '.$this->app->request->getMethod().' authentication failed.',
                        401
                    );
                }

                //Add the username to the Slim environment
                $env['principal.name'] = $hmacAuth->getPrincipal();
                break;

            case 'permitall':
                // No authentication - let everyone in.
                break;

            case 'denyall':
                // No authentication - keep everyone out.
                $this->_denyAccess();
                break;

            default:
                throw new Exception("Unknown Authentication type: " . $this->authN_type, 500);
                break;
        }
    }
825818
public function authorizationEndpoint() {
		$endpoint = $this->getset('authorization_endpoint', func_get_args());
		return $this->validateEndpoint($endpoint ?: self::URI_AUTHORIZE);
	}
654613
protected function parseEnv(
        array $envs,
        /*# string */ $path,
        /*# bool */ $overload
    )/*# : array */ {
        foreach ($envs as $key => $val) {
            // source another env file
            if ($this->source_marker === $val) {
                $src = $this->expandPath($this->deReference($key), $path);
                $this->load($src, $overload);

            // set env
            } else {
                $this->setEnv($key, $this->deReference($val), $overload);
            }
        }
        return $this;
    }
254730
private function getPermissions(): ? Collection
    {
        if (!cache()->has('hc-permissions')) {
            try {
                if (class_exists(HCAclPermission::class) && Schema::hasTable(HCAclPermission::getTableName())) {
                    $permissions = HCAclPermission::with('roles')->get();

                    cache()->put('hc-permissions', $permissions, now()->addHour(12));
                }
            } catch (\Throwable $e) {
                report($e);
            }
        }

        return cache()->get('hc-permissions');
    }