You are here

class CsrfAccessCheck in Flag 8.4

Proxy class to the core CSRF access chcker allowing anonymous requests.

As per https://www.drupal.org/node/2319205 this is OK and desired.

Hierarchy

Expanded class hierarchy of CsrfAccessCheck

File

src/Access/CsrfAccessCheck.php, line 18

Namespace

Drupal\flag\Access
View source
class CsrfAccessCheck implements AccessInterface {

  /**
   * @var \Drupal\Core\Access\CsrfAccessCheck
   */
  protected $original;

  /**
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $account;

  /**
   * CsrfAccessCheck constructor.
   *
   * @param \Drupal\Core\Access\CsrfAccessCheck $original
   */
  public function __construct(OrignalCsrfAccessCheck $original, AccountInterface $account) {
    $this->original = $original;
    $this->account = $account;
  }

  /**
   * Checks access based on a CSRF token for the request for auth users.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The route to check against.
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The request object.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match object.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result, always allowed for anonymous users.
   */
  public function access(Route $route, Request $request, RouteMatchInterface $route_match) {

    // As the original returns AccessResult::allowedif the token validates,
    // we do the same for anonymous.
    return $this->account
      ->isAnonymous() ? AccessResult::allowed() : $this->original
      ->access($route, $request, $route_match);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CsrfAccessCheck::$account protected property
CsrfAccessCheck::$original protected property
CsrfAccessCheck::access public function Checks access based on a CSRF token for the request for auth users.
CsrfAccessCheck::__construct public function CsrfAccessCheck constructor.