/** * Create a user. * * If you specify a password here, this can only be performed over SSL. * * @param array $attributes The attributes to set to the user account * * @return bool|string * * @throws AdldapException */ public function create(array $attributes) { $user = new User($attributes); if ($user->hasAttribute('password') && !$this->connection->canChangePasswords()) { throw new AdldapException('SSL must be configured on your web server and enabled in the class to set passwords.'); } // Translate the schema $add = $this->adldap->ldapSchema($user->toCreateSchema()); // Additional stuff only used for adding accounts $add['cn'][0] = $user->getAttribute('display_name'); $add[$this->adldap->getUserIdKey()][0] = $user->getAttribute('username'); $add['objectclass'][0] = 'top'; $add['objectclass'][1] = 'person'; $add['objectclass'][2] = 'organizationalPerson'; $add['objectclass'][3] = 'user'; // Set the account control attribute $controlOptions = ['NORMAL_ACCOUNT' => true]; if (!$user->hasAttribute('enabled')) { $controlOptions['ACCOUNTDISABLE'] = true; } $add['userAccountControl'][0] = $this->accountControl($controlOptions); // Determine the container $attributes['container'] = array_reverse($user->getAttribute('container')); $container = 'OU=' . implode(',OU=', $user->getAttribute('container')); $dn = 'CN=' . $add['cn'][0] . ',' . $container . ',' . $this->adldap->getBaseDn(); // Add the entry return $this->connection->add($dn, $add); }
public function testUserToSchemaEmailFailure() { $attributes = $this->stubbedUserAttributes(); unset($attributes['email']); $user = new User($attributes); $this->setExpectedException('Adldap\\Exceptions\\AdldapException'); $user->toCreateSchema(); }