/** * Creates the user in the LDAP directory. * * @param array $options Optional array of options. * * @return SHAdapterResponseCommit Stores the add commit object and status. * * @since 2.0 */ public function create($options = array()) { if ($this->_dn instanceof Exception) { // Do not retry. Ldap configuration or user has problems. throw $this->_dn; } // 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); } } // Remove the DN if exists in the attribute list unset($this->_changes['dn']); /* * Automatically add in the username and password if they do not exist. */ if (!isset($this->_changes[$this->getUid(true)])) { $this->_changes[$this->getUid(true)] = array($this->username); } if (!isset($this->_changes['password'])) { // Do not array the password so it can be hashed later $this->_changes['password'] = $this->password; } /* * Replace any attributes that have been given generic keywords * such as username, password and put them into the ldap attribute format. */ if (isset($this->_changes['username']) && !is_array($this->_changes['username'])) { $username = $this->_changes['username']; unset($this->_changes['username']); $this->_changes[$this->getUid(true)] = array($username); } if (isset($this->_changes['email']) && !is_array($this->_changes['email'])) { $email = $this->_changes['email']; unset($this->_changes['email']); $this->_changes[$this->getEmail(true)] = array($email); } if (isset($this->_changes['fullname']) && !is_array($this->_changes['fullname'])) { $fullname = $this->_changes['fullname']; unset($this->_changes['fullname']); $this->_changes[$this->getFullname(true)] = array($fullname); } if (isset($this->_changes['password']) && !is_array($this->_changes['password'])) { $password = $this->_changes['password']; unset($this->_changes['password']); $password = $this->_genPassword($password); $this->_changes[$this->getPassword(true)] = array($password); } $response = new SHAdapterResponseCommit('add', null); try { $this->client->add($this->_dn, $this->_changes); } catch (Exception $e) { if (!isset($options['nothrow'])) { throw $e; } $response->exception = $e; $response->status = JLog::ERROR; } if (isset($this->_changes[$this->getPassword(true)])) { // NEVER audit the actual password! $this->_changes[$this->getPassword(true)] = '*********'; } $response->message = JText::sprintf( 'LIB_SHUSERADAPTERSLDAP_INFO_10922', $this->username, preg_replace('/\s+/', ' ', var_export($this->_changes, true)) ); if ($response->status !== JLog::ERROR) { $this->_changes = array(); $this->isNew = false; } return $response; }