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

View File

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

View File

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

View File

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

View File

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

View File

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