class KeycloakRouteSubscriber in Keycloak OpenID Connect 8
Listens to dynamic route events.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\keycloak\Routing\KeycloakRouteSubscriber
Expanded class hierarchy of KeycloakRouteSubscriber
1 string reference to 'KeycloakRouteSubscriber'
1 service uses KeycloakRouteSubscriber
File
- src/
Routing/ KeycloakRouteSubscriber.php, line 13
Namespace
Drupal\keycloak\RoutingView source
class KeycloakRouteSubscriber extends RouteSubscriberBase {
/**
* The Keycloak service.
*
* @var \Drupal\keycloak\Service\KeycloakServiceInterface
*/
protected $keycloak;
/**
* Construct a KeycloakRouteSubscriber object.
*
* @param \Drupal\keycloak\Service\KeycloakServiceInterface $keycloak
* A Keycloak service instance.
*/
public function __construct(KeycloakServiceInterface $keycloak) {
$this->keycloak = $keycloak;
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
// Whether the Keycloak client is disabled.
if (!$this->keycloak
->isEnabled()) {
return;
}
// Whether Keycloak single sign-on is enabled.
if ($this->keycloak
->isSsoEnabled() && ($route = $collection
->get('user.login'))) {
$route
->setDefaults([
'_controller' => '\\Drupal\\keycloak\\Controller\\KeycloakController::login',
])
->setOptions([
'_maintenance_access' => TRUE,
'no_cache' => TRUE,
]);
}
// Always grant access to '/user/logout' and delegate its
// handling to our own controller.
if (($this->keycloak
->isKeycloakSignOutEnabled() || $this->keycloak
->isCheckSessionEnabled()) && ($route = $collection
->get('user.logout'))) {
$route
->setDefaults([
'_controller' => '\\Drupal\\keycloak\\Controller\\KeycloakController::logout',
])
->setRequirements([
'_access' => 'TRUE',
])
->setOptions([
'no_cache' => TRUE,
]);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// Come after field_ui.
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
-200,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KeycloakRouteSubscriber:: |
protected | property | The Keycloak service. | |
KeycloakRouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
KeycloakRouteSubscriber:: |
public static | function |
Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase:: |
|
KeycloakRouteSubscriber:: |
public | function | Construct a KeycloakRouteSubscriber object. | |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |