/** * {@inheritdoc} */ public function setConnection(ConnectionInterface $connection = null) { // We'll create a standard connection if one isn't given. $this->connection = $connection ?: new Ldap(); // Prepare the connection. $this->prepareConnection(); // Instantiate the LDAP connection. $this->connection->connect($this->configuration->get('domain_controllers'), $this->configuration->get('port')); return $this; }
/** * {@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.'); } }
/** * Connects and Binds to the Domain Controller. * * @throws AdldapException * * @return bool */ public function connect() { // Retrieve the controllers from the configuration $controllers = $this->configuration->getDomainControllers(); // Select a random domain controller $domainController = $controllers[array_rand($controllers)]; // Get the LDAP port $port = $this->configuration->getPort(); // Create the LDAP connection $this->connection->connect($domainController, $port); // Set the LDAP options $this->connection->setOption(LDAP_OPT_PROTOCOL_VERSION, 3); $this->connection->setOption(LDAP_OPT_REFERRALS, $this->configuration->getFollowReferrals()); // Authenticate to the server return $this->authenticate($this->configuration->getAdminUsername(), $this->configuration->getAdminPassword(), true); }
/** * {@inheritdoc} */ public function connect($username = null, $password = null) { // Set the beginning protocol options on the connection // if they're set in the configuration. if ($this->configuration->getUseSSL()) { $this->connection->useSSL(); } elseif ($this->configuration->getUseTLS()) { $this->connection->useTLS(); } // If we've set SSO to true, we'll make sure we check if // SSO is supported, and if so we'll bind it to // the current LDAP connection. if ($this->configuration->getUseSSO() && $this->connection->isSaslSupported()) { $this->connection->useSSO(); } // Retrieve the controllers from the configuration. $controllers = $this->configuration->getDomainControllers(); if (count($controllers) === 0) { // Make sure we have at least one domain controller. throw new AdldapException('You must specify at least one domain controller in your configuration.'); } // Select a random domain controller. $controller = $controllers[array_rand($controllers)]; // Set the controller selected in the configuration so devs // can retrieve the domain controller in use if needed. $this->configuration->setDomainControllerSelected($controller); // Get the LDAP port. $port = $this->configuration->getPort(); // Create the LDAP connection. $this->connection->connect($controller, $port); // Set the LDAP options. $this->connection->setOption(LDAP_OPT_PROTOCOL_VERSION, 3); $this->connection->setOption(LDAP_OPT_REFERRALS, $this->configuration->getFollowReferrals()); // If both the username and password are null, we'll connect to the server // using the configured administrator username and password. if (is_null($username) && is_null($password)) { return $this->bindAsAdministrator(); } // Bind as the specified user. return $this->bindUsingCredentials($username, $password); }