From 3199f21f296caf57f8452b13d7c441c3538642f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Mo=C3=9Fhammer?= Date: Mon, 10 Jun 2013 17:03:01 +0200 Subject: [PATCH] Added License header, removed deprecated or empty files refs #4265 --- library/Icinga/Authentication/Auth.php | 83 ------- library/Icinga/Authentication/Backend.php | 2 + .../Backend/LdapUserBackend.php | 2 + library/Icinga/Authentication/Credentials.php | 2 + .../Icinga/Authentication/LdapUserBackend.php | 57 ----- library/Icinga/Authentication/Manager.php | 3 +- library/Icinga/Authentication/PhpSession.php | 2 + library/Icinga/Authentication/Session.php | 2 + library/Icinga/Authentication/Storable.php | 203 ------------------ library/Icinga/Authentication/User.php | 2 + library/Icinga/Authentication/UserBackend.php | 3 + .../Icinga/Authentication/BackendMock.php | 3 +- .../Icinga/Authentication/CredentialsTest.php | 67 ++++++ .../Authentication/LdapUserBackendTest.php | 4 + .../Icinga/Authentication/ManagerTest.php | 3 +- .../Icinga/Authentication/PhpSessionTest.php | 2 + .../Icinga/Authentication/SessionMock.php | 3 +- 17 files changed, 96 insertions(+), 347 deletions(-) delete mode 100644 library/Icinga/Authentication/Auth.php delete mode 100644 library/Icinga/Authentication/LdapUserBackend.php delete mode 100644 library/Icinga/Authentication/Storable.php create mode 100644 test/php/library/Icinga/Authentication/CredentialsTest.php diff --git a/library/Icinga/Authentication/Auth.php b/library/Icinga/Authentication/Auth.php deleted file mode 100644 index 74ddc8024..000000000 --- a/library/Icinga/Authentication/Auth.php +++ /dev/null @@ -1,83 +0,0 @@ -session = new SessionNamespace('IcingaAuth'); - } - - public static function getInstance() - { - if (self::$instance === null) { - self::$instance = new Auth(); - } - return self::$instance; - } - - public function isAuthenticated() - { - if ($this->userInfo === null) { - if ($sessionInfo = $this->session->userInfo) { - $this->userInfo = $sessionInfo; - } - } - return is_object($this->userInfo) && ! empty($this->userInfo->username); - } - - public function getUsername() - { - $this->assertIsAuthenticated(); - return $this->userInfo->username; - } - - public function getEmail() - { - $this->assertIsAuthenticated(); - return $this->userInfo->email; - } - - public function setAuthenticatedUser(User $user) - { - $this->userInfo = (object) array( - 'username' => $user->username, - 'permissions' => $user->getPermissionList(), - 'email' => $user->email, - ); - $this->session->userInfo = $this->userInfo; - } - - public function forgetAuthentication() - { - unset($this->session->userInfo); - $this->userInfo = null; - } - - public function hasPermission($route, $flags = 0x01) - { - $this->assertBeingAuthenticated(); - if (! array_key_exists($route, $this->userInfo->permissions)) { - return false; - } - - return $this->userInfo->permissions[$route] & $flags === $flags; - } - - protected function assertIsAuthenticated() - { - if (! $this->isAuthenticated()) { - throw new Exception\ProgrammingError( - 'Cannot fetch properties of a non-authenticated user' - ); - } - } -} diff --git a/library/Icinga/Authentication/Backend.php b/library/Icinga/Authentication/Backend.php index 19534478f..24fcb6433 100644 --- a/library/Icinga/Authentication/Backend.php +++ b/library/Icinga/Authentication/Backend.php @@ -1,4 +1,6 @@ connection = new Ldap\Connection($this->config); - } - - public function hasUsername($username) - { - if (! $username) { - return false; - } - return $this->connection->fetchOne( - $this->selectUsername($username) - ) === $username; - } - - protected function stripAsterisks($string) - { - return str_replace('*', '', $string); - } - - protected function selectUsername($username) - { - return $this->connection->select() - ->from('user', array('sAMAccountName')) - ->where('sAMAccountName', $this->stripAsterisks($username)); - } - - public function authenticate($username, $password = null) - { - if (empty($username) || empty($password)) { - return false; - } - if (! $this->connection->testCredentials( - $this->connection->fetchDN($this->selectUsername($username)), - $password - )) { - return false; - } - $user = User::create( - $this, - array( - 'username' => $username, - ) - ); - return $user; - } -} diff --git a/library/Icinga/Authentication/Manager.php b/library/Icinga/Authentication/Manager.php index e1f2abe17..bd3df3425 100644 --- a/library/Icinga/Authentication/Manager.php +++ b/library/Icinga/Authentication/Manager.php @@ -1,5 +1,6 @@ - * @author Icinga-Web Team - * @package Icinga\Application - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License - */ -abstract class Storable -{ - protected $key; - - /** - * Current Storable properties - */ - protected $props; - - /** - * Default property values for this Storable - * - * All allowed properties have to be defined here, otherwise they will be - * rejected - */ - protected $defaultProps = array(); - - /** - * Properties as they have been once loaded from backend - */ - protected $storedProps = array(); - - /** - * Whether this storable has been stored in the current state - */ - protected $stored = false; - - /** - * Create a new Storable instance, with data loaded from backend - * - * You should NEVER directly use this function unless you are absolutely - * sure on what you are doing. - * - * @param Backend The backend used to load this object from - * @param Array Property array - * @return Storable - */ - public static function create(UserBackend $backend, $props = array()) - { - $class = get_called_class(); - $object = new $class($props); - return $object; - } - - /** - * Override this function for custom cross-value checks before storing it - * - * @return boolean Whether the Storable is valid - */ - public function isValid() - { - return true; - } - - /** - * The constructor is protected, you should never override it - * - * Use the available hooks for all the things you need to do at construction - * time - * - * @param Array Property array - * @return void - */ - final protected function __construct($properties = array()) - { - $this->assertKeyHasBeenDefined(); - $this->props = $this->defaultProps; - foreach ($properties as $key => $val) { - $this->set($key, $val); - } - $this->assertKeyExists(); - } - - - /** - * Get property value, fail unless it exists - * - * @param string Property name - * @return mixed - */ - public function get($key) - { - $this->assertPropertyExists($key); - return $this->props[$key]; - return $this; - } - - /** - * Set property value, fail unless it exists - * - * @param string Property name - * @param mixed New property value - * @return Storable - */ - protected function set($key, $val) - { - $this->assertPropertyExists($key); - $this->props[$key] = $val; - return $this; - } - - /** - * Getter - * - * @param string Property name - * @return mixed - */ - public function __get($key) - { - return $this->get($key); - } - - /** - * Setter - * - * @param string Property name - * @param mixed New property value - * @return void - */ - public function __set($key, $val) - { - $this->set($key, $val); - } - - /** - * Whether the given property name exist - * - * @param string Property name - * @return boolean - */ - public function __isset($key) - { - return array_key_exists($key, $this->props); - } - - /** - * Makes sure that the Storable got it's unique key - * - * @throws \Exception - * @return Storable - */ - protected function assertKeyExists() - { - return $this->assertPropertyExists($this->key); - } - - /** - * Makes sure the given property is allowed - * - * @throws \Exception - * @return Storable - */ - protected function assertPropertyExists($key) - { - if (! array_key_exists($key, $this->props)) { - throw new \Exception( - sprintf( - 'Storable (%s) has no "%s" property', - get_class($this), - $key - ) - ); - } - return $this; - } - - /** - * Makes sure that the class inheriting Storable defined it's key column - * - * @throws \Exception - * @return Storable - */ - protected function assertKeyHasBeenDefined() - { - if ($this->key === null) { - throw new \Exception( - 'Implementation error, Storable needs a valid key' - ); - } - return $this; - } -} diff --git a/library/Icinga/Authentication/User.php b/library/Icinga/Authentication/User.php index a739394a5..e3109bc1c 100644 --- a/library/Icinga/Authentication/User.php +++ b/library/Icinga/Authentication/User.php @@ -1,4 +1,6 @@ markTestIncomplete('testGetUsername is not implemented yet'); + } + + /** + * Test for Credentials::SetUsername() + * + **/ + public function testSetUsername() + { + $this->markTestIncomplete('testSetUsername is not implemented yet'); + } + + /** + * Test for Credentials::GetPassword() + * + **/ + public function testGetPassword() + { + $this->markTestIncomplete('testGetPassword is not implemented yet'); + } + + /** + * Test for Credentials::SetPassword() + * + **/ + public function testSetPassword() + { + $this->markTestIncomplete('testSetPassword is not implemented yet'); + } + + /** + * Test for Credentials::GetDomain() + * + **/ + public function testGetDomain() + { + $this->markTestIncomplete('testGetDomain is not implemented yet'); + } + + /** + * Test for Credentials::SetDomain() + * + **/ + public function testSetDomain() + { + $this->markTestIncomplete('testSetDomain is not implemented yet'); + } + +} diff --git a/test/php/library/Icinga/Authentication/LdapUserBackendTest.php b/test/php/library/Icinga/Authentication/LdapUserBackendTest.php index 4a797bedc..70c2c2132 100644 --- a/test/php/library/Icinga/Authentication/LdapUserBackendTest.php +++ b/test/php/library/Icinga/Authentication/LdapUserBackendTest.php @@ -1,6 +1,10 @@