add auto load config from config file

This commit is contained in:
Christophe Massin 2014-07-17 15:41:49 +02:00
parent 3a8e66c438
commit 65d4033e7b
2 changed files with 31 additions and 110 deletions

View File

@ -34,6 +34,7 @@ use core_kernel_users_InvalidLoginException;
use oat\authKeyValue\model\AuthKeyValueUser; use oat\authKeyValue\model\AuthKeyValueUser;
use oat\oatbox\user\auth\LoginAdapter; use oat\oatbox\user\auth\LoginAdapter;
use Zend\Authentication\Adapter\Ldap; use Zend\Authentication\Adapter\Ldap;
use common_persistence_Manager;
/** /**
* Adapter to authenticate users stored in the Ldap implementation * Adapter to authenticate users stored in the Ldap implementation
@ -45,7 +46,7 @@ class LdapAdapter implements LoginAdapter
{ {
/** Key used to retrieve the persistence information */ /** Key used to retrieve the persistence information */
CONST KEY_VALUE_PERSISTENCE_ID = 'authLdap'; CONST LDAP_PERSISTENCE_ID = 'authLdap';
/** @var $username string */ /** @var $username string */
private $username; private $username;
@ -56,11 +57,20 @@ class LdapAdapter implements LoginAdapter
/** @var $configuration array $configuration */ /** @var $configuration array $configuration */
protected $configuration; protected $configuration;
/**
* @var \Zend\Authentication\Adapter\Ldap
*/
protected $adapter;
/** /**
* @param array $configuration * @param array $configuration
*/ */
public function __construct(array $configuration) { public function __construct(array $configuration) {
$this->configuration = $configuration; $this->configuration = $configuration;
$this->adapter = new Ldap();
$this->adapter->setOptions($configuration['config']);
} }
/** /**
@ -75,17 +85,9 @@ class LdapAdapter implements LoginAdapter
} }
public function authenticate() { public function authenticate() {
$adapter = new Ldap();
$adapter->setOptions(
array(array( $adapter = $this->getAdapter();
'host' => '127.0.0.1',
'accountDomainName' => 'test.com',
'username' => 'cn=admin,dc=test,dc=com',
'password' => 'admin',
'baseDn' => 'OU=organisation,dc=test,dc=com',
'bindRequiresDn' => 'true',
))
);
$adapter->setUsername($this->getUsername()); $adapter->setUsername($this->getUsername());
$adapter->setPassword($this->getPassword()); $adapter->setPassword($this->getPassword());
@ -110,6 +112,23 @@ class LdapAdapter implements LoginAdapter
} }
/**
* @param \Zend\Authentication\Adapter\Ldap $adapter
*/
public function setAdapter($adapter)
{
$this->adapter = $adapter;
}
/**
* @return \Zend\Authentication\Adapter\Ldap
*/
public function getAdapter()
{
return $this->adapter;
}
/** /**
* @param array $configuration * @param array $configuration
*/ */

View File

@ -1,98 +0,0 @@
<?php
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2014 (original work) Open Assessment Technologies SA;
*
*
*/
/**
* Authentication service to access db
*
* @author christophe massin
* @package authLdap
*/
namespace oat\authLdap\model;
use common_persistence_AdvKeyValuePersistence;
class AuthLdapUserService {
const PREFIXES_KEY = 'auth';
const USER_PARAMETERS = 'parameters';
/**
* @var \common_persistence_Driver
*/
protected $driver;
public function __construct(){
$kvStore = common_persistence_AdvKeyValuePersistence::getPersistence(AuthKeyValueAdapter::KEY_VALUE_PERSISTENCE_ID);
$this->driver = $kvStore->getDriver();
}
/**
* @param $login
* @return mixed
*/
public function getUserData($login){
return $this->driver->hGetAll(AuthKeyValueUserService::PREFIXES_KEY.':'.$login);
}
/**
* @param $userLogin string
* @param $parameter string
* @return mixed
*/
public function getUserParameter($userLogin, $parameter){
return $this->driver->get(AuthKeyValueUserService::PREFIXES_KEY.':'.$userLogin.':'.$parameter);
}
/**
* @param $userLogin string user login
* @param $parameter string parameter
* @param $value mixed
*/
public function addUserParameter($userLogin, $parameter, $value){
$this->driver->set(AuthKeyValueUserService::PREFIXES_KEY.':'.$userLogin.':'.$parameter, $value);
}
/**
* @param $userLogin string
* @param $parameter string
*/
public function deleteUserParameter($userLogin, $parameter){
$this->driver->del(AuthKeyValueUserService::PREFIXES_KEY.':'.$userLogin.':'.$parameter);
}
/**
* @param $userLogin
* @param $parameter
* @param $value
*/
public function editUserParameter($userLogin, $parameter, $value){
$this->driver->set(AuthKeyValueUserService::PREFIXES_KEY.':'.$userLogin.':'.$parameter, $value);
}
}