Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     $this->data['name'] = $this->currentUser->getDisplayName();
     $this->data['authenticated'] = $this->currentUser->isAuthenticated();
     $this->data['roles'] = [];
     $storage = $this->entityManager->getStorage('user_role');
     foreach ($this->currentUser->getRoles() as $role) {
         $entity = $storage->load($role);
         $this->data['roles'][] = $entity->label();
     }
     foreach ($this->providerCollector->getSortedProviders() as $provider_id => $provider) {
         if ($provider->applies($request)) {
             $this->data['provider'] = $provider_id;
         }
     }
     $this->data['anonymous'] = $this->configFactory->get('user.settings')->get('anonymous');
 }
Esempio n. 2
0
 /**
  * Default implementation of the provider filter.
  *
  * Checks whether a provider is allowed as per the _auth option on a route. If
  * the option is not set or if the request did not match any route, only
  * providers from the global provider set are allowed.
  *
  * If no filter is registered for the given provider id, the default filter
  * is applied.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The incoming request.
  * @param string $provider_id
  *   The id of the authentication provider to check access for.
  *
  * @return bool
  *   TRUE if provider is allowed, FALSE otherwise.
  */
 protected function defaultFilter(Request $request, $provider_id)
 {
     $route = RouteMatch::createFromRequest($request)->getRouteObject();
     $has_auth_option = isset($route) && $route->hasOption('_auth');
     if ($has_auth_option) {
         return in_array($provider_id, $route->getOption('_auth'));
     } else {
         return $this->authCollector->isGlobal($provider_id);
     }
 }