You are here

public function ContentHubAccess::access in Acquia Content Hub 8.2

Same name and namespace in other branches
  1. 8 src/Access/ContentHubAccess.php \Drupal\acquia_contenthub\Access\ContentHubAccess::access()

Checks access to Entity CDF.

Only grants access to logged in users with 'Administer Acquia Content Hub' permission or if the request verifies its HMAC signature.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The HTTP request object.

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

Return value

\Drupal\Core\Access\AccessResult TRUE if granted access, FALSE otherwise.

File

src/Access/ContentHubAccess.php, line 58

Class

ContentHubAccess
Implements permission to prevent unauthorized access to webhooks.

Namespace

Drupal\acquia_contenthub\Access

Code

public function access(Request $request, AccountInterface $account) {

  // Check permissions and combine that with any custom access checking
  // needed. Pass forward parameters from the route and/or request as needed.
  if ($account
    ->hasPermission('administer acquia content hub')) {

    // If this is a logged in user with 'Administer Acquia Content Hub'
    // permission then grant access.
    return AccessResult::allowed();
  }
  else {
    if (!$this->clientFactory
      ->getClient()) {
      $this->loggerFactory
        ->get('acquia_contenthub')
        ->debug('Access denied: Acquia Content Hub Client not connected.');
      return AccessResult::forbidden('Acquia Content Hub Client not connected.');
    }

    // Only allow access if the Signature validates.
    return AccessResult::allowedIf((bool) $this->clientFactory
      ->authenticate($request));
  }
}