Check access to an object in the frontend
@param Action $action The action taken on the object
@param mixed $onObject The object; page and contents are currently supported
@return GrantResult Returns the check result
4366
public function Grant(Action $action, $onObject)
    {
        if ($onObject instanceof Page)
        {
            return $this->GrantOnPage($onObject);
        }
        if ($onObject instanceof Content)
        {
            return $this->GrantOnContent($onObject, $action);
        }
        else
        {
            throw new \LogicException('Frontend access check not implemented for type '. get_class($onObject));
        }
        return GrantResult::Allowed();
    }
321127
public function get($account, $action = '', $parameters = null, $acceptableContentTypes = null)
    {
        if (is_array($account)) {
            $tmp_results = array();
            foreach ($account as $accnt) {
                $result = $this->sendRequest('GET', $accnt, $action, $parameters, null, $acceptableContentTypes);
                if ($result === false) {
                    return false;
                }
                $tmp_results[ $accnt ] = $result;
            }
            
            return $tmp_results;
        }
        
        return $this->sendRequest('GET', $account, $action, $parameters, null, $acceptableContentTypes);
    }
205834
protected function checkAllScheduledByAction(array $objects, $action): void
    {
        foreach ($objects as $object) {
            if (!$this->getAuthorizationChecker()->isGranted('perm_'.$action, $object)) {
                throw new AccessDeniedException('Insufficient privilege to '.$action.' the entity');
            }
        }
    }
470670
public function passesOrFail($action = null)
    {
        if(  !$this->passes($action) ){
            throw new ValidatorException( $this->errorsBag() );
        }

        return true;
    }
325246
public function check($action, NodeRef &$nodeRef, &$newData = null, $isRead = false)
    {
        return $this->checkInternal($action, $nodeRef, $newData, false, $isRead);
    }
805284
public function searchContextGetAction(Request $request, $access, $system, $object_name, $external_id)
    {
        // Search/Index - basically same same. For now at least.
        /* But it has a very annoying drawback;
         * It more or less does not work.
         * The reason is simple: I have to be able to filter every entity on
         * granted or not. And I can do that on two ways:
         *
         * Not use contextGetAction from the CommonBundle and make my own here
         *   and filter every single entity.
         * Rewrite contextGetAction to check every entity and filter.
         *   Which means quite alot more calls and slower response.
         * Add a better is_granted to twig and filter there.
         *   is_granted in twog only supports a role check, not the symfony
         *   security voter, which is quite odd. Someone else should have felt
         *   this need aswell.
         */
        $this->denyAccessUnlessGranted('index', new Message());
        $context_conf = $this->container->getParameter('app.contexts');
        $conf = $context_conf['BisonLabSakonninBundle']['Message'];
        $conf['entity'] = "BisonLabSakonninBundle:Message";

        // If it's REST, but HTML, we'll be returning HTML content, but not a
        // complete page.
        if ($this->isRest($access)) {
            $conf['show_template'] = "BisonLabSakonninBundle:Message:_show.html.twig";
            $conf['list_template'] = "BisonLabSakonninBundle:Message:_index.html.twig";
        } else {
            $conf['show_template'] = "BisonLabSakonninBundle:Message:show.html.twig";
            $conf['list_template'] = "BisonLabSakonninBundle:Message:index.html.twig";
        }
        return $this->contextGetAction(
            $request, $conf, $access, $system, $object_name, $external_id);
    }
99569
public static function canAny($action, $objectType)
    {
        if (!isset($_SESSION['ACL_INFO'])) {
            return false;
        };
        $acl = $_SESSION['ACL_INFO'];
        foreach (array('*', $action) as $act) {
            if (array_key_exists($act, $acl)) {
                $acl2 = $acl[$act];
                foreach (array('*', $objectType) as $typ) {
                    if (array_key_exists($typ, $acl2)) {
                        foreach ($acl2[$typ] as $id) {
                            return true;
                        };
                    };
                };
            };
        };
        return false;
    }
