* */ 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(array( '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->setPassword($this->getPassword()); $result = $adapter->authenticate(); if($result->isValid()){ $result = $adapter->getAccountObject(); $params = get_object_vars($result); $user = new LdapUser(); $user->setConfiguration($this->getConfiguration()); $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; } }