Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function connect($username = null, $password = null)
 {
     $controllers = $this->configuration->getDomainControllers();
     $port = $this->configuration->getPort();
     // Connect to the LDAP server.
     if ($this->connection->connect($controllers, $port)) {
         $protocol = 3;
         $followReferrals = $this->configuration->getFollowReferrals();
         // Set the LDAP options.
         $this->connection->setOption(LDAP_OPT_PROTOCOL_VERSION, $protocol);
         $this->connection->setOption(LDAP_OPT_REFERRALS, $followReferrals);
         // Get the default guard instance.
         $guard = $this->getGuard();
         if (is_null($username) && is_null($password)) {
             // If both the username and password are null, we'll connect to the server
             // using the configured administrator username and password.
             $guard->bindAsAdministrator();
         } else {
             // Bind to the server with the specified username and password otherwise.
             $guard->bindUsingCredentials($username, $password);
         }
     } else {
         throw new ConnectionException('Unable to connect to LDAP server.');
     }
 }