class SimplesamlExternalauthSubscriber in simpleSAMLphp Authentication 8.3
Event subscriber subscribing to ExternalAuthEvents.
Hierarchy
- class \Drupal\simplesamlphp_auth\EventSubscriber\SimplesamlExternalauthSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of SimplesamlExternalauthSubscriber
1 string reference to 'SimplesamlExternalauthSubscriber'
1 service uses SimplesamlExternalauthSubscriber
File
- src/
EventSubscriber/ SimplesamlExternalauthSubscriber.php, line 18
Namespace
Drupal\simplesamlphp_auth\EventSubscriberView source
class SimplesamlExternalauthSubscriber implements EventSubscriberInterface {
/**
* The SimpleSAML Authentication helper service.
*
* @var \Drupal\simplesamlphp_auth\Service\SimplesamlphpAuthManager
*/
protected $simplesaml;
/**
* The SimpleSAML Drupal Authentication service.
*
* @var \Drupal\simplesamlphp_auth\Service\SimplesamlphpDrupalAuth
*/
public $simplesamlDrupalauth;
/**
* A configuration object.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* A logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*
* @param \Drupal\simplesamlphp_auth\Service\SimplesamlphpAuthManager $simplesaml
* The SimpleSAML Authentication helper service.
* @param \Drupal\simplesamlphp_auth\Service\SimplesamlphpDrupalAuth $simplesaml_drupalauth
* The SimpleSAML Drupal Authentication service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(SimplesamlphpAuthManager $simplesaml, SimplesamlphpDrupalAuth $simplesaml_drupalauth, ConfigFactoryInterface $config_factory, LoggerInterface $logger, ModuleHandlerInterface $module_handler) {
$this->simplesaml = $simplesaml;
$this->simplesamlDrupalauth = $simplesaml_drupalauth;
$this->config = $config_factory
->get('simplesamlphp_auth.settings');
$this->logger = $logger;
$this->moduleHandler = $module_handler;
}
/**
* React on an ExternalAuth login event.
*
* @param \Drupal\externalauth\Event\ExternalAuthLoginEvent $event
* The subscribed event.
*/
public function externalauthLogin(ExternalAuthLoginEvent $event) {
if ($event
->getProvider() == "simplesamlphp_auth") {
if (!$this->simplesaml
->isActivated()) {
return;
}
if (!$this->simplesaml
->isAuthenticated()) {
return;
}
$account = $event
->getAccount();
$this->simplesamlDrupalauth
->synchronizeUserAttributes($account);
// Invoke a hook to let other modules alter the user account based on
// SimpleSAMLphp attributes.
$account_altered = FALSE;
$attributes = $this->simplesaml
->getAttributes();
foreach ($this->moduleHandler
->getImplementations('simplesamlphp_auth_user_attributes') as $module) {
$return_value = $this->moduleHandler
->invoke($module, 'simplesamlphp_auth_user_attributes', [
$account,
$attributes,
]);
if ($return_value instanceof UserInterface) {
if ($this->config
->get('debug')) {
$this->logger
->debug('Drupal user attributes have altered based on SAML attributes by %module module.', [
'%module' => $module,
]);
}
$account_altered = TRUE;
$account = $return_value;
}
}
if ($account_altered) {
$account
->save();
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ExternalAuthEvents::LOGIN][] = [
'externalauthLogin',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SimplesamlExternalauthSubscriber:: |
protected | property | A configuration object. | |
SimplesamlExternalauthSubscriber:: |
protected | property | A logger instance. | |
SimplesamlExternalauthSubscriber:: |
protected | property | The module handler service. | |
SimplesamlExternalauthSubscriber:: |
protected | property | The SimpleSAML Authentication helper service. | |
SimplesamlExternalauthSubscriber:: |
public | property | The SimpleSAML Drupal Authentication service. | |
SimplesamlExternalauthSubscriber:: |
public | function | React on an ExternalAuth login event. | |
SimplesamlExternalauthSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
SimplesamlExternalauthSubscriber:: |
public | function |