* */ class LdapAdapter implements LoginAdapter { /** @var $username string */ private $username; /** @var $password string */ private $password; /** @var $configuration array $configuration */ protected $configuration; /** @var $mapping array $mapping */ protected $mapping; /** * @var \Zend\Authentication\Adapter\Ldap */ protected $adapter; /** * Instantiates Zend Ldap adapter */ public function __construct() { $this->adapter = new Ldap(); } /** * (non-PHPdoc) * @see \oat\oatbox\user\auth\LoginAdapter::setOptions() */ public function setOptions(array $options) { $this->configuration = $options; $this->adapter->setOptions($options['config']); if (isset($options['mapping'])) { $this->setMapping($options['mapping']); } } /** * Set the credential * * @param string $login * @param string $password */ public function setCredentials($login, $password){ $this->username = $login; $this->password = $password; } public function authenticate() { $adapter = $this->getAdapter(); $adapter->setUsername($this->getUsername()); $adapter->setPassword($this->getPassword()); $result = $adapter->authenticate(); if($result->isValid()){ $result = $adapter->getAccountObject(); $params = get_object_vars($result); $user = new LdapUser($this->getMapping()); $user->setUserRawParameters($params); return $user; } else { throw new core_kernel_users_InvalidLoginException('User "'.$this->getUsername().'" failed LDAP authentication.'); } } /** * @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 */ public function setConfiguration($configuration) { $this->configuration = $configuration; } /** * @return array */ public function getConfiguration() { return $this->configuration; } /** * @param array $mapping */ public function setMapping($mapping) { $this->mapping = $mapping; } /** * @return array */ public function getMapping() { return $this->mapping; } /** * @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; } }