Skip to content
Snippets Groups Projects
Commit d734489a authored by Anna Headley's avatar Anna Headley Committed by Demian Katz
Browse files

ChoiceAuth: store user's choice in session.

This will be useful for future things and also fixes a bug wherein login
errors were appearing when a logged-in user navigated to MyResearch/Home
parent 8d0ebd71
Branches
Tags
No related merge requests found
...@@ -79,6 +79,18 @@ class ChoiceAuth extends AbstractBase ...@@ -79,6 +79,18 @@ class ChoiceAuth extends AbstractBase
*/ */
protected $manager; protected $manager;
/**
* Session container
*
* @var \Zend\Session\Container
*/
protected $session;
public function __construct()
{
$this->session = new \Zend\Session\Container('ChoiceAuth');
}
/** /**
* Validate configuration parameters. This is a support method for getConfig(), * Validate configuration parameters. This is a support method for getConfig(),
* so the configuration MUST be accessed using $this->config; do not call * so the configuration MUST be accessed using $this->config; do not call
...@@ -131,8 +143,13 @@ class ChoiceAuth extends AbstractBase ...@@ -131,8 +143,13 @@ class ChoiceAuth extends AbstractBase
$this->password = trim($request->getPost()->get('password')); $this->password = trim($request->getPost()->get('password'));
$this->method = trim($request->getPost()->get('auth_method')); $this->method = trim($request->getPost()->get('auth_method'));
if ($this->method == '') { if ($this->method == '')
throw new AuthException('authentication_error_technical'); {
if (isset($this->session->auth_method)) {
$this->method = $this->session->auth_method;
} else {
throw new AuthException('authentication_error_technical');
}
} }
// Do the actual authentication work: // Do the actual authentication work:
...@@ -156,6 +173,9 @@ class ChoiceAuth extends AbstractBase ...@@ -156,6 +173,9 @@ class ChoiceAuth extends AbstractBase
$authenticator->setConfig($this->getConfig()); $authenticator->setConfig($this->getConfig());
try { try {
$user = $authenticator->authenticate($request); $user = $authenticator->authenticate($request);
if ($user) {
$this->session->auth_method = $this->method;
}
} catch (AuthException $exception) { } catch (AuthException $exception) {
throw $exception; throw $exception;
} }
...@@ -208,4 +228,43 @@ class ChoiceAuth extends AbstractBase ...@@ -208,4 +228,43 @@ class ChoiceAuth extends AbstractBase
} }
return $classes; return $classes;
} }
/**
* Perform cleanup at logout time.
*
* @param string $url URL to redirect user to after logging out.
*
* @return string Redirect URL (usually same as $url, but modified in
* some authentication modules).
*/
public function logout($url)
{
// clear user's login choice
unset($this->session->auth_method);
// TODO: proxy logout
// No special cleanup or URL modification needed by default.
return $url;
}
/**
* Get the URL to establish a session (needed when the internal VuFind login
* form is inadequate). Returns false when no session initiator is needed.
*
* @param string $target Full URL where external authentication method should
* send user after login (some drivers may override this).
*
* @return bool|string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getSessionInitiator($target)
{
if (isset($this->session->auth_method)) {
// if user has chosen and logged in; use that auth's method
$manager = $this->getPluginManager();
$authenticator = $manager->get($this->session->auth_method);
$authenticator->setConfig($this->getConfig());
return $authenticator->getSessionInitiator($target);
}
return false;
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment