/** * Inspect if this LDAP User Backend is working as expected by probing the backend * and testing if thea uthentication is possible * * Try to bind to the backend and fetch a single user to check if: * <ul> * <li>Connection credentials are correct and the bind is possible</li> * <li>At least one user exists</li> * <li>The specified userClass has the property specified by userNameAttribute</li> * </ul> * * @return Inspection Inspection result */ public function inspect() { $result = new Inspection('Ldap User Backend'); // inspect the used connection to get more diagnostic info in case the connection is not working $result->write($this->ds->inspect()); try { try { $res = $this->select()->fetchRow(); } catch (LdapException $e) { throw new AuthenticationException('Connection not possible', $e); } $result->write('Searching for: ' . sprintf('objectClass "%s" in DN "%s" (Filter: %s)', $this->userClass, $this->baseDn ?: $this->ds->getDn(), $this->filter ?: 'None')); if ($res === false) { throw new AuthenticationException('Error, no users found in backend'); } $result->write(sprintf('%d users found in backend', $this->select()->count())); if (!isset($res->user_name)) { throw new AuthenticationException('UserNameAttribute "%s" not existing in objectClass "%s"', $this->userNameAttribute, $this->userClass); } } catch (AuthenticationException $e) { if (($previous = $e->getPrevious()) !== null) { $result->error($previous->getMessage()); } else { $result->error($e->getMessage()); } } catch (Exception $e) { $result->error(sprintf('Unable to validate authentication: %s', $e->getMessage())); } return $result; }
public function inspect() { $insp = new Inspection('Db Connection'); try { $this->getDbAdapter()->getConnection(); $config = $this->dbAdapter->getConfig(); $insp->write(sprintf('Connection to %s as %s on %s:%s successful', $config['dbname'], $config['username'], $config['host'], $config['port'])); switch ($this->dbType) { case 'mysql': $rows = $this->dbAdapter->query('SHOW VARIABLES WHERE variable_name ' . 'IN (\'version\', \'protocol_version\', \'version_compile_os\');')->fetchAll(); $sqlinsp = new Inspection('MySQL'); foreach ($rows as $row) { $sqlinsp->write($row->variable_name . ': ' . $row->value); } $insp->write($sqlinsp); break; case 'pgsql': $row = $this->dbAdapter->query('SELECT version();')->fetchAll(); $sqlinsp = new Inspection('PostgreSQL'); $sqlinsp->write($row[0]->version); $insp->write($sqlinsp); break; } } catch (Exception $e) { return $insp->error(sprintf('Connection failed %s', $e->getMessage())); } return $insp; }
/** * Inspect this object to gain extended information about its health * * @return Inspection The inspection result */ public function inspect() { $insp = new Inspection('Db User Backend'); $insp->write($this->ds->inspect()); try { $users = $this->select()->where('is_active', true)->count(); if ($users > 1) { $insp->write(sprintf('%s active users', $users)); } else { return $insp->error('0 active users', $users); } } catch (Exception $e) { $insp->error(sprintf('Query failed: %s', $e->getMessage())); } return $insp; }