[commits] [Wiki] changed: NewLDAPHowTo

Wiki Guest wikiguest at horde.org
Mon Jul 1 20:55:40 UTC 2013


guest [186.32.221.224]  Mon, 01 Jul 2013 20:55:40 +0000

Modified page: http://wiki.horde.org/NewLDAPHowTo
New Revision:  36
Change log:  added horde 5 hooks

@@ -265,8 +265,93 @@
  }
  </code>

  This hook function also needs to be enabled in the horde configuration.
+
+++++ Horde 5
+
+I recently modified some examples to provide this H5 hook. This hook  
uses the default LDAP configuration for base DN and uid attribute  
name. It creates or updates an LDAP entry for a user via the  
Administration > Users page and does nothing from the registration  
form. It fills in the cn, sn, and givenName attributes from the  
'user_fullname' signup field and creates the mail attribute from the  
uid and the default domain specified in the Horde IMAP configuration.
+
+<code type="php">
+class Horde_Hooks {
+    public function signup_getextra()
+    {
+        return array(
+            'user_fullname' => array(
+                'label' => 'Full Name',
+                'type' => 'text',
+                'required' => true
+            ),
+        );
+    }
+
+    public function signup_addextra($userId, $extra, $password)
+    {
+        // defined but empty, work around a small horde bug
+    }
+
+    public function preauthenticate($userId, $credentials)
+    {
+        if ($credentials['authMethod'] != 'admin' ||  
!isset($credentials['password']))
+            return true;
+
+        global $conf;
+
+        $base = $conf['auth']['params']['basedn'];
+        $attr = $conf['auth']['params']['uid'];
+
+        $dn = "$attr=$userId,$base";
+        $default_domain = $conf['imap']['defaultdomain'];
+
+        $cn = $userId;
+        $sn = $userId;
+        $given = '';
+        if (isset($credentials['user_fullname'])) {
+            $cn = $credentials['user_fullname'];
+            if (($pos = strrpos($cn, ' ')) !== false) {
+                $sn = substr($cn, -$pos);
+                $given = substr($cn, 0, $pos);
+            }
+            else {
+                $sn = $cn;
+            }
+        }
+
+        // Create credentials needed by the LDAP Horde_Auth
+        // driver for adding/deleting/updating users.
+        $entry = array(
+            'dn' => $dn,
+            'cn' => $cn,
+            'givenName' =>  $given,
+            'sn' => $sn,
+            'objectclass' => array_merge(array('top'),  
$conf['auth']['params']['newuser_objectclass']),
+            'mail' => "$userId@$default_domain",
+            $attr => $userId,
+        );
+
+        // Need to check for new users (password) and edited users  
(user_pass_2)
+        if (isset($credentials['password'])) {
+            $password = $credentials['password'];
+        } elseif (isset($credentials['user_pass_2'])) {
+            $password = $credentials['user_pass_2'];
+        }
+
+        if (isset($password)) {
+            $entry['userPassword'] = Horde_Auth::getCryptedPassword(
+                    $password, '',  
$conf['auth']['params']['encryption'], true);
+        }
+
+        $credentials['ldap'] = $entry;
+
+        return array(
+            'userId' => $userId,
+            'credentials' => $credentials
+        );
+     }
+}
+
+</code>
+

  [[image hook_authldap.png]]

  TODO: Group Hooks
@@ -277,5 +362,4 @@

  * ExistingLDAPHowTo
  * LdapPref
  *  
[http://linuxwiki.riverworth.com/index.php?title=LDAP_Authentication  
General LDAP Authentication Info for Linux (Unix) and Windows (Samba)]
-



More information about the commits mailing list