basicshib preserve drupal session
The snippet can be accessed without any authentication.
Authored by
Will McCreery
this patch simply lets Drupal handle the expiration of sessions
basicshib-session-expiration-option.patch 2.65 KiB
diff --git a/src/AuthenticationHandler.php b/src/AuthenticationHandler.php
index 5f636da..a3f4add 100644
--- a/src/AuthenticationHandler.php
+++ b/src/AuthenticationHandler.php
@@ -56,6 +56,11 @@ class AuthenticationHandler implements AuthenticationHandlerInterface {
*/
private $path_validator;
+ /**
+ * @var \Drupal\Core\Config\ImmutableConfig
+ */
+ private $config;
+
/**
* AuthenticationHandler constructor.
*
@@ -96,6 +101,8 @@ class AuthenticationHandler implements AuthenticationHandlerInterface {
->get('handlers');
$this->path_validator = $path_validator;
+
+ $this->config = $config_factory->get('basicshib.settings');
}
/**
@@ -269,13 +276,17 @@ class AuthenticationHandler implements AuthenticationHandlerInterface {
return self::AUTHCHECK_IGNORE;
}
- // Authenticated user with expired shib session
$session_id = $this->attribute_mapper->getAttribute('session_id', true);
- if (!$session_id) {
- $this->terminateSession($account);
- return self::AUTHCHECK_SHIB_SESSION_EXPIRED;
+ // Authenticated user with expired shib session
+ // if applicable
+ if ($this->config->get('invalidate_drupal_session')) {
+ if (!$session_id) {
+ $this->terminateSession($account);
+ return self::AUTHCHECK_SHIB_SESSION_EXPIRED;
+ }
}
+
// Authenticated user whose tracked session id does not match the current
// session id.
if ($session_id !== $this->session_tracker->get()) {
diff --git a/src/Form/CoreSettingsForm.php b/src/Form/CoreSettingsForm.php
index 83fcd4e..40e933b 100644
--- a/src/Form/CoreSettingsForm.php
+++ b/src/Form/CoreSettingsForm.php
@@ -72,6 +72,12 @@ class CoreSettingsForm extends ConfigFormBase {
'#default_value' => $config->get('handlers')['logout'],
];
+ $form['invalidate_drupal_session'] = [
+ '#type' => 'checkbox',
+ '#title' => $this->t('Invalidate Drupal session when shibboleth session expires'),
+ '#default_value' => $config->get('invalidate_drupal_session')
+ ];
+
$form['attributes'] = [
'#type' => 'fieldset',
'#title' => $this->t('Attributes'),
@@ -188,6 +194,7 @@ class CoreSettingsForm extends ConfigFormBase {
$this->config('basicshib.settings')
->set('login_link_label', $form_state->getValue('login_link_label'))
->set('default_post_login_redirect_path', $form_state->getValue('default_post_login_redirect_path'))
+ ->set('invalidate_drupal_session', $form_state->getValue('invalidate_drupal_session'))
->set('handlers', [
'login' => $form_state->getValue('login_handler'),
'logout' => $form_state->getValue('logout_handler'),
Please register or sign in to comment