Example #1
0
 /**
  * Inspect if this LDAP Connection is working as expected
  *
  * Check if connection, bind and encryption is working as expected and get additional
  * information about the used
  *
  * @return  Inspection  Inspection result
  */
 public function inspect()
 {
     $insp = new Inspection('Ldap Connection');
     // Try to connect to the server with the given connection parameters
     try {
         $ds = $this->prepareNewConnection($insp);
     } catch (Exception $e) {
         if ($this->encryption === 'starttls') {
             // The Exception does not return any proper error messages in case of certificate errors. Connecting
             // by STARTTLS will usually fail at this point when the certificate is unknown,
             // so at least try to give some hints.
             $insp->write('NOTE: There might be an issue with the chosen encryption. Ensure that the LDAP-Server ' . 'supports STARTTLS and that the LDAP-Client is configured to accept its certificate.');
         }
         return $insp->error($e->getMessage());
     }
     // Try a bind-command with the given user credentials, this must not fail
     $success = @ldap_bind($ds, $this->bindDn, $this->bindPw);
     $msg = sprintf('LDAP bind to %s:%s (%s / %s)', $this->hostname, $this->port, $this->bindDn, '***');
     if (!$success) {
         // ldap_error does not return any proper error messages in case of certificate errors. Connecting
         // by LDAPS will usually fail at this point when the certificate is unknown, so at least try to give
         // some hints.
         if ($this->encryption === 'ldaps') {
             $insp->write('NOTE: There might be an issue with the chosen encryption. Ensure that the LDAP-Server ' . ' supports LDAPS and that the LDAP-Client is configured to accept its certificate.');
         }
         return $insp->error(sprintf('%s failed: %s', $msg, ldap_error($ds)));
     }
     $insp->write(sprintf($msg . ' successful'));
     // Try to execute a schema discovery this may fail if schema discovery is not supported
     try {
         $cap = LdapCapabilities::discoverCapabilities($this);
         $discovery = new Inspection('Discovery Results');
         $discovery->write($cap->getVendor());
         $version = $cap->getVersion();
         if (isset($version)) {
             $discovery->write($version);
         }
         $discovery->write('Supports STARTTLS: ' . ($cap->hasStartTls() ? 'True' : 'False'));
         $discovery->write('Default naming context: ' . $cap->getDefaultNamingContext());
         $insp->write($discovery);
     } catch (Exception $e) {
         $insp->write('Schema discovery not possible: ' . $e->getMessage());
     }
     return $insp;
 }
Example #2
0
 /**
  * Inspect if this LDAP Connection is working as expected
  *
  * Check if connection, bind and encryption is working as expected and get additional
  * information about the used
  *
  * @return  Inspection  Inspection result
  */
 public function inspect()
 {
     $insp = new Inspection('Ldap Connection');
     // Try to connect to the server with the given connection parameters
     try {
         $ds = $this->prepareNewConnection($insp);
     } catch (Exception $e) {
         return $insp->error($e->getMessage());
     }
     // Try a bind-command with the given user credentials, this must not fail
     $success = @ldap_bind($ds, $this->bindDn, $this->bindPw);
     $msg = sprintf('LDAP bind to %s:%s (%s / %s)', $this->hostname, $this->port, $this->bindDn, '***');
     if (!$success) {
         return $insp->error(sprintf('%s failed: %s', $msg, ldap_error($ds)));
     }
     $insp->write(sprintf($msg . ' successful'));
     // Try to execute a schema discovery this may fail if schema discovery is not supported
     try {
         $cap = LdapCapabilities::discoverCapabilities($this);
         $discovery = new Inspection('Discovery Results');
         $discovery->write($cap->getVendor());
         $version = $cap->getVersion();
         if (isset($version)) {
             $discovery->write($version);
         }
         $discovery->write('Supports STARTTLS: ' . ($cap->hasStartTls() ? 'True' : 'False'));
         $discovery->write('Default naming context: ' . $cap->getDefaultNamingContext());
         $insp->write($discovery);
     } catch (Exception $e) {
         $insp->write('Schema discovery not possible: ' . $e->getMessage());
     }
     return $insp;
 }