822689
protected function checkAuth($action,$resource)
	{
		return true; // remove after testing
		try {
			$userModel  = new User();
			$auth       = new BasicAuthenticator($userModel);
			$user       = $auth->currentUser();
			if ($user instanceof UserInterface) {
				$authorizer = new Authorizer( $user );
				$result     = $authorizer->can( $action, $resource );
			} else {
				$result = false;
			}
		} catch (\Exception $e) {
			\error_log($e->getMessage());
			$result = false;
		}
		return $result;
	}
953849
public function hasAccess(User $user, $controller, $action, $requestParameters) {
        $required = array();
        try {
            // $rights = ServiceManager::getServiceManager()->get(RouteAnnotationService::SERVICE_ID)->getRights($controller, $action);
            // todo use $rights when PHPDoc Annotations will be moved to the Doctrines annotations
            $requiredRights = ControllerHelper::getRequiredRights($controller, $action);
            $uris = $this->extractAndGroupUriFromParameters($requestParameters, array_keys($requiredRights));

            foreach($uris as $name => $urisValue) {
                $required[] = array_fill_keys($urisValue, $requiredRights[$name]);
            }
        } catch (ActionNotFoundException $e) {
            // action not found, no access
            return false;
        }
        
        return empty($required)
            ? true
            : $this->hasPrivileges($user, array_merge(...$required));
    }
307902
public function userAllowed($action)
    {
        if (user()->isAdmin()) {
            return true;
        }

        $this->_loadPermissions();
        $allowedRoles = $this->_permissions
            ->filter(function ($rule) use ($action) {
                return $rule->get('action') == $action;
            })
            ->extract('role_id')
            ->toArray();
        $intersect = array_intersect($allowedRoles, user()->get('role_ids'));

        return !empty($intersect);
    }
142673
public function can($action, HasPermissionInterface $resource) {
        $has_permission = false;

        $checker = $resource->permissionChecker();
        $has_permission = $checker->checkPermission($this, $action);

        return $has_permission;
    }
464279
protected function authorize(?string $action = null): bool
    {
        if (empty($action)) {
            return false;
        }

        return $this->foundation->acl()->can($action);
    }
592415
public function goToAction($action, $params = [])
    {
        return $this->request->goToPage($this->getName(), $action, $params);
    }
1367534
protected function getAllowedMethodsForRoute(ControllerInterface $class, $action)
    {
        $actionsInfo = $class->getMethods();
        if (isset($actionsInfo[$action])) {
            $methods = implode(', ', $actionsInfo[$action]->getAllowedMethods());

            $methodInfo = ReflectionHelper::getMethodInfo($class, $action);

            header('Access-Control-Allow-Origin : *');
            header('Access-Control-Allow-Methods : ' . $methods);
            header('Access-Control-Allow-Headers : *');

            return $methodInfo;
        }

        return [];
    }
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;
  }
233361
public function canIf(string $action): bool
    {
        $roles = $this->getUserRoles();
        $action = Keyword::make($action);

        if (\is_null($this->actions->search($action))) {
            return false;
        }

        return $this->checkAuthorization($roles, $action);
    }
82631
private function GrantOnContent(Content $content, BackendAction $action)
    {
        if ($this->GetUser()->Equals($content->GetUser()))
        {
            return GrantResult::Allowed();
        }
        $contentRights = RightsFinder::FindContentRights($content);
        $contentGroup = GroupFinder::FindContentGroup($content);
        if (!$contentRights || !$contentGroup)
        {
            return GrantResult::NoAccess();
        }
        $groups = $this->GetGroups();
        foreach ($groups as $group)
        {
            $result = $this->GrantGroupOnContent($group, $contentGroup, $contentRights, $action);
            if ($result->Equals(GrantResult::Allowed()))
            {
                return $result;
            }
        }
        return GrantResult::NoAccess();
    }