Ejemplo n.º 1
0
	/**
	 * Deletes the user from the LDAP directory.
	 *
	 * @param   array  $options  Optional array of options.
	 *
	 * @return  boolean  True on success or False on error.
	 *
	 * @since   2.0
	 */
	public function delete($options = array())
	{
		$this->getId(false);

		// Ensure proxy binded
		if ($this->client->bindStatus !== SHLdap::AUTH_PROXY)
		{
			if (!$this->client->proxyBind())
			{
				// Failed to map as a proxy user
				throw new RuntimeException(JText::_('LIB_SHUSERADAPTERSLDAP_ERR_10901'), 10901);
			}
		}

		$this->client->delete($this->_dn);

		$this->_dn = new RuntimeException(JText::_('LIB_SHUSERADAPTERSLDAP_ERR_10906'), 10906);

		return true;
	}
Ejemplo n.º 2
0
 /**
  * Get a user's dn by attempting to search for it in the directory.
  *
  * This method uses the query as a filter to find where the user is located in the directory
  *
  * @return  array  An array containing user DNs.
  *
  * @since   2.1
  * @throws  InvalidArgumentException  Invalid argument in config related error
  * @throws  SHLdapException           Ldap search error
  */
 private function _getDnBySearch()
 {
     // Fixes special usernames and provides simple protection against ldap injections
     $username = SHLdapHelper::escape($this->username);
     $search = str_replace(SHLdap::USERNAME_REPLACE, $username, $this->_userParams['user_query']);
     // We can either use a specific user base dn or use SHLdap's default
     $baseDn = isset($this->_userParams['user_base_dn']) && !empty($this->_userParams['user_base_dn']) ? $this->_userParams['user_base_dn'] : null;
     // Bind using the proxy user so the user can be found in the Ldap directory.
     if (!$this->client->proxyBind()) {
         // Failed to bind with proxy user
         throw new InvalidArgumentException(JText::_('LIB_SHLDAP_ERR_10322'), 10322);
     }
     // Search the directory for the user
     $result = $this->client->search($baseDn, $search, array($this->_userParams['user_uid']));
     $return = array();
     $count = $result->countEntries();
     // Store the distinguished name for each user found
     for ($i = 0; $i < $count; ++$i) {
         $return[] = $result->getValue($i, 'dn', 0);
     }
     return $return;
 }
Ejemplo n.º 3
0
 /**
  * @covers SHLdap::__get
  */
 public function testMagicGetMethod()
 {
     $user = TestsHelper::getUserCreds('shaun.maunder');
     $ldap = new SHLdap(TestsHelper::getLdapConfig(214));
     $ldap->connect();
     // Test Bind Status
     $this->assertEquals(SHLdap::AUTH_NONE, $ldap->bindStatus);
     $ldap->proxyBind();
     $this->assertEquals(SHLdap::AUTH_PROXY, $ldap->bindStatus);
     $ldap->bind('asdasdas', 'asdasdas');
     $this->assertEquals(SHLdap::AUTH_NONE, $ldap->bindStatus);
     $ldap->bind($user['dn'], $user['password']);
     $this->assertEquals(SHLdap::AUTH_USER, $ldap->bindStatus);
     // Rinse and Go
     $ldap = new SHLdap(TestsHelper::getLdapConfig(214));
     $ldap->connect();
     // Test Last User DN
     $this->assertNull($ldap->lastUserDn);
     $ldap->getUserDn($user['username'], $user['password']);
     $this->assertEquals($user['dn'], $ldap->lastUserDn);
     // Test All user Filter
     $this->assertEquals('(objectclass=user)', $ldap->allUserFilter);
     // Rinse and Go
     $ldap = new SHLdap(TestsHelper::getLdapConfig(216));
     $ldap->connect();
     // Test Key for Name Attribute
     $this->assertEquals('cn', $ldap->keyName);
     $this->assertEquals('mail', $ldap->keyEmail);
     $this->assertEquals('uid', $ldap->keyUid);
     $this->assertEquals('uid', $ldap->ldap_uid);
     // Test Information
     $this->assertEquals('ldap1.shmanic.net:389', $ldap->info);
     // Test something that doesn't exist
     $this->assertNull($ldap->doesntexist);
 }
Ejemplo n.º 4
0
 /**
  * Gets all the LDAP configs and attempts to bind with each.
  * This is presented on the dashboard.
  *
  * @return  array  Array of objects containing LDAP config information.
  *
  * @since   2.0
  */
 public function getBinds()
 {
     try {
         $results = array();
         // Get all the Ldap config IDs and Names
         $ids = SHLdapHelper::getConfigIDs();
         foreach ($ids as $name) {
             // Get this specific Ldap configuration based on name
             $config = SHLdapHelper::getConfig($name);
             $result = new stdClass();
             $result->name = $name;
             $result->host = $config->get('host');
             $result->port = $config->get('port');
             $result->connect = false;
             $ldap = new SHLdap($config);
             // Need to process the ldap formatting for the host configuration ready for a fsockopen
             $processed = str_replace(array('ldap://', 'ldaps://'), '', $config->get('host'));
             if ($pos = strpos($processed, chr(32))) {
                 $processed = substr($processed, 0, $pos);
             }
             // Check if we can open a socket to the LDAP server:port to check the connection
             if (@fsockopen($processed, $config->get('port'))) {
                 $result->connect = true;
             }
             // Attempt to connect and bind and record the result
             if ($ldap->connect()) {
                 if ($ldap->proxyBind()) {
                     $result->bind = true;
                 }
             }
             // Lets add this config to our results pool
             $results[] = $result;
         }
         return $results;
     } catch (Exception $e) {
         // We need to look for a string instead of an array on error
         return $e->getMessage();
     }
 }