/**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param callable|null $next
  * @return EmptyResponse
  * @throws \Exception
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     if ($this->isAdminAuthentication($request)) {
         $this->user->addRoles([Roles::ADMIN]);
     }
     return $next($request, $response);
 }
 /**
  * @return int
  */
 protected function getCursor()
 {
     $allowCursor = $this->config->get('staticus.search.allow_cursor_for_users', false);
     $roles = $this->user->getRoles();
     if ($allowCursor || in_array(Roles::ADMIN, $roles, true)) {
         $cursor = (int) PrepareResourceMiddlewareAbstract::getParamFromRequest('cursor', $this->request);
         return $cursor;
     }
     return self::DEFAULT_CURSOR;
 }
Esempio n. 3
0
 protected function isAllowedForUser($aclResource, $action, $namespace = '')
 {
     if (!$this->service->acl()->hasResource($namespace . $aclResource)) {
         return false;
     }
     return $this->user->can($namespace . $aclResource, $action);
 }
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     /** @link http://framework.zend.com/manual/current/en/modules/zend.authentication.intro.html */
     if (array_key_exists('Zend_Auth', $_SESSION)) {
         /** @var \Zend\Stdlib\ArrayObject $auth */
         $auth = $_SESSION['Zend_Auth'];
         if ($auth->offsetExists('storage')) {
             /** @var StdClass $storage */
             $storage = $auth->storage;
             if (property_exists($storage, 'user_id')) {
                 $this->user->login($storage->user_id, [Roles::USER]);
                 $this->user->setNamespace(UserInterface::NAMESPACES . DIRECTORY_SEPARATOR . $storage->user_id);
             }
         }
     }
     return $next($request, $response);
 }