class ShibAuthSubscriber in Shibboleth Authentication 8
Class ShibAuthSubscriber.
@package Drupal\shib_auth\EventSubscriber
Hierarchy
- class \Drupal\shib_auth\EventSubscriber\ShibAuthSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of ShibAuthSubscriber
1 string reference to 'ShibAuthSubscriber'
1 service uses ShibAuthSubscriber
File
- src/
EventSubscriber/ ShibAuthSubscriber.php, line 19
Namespace
Drupal\shib_auth\EventSubscriberView source
class ShibAuthSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* @var \Drupal\shib_auth\Login\LoginHandler
*/
private $lh;
/**
* @var MessengerInterface
*/
private $messenger;
/**
* ShibAuthSubscriber constructor.
*
* @param \Drupal\shib_auth\Login\LoginHandler $lh
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
*/
public function __construct(LoginHandler $lh, MessengerInterface $messenger) {
$this->lh = $lh;
$this->messenger = $messenger;
}
/**
* Show debug messages, if needed.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
*/
public function checkForShibbolethDebug(GetResponseEvent $event) {
$config = \Drupal::config('shib_auth.shibbolethsettings');
if (!$config
->get('enable_debug_mode')) {
// Debugging is off-- bail.
return;
}
$patterns = '';
if ($path_prefix = $config
->get('debug_prefix_path')) {
$patterns = $path_prefix . "\n" . $path_prefix . '*';
}
$current_path = \Drupal::service('path.current')
->getPath();
if ($patterns && !\Drupal::service('path.matcher')
->matchPath($current_path, $patterns)) {
// Path doesn't match-- bail.
return;
}
$tags = [
'pre',
'b',
'br',
];
$debug_message = Xss::filter('<b>' . $this
->t('Shibboleth debug information') . '</b>', $tags);
$rendered_message = Markup::create($debug_message);
$this->messenger
->addStatus($rendered_message);
$current_user = \Drupal::currentUser();
if ($current_user
->id()) {
$user_info = [
'uid' => $current_user
->id(),
'name' => $current_user
->getAccountName(),
'mail' => $current_user
->getEmail(),
'roles' => $current_user
->getRoles(),
];
$debug_message = Xss::filter('<b>Drupal::currentUser():</b><br/><pre>' . print_r($user_info, TRUE) . '</pre>', $tags);
$rendered_message = Markup::create($debug_message);
$this->messenger
->addStatus($rendered_message);
}
// Show $_SESSION variables.
// Work around that drupal_set_message() keeps previous messages in $_SESSION.
if (!empty($_SESSION)) {
$session_copy = $_SESSION;
}
else {
$session_copy = [];
}
if (isset($session_copy['messages'])) {
unset($session_copy['messages']);
}
$debug_message = Xss::filter('<b>$_SESSION:</b><br/><pre>' . print_r($session_copy, TRUE) . '</pre>', $tags);
unset($session_copy);
$rendered_message = Markup::create($debug_message);
$this->messenger
->addStatus($rendered_message);
// Show $_SERVER variables.
$debug_message = Xss::filter('<b>$_SERVER:</b><br/><pre>' . print_r($_SERVER, TRUE) . '</pre>', $tags);
$rendered_message = Markup::create($debug_message);
$this->messenger
->addStatus($rendered_message);
// Show config settings.
$settings = $config
->getRawData();
$adv_config = \Drupal::config('shib_auth.advancedsettings');
$settings += $adv_config
->getRawData();
ksort($settings);
$debug_message = Xss::filter('<b>' . $this
->t('Module configuration') . ':</b><br/><pre>' . print_r($settings, TRUE) . '</pre>', $tags);
$rendered_message = Markup::create($debug_message);
$this->messenger
->addStatus($rendered_message);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = [
'checkForShibbolethDebug',
28,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ShibAuthSubscriber:: |
private | property | ||
ShibAuthSubscriber:: |
private | property | ||
ShibAuthSubscriber:: |
public | function | Show debug messages, if needed. | |
ShibAuthSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ShibAuthSubscriber:: |
public | function | ShibAuthSubscriber constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |