16 import(
'lib.pkp.classes.plugins.AuthPlugin');
22 function register($category, $path, $mainContextId =
null) {
23 $success = parent::register($category, $path, $mainContextId);
53 return __(
'plugins.auth.ldap.displayName');
61 return __(
'plugins.auth.ldap.description');
88 if ($password !=
null) {
91 $userdn = ldap_get_dn($this->conn, $entry);
92 if ($this->
bind($userdn, $password)) {
116 $result = ldap_search($this->conn, $this->settings[
'basedn'], $this->settings[
'uid'] .
'=' . $username);
117 $exists = (ldap_count_entries($this->conn, $result) != 0);
134 $attr = ldap_get_attributes($this->conn, $entry);
151 $userdn = ldap_get_dn($this->conn, $entry);
152 if ($this->
bind($this->settings[
'managerdn'], $this->settings[
'managerpwd'])) {
155 $valid = ldap_modify($this->conn, $userdn, $attr);
172 $userdn = ldap_get_dn($this->conn, $entry);
173 if ($this->
bind($this->settings[
'managerdn'], $this->settings[
'managerpwd'])) {
174 $attr = array(
'userPassword' => $this->
encodePassword($password));
175 $valid = ldap_modify($this->conn, $userdn, $attr);
191 if ($this->
bind($this->settings[
'managerdn'], $this->settings[
'managerpwd'])) {
192 $userdn = $this->settings[
'uid'] .
'=' . $user->getUsername() .
',' . $this->settings[
'basedn'];
194 'objectclass' => array(
'top',
'person',
'organizationalPerson',
'inetorgperson'),
195 $this->settings[
'uid'] => $user->getUsername(),
196 'userPassword' => $this->encodePassword($user->getPassword())
199 $valid = ldap_add($this->conn, $userdn, $attr);
216 $userdn = ldap_get_dn($this->conn, $entry);
217 if ($this->
bind($this->settings[
'managerdn'], $this->settings[
'managerpwd'])) {
218 $valid = ldap_delete($this->conn, $userdn);
235 $this->conn = ldap_connect($this->settings[
'hostname'], (
int)$this->settings[
'port']);
236 ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3);
244 ldap_close($this->conn);
253 function bind($binddn =
null, $password =
null) {
254 if (isset($this->settings[
'sasl'])) {
256 return @ldap_sasl_bind($this->conn, $binddn, $password, $this->settings[
'saslmech'], $this->settings[
'saslrealm'], $this->settings[
'saslauthzid'], $this->settings[
'saslprop']);
258 return @ldap_bind($this->conn, $binddn, $password);
267 if ($this->
bind($this->settings[
'managerdn'], $this->settings[
'managerpwd'])) {
268 $result = ldap_search($this->conn, $this->settings[
'basedn'], $this->settings[
'uid'] .
'=' . $username);
269 if (ldap_count_entries($this->conn, $result) == 1) {
270 $entry = ldap_first_entry($this->conn, $result);
286 $site = $siteDao->getSite();
288 $attr = array_change_key_case($uattr, CASE_LOWER);
289 $givenName = @$attr[
'givenname'][0];
290 $familyName = @$attr[
'sn'][0];
291 if (!isset($familyName))
292 $familyName = @$attr[
'surname'][0];
293 $affiliation = @$attr[
'o'][0];
294 if (!isset($affiliation))
295 $affiliation = @$attr[
'organizationname'][0];
296 $email = @$attr[
'mail'][0];
298 $email = @$attr[
'email'][0];
299 $phone = @$attr[
'telephonenumber'][0];
300 $mailingAddress = @$attr[
'postaladdress'][0];
301 if (!isset($mailingAddress))
302 $mailingAddress = @$attr[
'registeredAddress'][0];
307 if (isset($givenName))
309 if (isset($familyName))
311 if (isset($affiliation))
314 $user->setEmail($email);
316 $user->setPhone($phone);
317 if (isset($mailingAddress))
318 $user->setMailingAddress($mailingAddress);
319 if (isset($biography))
321 if (isset($interests))
333 $site = $siteDao->getSite();
335 if ($user->getFullName())
336 $attr[
'cn'] = $user->getFullName();
337 if ($user->getLocalizedGivenName())
338 $attr[
'givenName'] = $user->getLocalizedGivenName();
339 if ($user->getLocalizedFamilyName())
340 $attr[
'sn'] = $user->getLocalizedFamilyName();
341 if ($user->getLocalizedAffiliation())
342 $attr[
'organizationName'] = $user->getLocalizedAffiliation();
343 if ($user->getEmail())
344 $attr[
'mail'] = $user->getEmail();
345 if ($user->getPhone())
346 $attr[
'telephoneNumber'] = $user->getPhone();
347 if ($user->getMailingAddress())
348 $attr[
'postalAddress'] = $user->getMailingAddress();
357 switch ($this->settings[
'pwhash']) {
359 return '{MD5}' . base64_encode(pack(
'H*', md5($password)));
361 $salt = pack(
'C*', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand());
362 return '{SMD5}' . base64_encode(pack(
'H*', md5($password . $salt)) . $salt);
364 return '{SHA}' . base64_encode(pack(
'H*', sha1($password)));
366 $salt = pack(
'C*', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand());
367 return '{SSHA}' . base64_encode(pack(
'H*', sha1($password . $salt)) . $salt);
369 return '{CRYPT}' . crypt($password);