Refactor Authentication Code

Fix PSR, fix testing

refs #4265
This commit is contained in:
Marius Hein 2013-06-11 13:53:42 +02:00
parent 8797d3e095
commit ed53ab6c9d
6 changed files with 38 additions and 22 deletions

View File

@ -43,6 +43,7 @@ class LdapUserBackend implements UserBackend
if (empty($username) || empty($password)) { if (empty($username) || empty($password)) {
return false; return false;
} }
if (!$this->connection->testCredentials( if (!$this->connection->testCredentials(
$this->connection->fetchDN($this->selectUsername($username)), $this->connection->fetchDN($this->selectUsername($username)),
$password $password
@ -50,6 +51,7 @@ class LdapUserBackend implements UserBackend
return false; return false;
} }
$user = new User($username); $user = new User($username);
return $user; return $user;
} }
} }

View File

@ -4,7 +4,6 @@
namespace Icinga\Authentication; namespace Icinga\Authentication;
class Credentials class Credentials
{ {
protected $username; protected $username;

View File

@ -7,6 +7,8 @@ namespace Icinga\Authentication;
use Icinga\Application\Logger as Logger; use Icinga\Application\Logger as Logger;
/** /**
* Class PhpSession
*
* Standard PHP Session handling * Standard PHP Session handling
* You have to call read() first in order to start the session. If * You have to call read() first in order to start the session. If
* no parameter is given to read, the session is closed immediately * no parameter is given to read, the session is closed immediately
@ -15,7 +17,8 @@ use Icinga\Application\Logger as Logger;
* no parameter in order to auto-close it) to persist all values previously * no parameter in order to auto-close it) to persist all values previously
* set with the set() method * set with the set() method
* *
**/ * @package Icinga\Authentication
*/
class PhpSession extends Session class PhpSession extends Session
{ {
const SESSION_NAME = "Icinga2Web"; const SESSION_NAME = "Icinga2Web";
@ -32,7 +35,6 @@ class PhpSession extends Session
'hash_bits_per_character' => 5, 'hash_bits_per_character' => 5,
); );
public function __construct(array $options = null) public function __construct(array $options = null)
{ {
if ($options !== null) { if ($options !== null) {
@ -114,9 +116,11 @@ class PhpSession extends Session
$_SESSION[$key] = $value; $_SESSION[$key] = $value;
} }
if ($keepOpen) { if ($keepOpen) {
return; return null;
} }
$this->close(); $this->close();
return null;
} }
public function close() public function close()

View File

@ -8,7 +8,6 @@ abstract class Session
{ {
private $sessionValues = array(); private $sessionValues = array();
abstract public function open(); abstract public function open();
abstract public function read($keepOpen = false); abstract public function read($keepOpen = false);
abstract public function write($keepOpen = false); abstract public function write($keepOpen = false);

View File

@ -30,13 +30,22 @@ class User
private $permissions = array(); private $permissions = array();
private $groups = array(); private $groups = array();
public function __construct($username, $firstname, $lastname, $email) public function __construct($username, $firstname = null, $lastname = null, $email = null)
{ {
$this->setUsername($username); $this->setUsername($username);
if ($firstname !== null) {
$this->setFirstname($firstname); $this->setFirstname($firstname);
}
if ($lastname !== null) {
$this->setLastname($lastname); $this->setLastname($lastname);
}
if ($email !== null) {
$this->setEmail($email); $this->setEmail($email);
} }
}
public function getGroups() public function getGroups()
{ {

View File

@ -6,7 +6,10 @@ require_once("../../library/Icinga/Protocol/Statusdat/Reader.php");
require_once("../../library/Icinga/Exception/ConfigurationError.php"); require_once("../../library/Icinga/Exception/ConfigurationError.php");
use Icinga\Protocol\Statusdat\Reader as Reader; use Icinga\Protocol\Statusdat\Reader as Reader;
if (!defined('APPLICATION_PATH')) {
define("APPLICATION_PATH","./"); // TODO: test boostrap define("APPLICATION_PATH","./"); // TODO: test boostrap
}
/** /**
* *
* Test class for Reader * Test class for Reader