From f81b903ae25c4ab7dd37e2500b52489bd18fe86d Mon Sep 17 00:00:00 2001 From: Christophe Massin Date: Tue, 15 Jul 2014 16:02:32 +0200 Subject: [PATCH] test adapter --- model/LdapAdapter.php | 160 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/model/LdapAdapter.php b/model/LdapAdapter.php index e69de29..9824fa9 100644 --- a/model/LdapAdapter.php +++ b/model/LdapAdapter.php @@ -0,0 +1,160 @@ + + * + */ +class LdapAdapter implements LoginAdapter +{ + + /** Key used to retrieve the persistence information */ + CONST KEY_VALUE_PERSISTENCE_ID = 'authLdap'; + + /** @var $username string */ + private $username; + + /** @var $password string */ + private $password; + + /** @var $configuration array $configuration */ + protected $configuration; + + /** + * @param array $configuration + */ + public function __construct(array $configuration) { + $this->configuration = $configuration; + } + + /** + * Set the credential + * + * @param string $login + * @param string $password + */ + public function setCredentials($login, $password){ + $this->username = $login; + $this->password = $password; + } + + public function authenticate() { + $adapter = new Ldap(); + $adapter->setOptions( + array($this->getConfiguration()) + ); + + $adapter->setUsername($this->getUsername()); + $adapter->setPassword($this->getPassword()); + + + $identity = $adapter->authenticate(); +$params=array(); + + + if($identity){ + $user = new AuthKeyValueUser(); + $user->setConfiguration($this->getConfiguration()); + $user->setIdentifier($params['uri']); + $user->setRoles($params[PROPERTY_USER_ROLES]); + $user->setLanguageUi($params[PROPERTY_USER_UILG]); + $user->setLanguageDefLg($params[PROPERTY_USER_DEFLG]); + $user->setUserRawParameters($params); + + return $user; + + } else { + throw new core_kernel_users_InvalidLoginException(); + } + + + } + + /** + * @param array $configuration + */ + public function setConfiguration($configuration) + { + $this->configuration = $configuration; + } + + /** + * @return array + */ + public function getConfiguration() + { + return $this->configuration; + } + + /** + * @param string $password + */ + public function setPassword($password) + { + $this->password = $password; + } + + /** + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param string $username + */ + public function setUsername($username) + { + $this->username = $username; + } + + /** + * @return string + */ + public function getUsername() + { + return $this->username; + } + + + + +} \ No newline at end of file