Ejemplo n.º 1
0
 /**
  * Connect to the LDAP server. Optionally takes DN and password which
  * overwrite any credentials given in the connection DSN.
  *
  * @param  string $dn
  * @param  util.Secret $password
  * @return self $this
  * @throws peer.ConnectException
  */
 public function connect($dn = null, Secret $password = null)
 {
     static $ports = ['ldap' => 389, 'ldaps' => 636];
     if ($this->isConnected()) {
         return true;
     }
     $uri = sprintf('%s://%s:%d', $this->url->getScheme(), $this->url->getHost(), $this->url->getPort($ports[$this->url->getScheme()]));
     if (false === ($this->handle = ldap_connect($uri))) {
         throw new ConnectException('Cannot connect to ' . $uri);
     }
     foreach (array_merge(['protocol_version' => 3], $this->url->getParams()) as $option => $value) {
         $set = self::$options[$option];
         if (!$set($this->handle, $value)) {
             ldap_unbind($this->handle);
             $this->handle = null;
             throw new LDAPException('Cannot set option "' . $option . '"', ldap_errno($this->handle));
         }
     }
     if (null === $dn) {
         $result = ldap_bind($this->handle, $this->url->getUser(null), $this->url->getPassword(null));
     } else {
         $result = ldap_bind($this->handle, $dn, $password->reveal());
     }
     if (false === $result) {
         $error = ldap_errno($this->handle);
         ldap_unbind($this->handle);
         $this->handle = null;
         if (LDAP_SERVER_DOWN === $error || -1 === $error) {
             throw new ConnectException('Cannot connect to ' . $uri);
         } else {
             throw new LDAPException('Cannot bind for "' . ($user ?: $this->url->getUser(null)) . '"', $error);
         }
     }
     return $this;
 }
Ejemplo n.º 2
0
 public function useBacking_with_invalid_backing_throws_exception()
 {
     Secret::useBacking(77);
 }
Ejemplo n.º 3
0
 /**
  * Use MCRYPT backing
  */
 public function setUp()
 {
     Secret::useBacking(Secret::BACKING_MCRYPT);
 }
 /**
  * Use PLAINTEXT backing
  */
 public function setUp()
 {
     Secret::useBacking(Secret::BACKING_PLAINTEXT);
 }