Skip to content

Commit

Permalink
AutoLogin/Logout: Remove own session namespace
Browse files Browse the repository at this point in the history
Store data in the user and implement interface to left
backends store remote information.

fixes #6461
  • Loading branch information
mxhash committed Jul 30, 2014
1 parent 294728a commit e2c761a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
9 changes: 2 additions & 7 deletions application/controllers/AuthenticationController.php
Expand Up @@ -68,9 +68,6 @@ public function loginAction()
$authenticated = $backend->authenticate($user);
if ($authenticated === true) {
$auth->setAuthenticated($user);
$session = Session::getSession()->getNamespace('authentication');
$session->set('is_remote_user', true);
$session->write();
$this->rerenderLayout()->redirectNow($redirectUrl);
}
}
Expand Down Expand Up @@ -135,12 +132,10 @@ public function loginAction()
public function logoutAction()
{
$auth = $this->Auth();

$session = Session::getSession()->getNamespace('authentication');

$isRemoteUser = $auth->getUser()->isRemoteUser();
$auth->removeAuthorization();

if ($session->get('is_remote_user', false) === true) {
if ($isRemoteUser === true) {
$this->_helper->layout->setLayout('login');
$this->_response->setHttpResponseCode(401);
} else {
Expand Down
1 change: 1 addition & 0 deletions library/Icinga/Authentication/Backend/AutoLoginBackend.php
Expand Up @@ -53,6 +53,7 @@ public function hasUser(User $user)
{
if (isset($_SERVER['REMOTE_USER'])) {
$username = $_SERVER['REMOTE_USER'];
$user->setRemoteUserInformation($username, 'REMOTE_USER');
if ($this->stripUsernameRegexp !== null) {
$stripped = preg_replace($this->stripUsernameRegexp, '', $username);
if ($stripped !== false) {
Expand Down
6 changes: 0 additions & 6 deletions library/Icinga/Authentication/Manager.php
Expand Up @@ -30,12 +30,6 @@ class Manager
*/
private $user;

/**
* If the user was authenticated from the REMOTE_USER server variable
*
* @var Boolean
*/
private $fromRemoteUser = false;

private function __construct()
{
Expand Down
43 changes: 43 additions & 0 deletions library/Icinga/User.php
Expand Up @@ -58,6 +58,18 @@ class User
*/
protected $additionalInformation = array();

/**
* Information if the user is external authenticated
*
* Keys:
*
* 0: origin username
* 1: origin field name
*
* @var array
*/
protected $remoteUserInformation = array();

/**
* Set of permissions
*
Expand Down Expand Up @@ -401,4 +413,35 @@ public function clearMessages()
{
$this->messages = null;
}

/**
* Set additional remote user information
*
* @param stirng $username
* @param string $field
*/
public function setRemoteUserInformation($username, $field)
{
$this->remoteUserInformation = array($username, $field);
}

/**
* Get additional remote user information
*
* @return array
*/
public function getRemoteUserInformation()
{
return $this->remoteUserInformation;
}

/**
* Return true if user has remote user information set
*
* @return bool
*/
public function isRemoteUser()
{
return (count($this->remoteUserInformation)) ? true : false;
}
}

0 comments on commit e2c761a

Please sign in to comment.