setAttribute() публичный статический Метод

Sets a LDAP attribute.
public static setAttribute ( array &$data, string $attribName, scalar | array | Traversable $value, boolean $append = false ) : void
$data array
$attribName string
$value scalar | array | Traversable
$append boolean
Результат void
Пример #1
0
 public function testChangePasswordWithUserAccountActiveDirectory()
 {
     if ($this->_getLdap()->getRootDse()->getServerType() !== Zend_Ldap_Node_RootDse::SERVER_TYPE_ACTIVEDIRECTORY) {
         $this->markTestSkipped('Test can only be run on an ActiveDirectory server');
     }
     $options = $this->_getLdap()->getOptions();
     if ($options['useSsl'] !== true && $options['useStartTls'] !== true) {
         $this->markTestSkipped('Test can only be run on an SSL or TLS secured connection');
     }
     $dn = $this->_createDn('cn=New User,');
     $data = array();
     $password = '******';
     Zend_Ldap_Attribute::setAttribute($data, 'cn', 'New User', false);
     Zend_Ldap_Attribute::setAttribute($data, 'displayName', 'New User', false);
     Zend_Ldap_Attribute::setAttribute($data, 'sAMAccountName', 'newuser', false);
     Zend_Ldap_Attribute::setAttribute($data, 'userAccountControl', 512, false);
     Zend_Ldap_Attribute::setAttribute($data, 'objectClass', 'person', true);
     Zend_Ldap_Attribute::setAttribute($data, 'objectClass', 'organizationalPerson', true);
     Zend_Ldap_Attribute::setAttribute($data, 'objectClass', 'user', true);
     Zend_Ldap_Attribute::setPassword($data, $password, Zend_Ldap_Attribute::PASSWORD_UNICODEPWD, 'unicodePwd');
     try {
         $this->_getLdap()->add($dn, $data);
         $this->_getLdap()->bind($dn, $password);
         $newPasswd = 'newpasswd';
         $newData = array();
         Zend_Ldap_Attribute::setPassword($newData, $newPasswd, Zend_Ldap_Attribute::PASSWORD_UNICODEPWD);
         $this->_getLdap()->update($dn, $newData);
         try {
             $this->_getLdap()->bind($dn, $password);
             $this->fail('Expected exception not thrown');
         } catch (Zend_Ldap_Exception $zle) {
             $message = $zle->getMessage();
             $this->assertTrue(strstr($message, 'Invalid credentials') || strstr($message, 'Server is unwilling to perform'));
         }
         $this->assertType('Zend_Ldap', $this->_getLdap()->bind($dn, $newPasswd));
         $this->_getLdap()->bind();
         $this->_getLdap()->delete($dn);
     } catch (Zend_Ldap_Exception $e) {
         $this->_getLdap()->bind();
         if ($this->_getLdap()->exists($dn)) {
             $this->_getLdap()->delete($dn);
         }
         $this->fail($e->getMessage());
     }
 }
Пример #2
0
 /**
  * Checks if the attribute can be set and sets it accordingly.
  *
  * @param  string  $name
  * @param  mixed   $value
  * @param  boolean $append
  * @throws Zend_Ldap_Exception
  */
 protected function _setAttribute($name, $value, $append)
 {
     $this->_assertChangeableAttribute($name);
     Zend_Ldap_Attribute::setAttribute($this->_currentData, $name, $value, $append);
 }
Пример #3
0
Файл: AD.php Проект: dafik/dfi
 public function updateByLogin($login, $options)
 {
     $filter = Zend_Ldap_Filter::equals('samaccountname', $login);
     $ldap = $this->getLdap();
     $users = $ldap->search($filter);
     if ($users->count() > 0) {
         $user = $users->getFirst();
         $dn = $user['dn'];
         $entry = array();
         foreach ($options as $attrib => $value) {
             Zend_Ldap_Attribute::setAttribute($entry, $attrib, $value);
         }
         $res = $ldap->update($dn, $entry);
         return $res;
     }
     return false;
 }
Пример #4
0
 public function testSetAttributeWithFilestream()
 {
     $data = array();
     $stream = fopen(dirname(__FILE__) . '/_files/AttributeTest.input.txt', 'r');
     Zend_Ldap_Attribute::setAttribute($data, 'file', $stream);
     fclose($stream);
     $this->assertEquals('String from file', $data['file'][0]);
 }
Пример #5
0
 /**
  * Sets the value for the given LDAP attribute.
  * 
  * @param array  $entry      LDAP entry
  * @param string $attribName Attribute name.
  * @param mixed  $value      Value.
  */
 protected function _setLDAPAttribute(&$entry, $attribName, $value)
 {
     $attribName = strtolower($attribName);
     Zend_Ldap_Attribute::setAttribute($entry, $attribName, $value);
 }