From 035bd6fc3b00c65f2c2771819c9eed42f353745e Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 19 Dec 2012 15:20:41 +0100 Subject: [PATCH] Support Organization field in default identity (#1189) --- plugins/kolab_auth/config.inc.php.dist | 5 +-- plugins/kolab_auth/kolab_auth.php | 50 ++++++++++++++++++-------- plugins/kolab_auth/package.xml | 4 +-- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/plugins/kolab_auth/config.inc.php.dist b/plugins/kolab_auth/config.inc.php.dist index 6ddfc630..05c610b8 100644 --- a/plugins/kolab_auth/config.inc.php.dist +++ b/plugins/kolab_auth/config.inc.php.dist @@ -14,8 +14,9 @@ $rcmail_config['kolab_auth_login'] = 'email'; // If the value array contains more than one field, first non-empty will be used // Note: These aren't LDAP attributes, but field names in config // Note: If there's more than one email address, as many identities will be created -$rcmail_config['kolab_auth_name'] = array('name', 'cn'); -$rcmail_config['kolab_auth_email'] = array('email'); +$rcmail_config['kolab_auth_name'] = array('name', 'cn'); +$rcmail_config['kolab_auth_email'] = array('email'); +$rcmail_config['kolab_auth_organization'] = array('organization'); // Login and password of the admin user. Enables "Login As" feature. $rcmail_config['kolab_auth_admin_login'] = ''; diff --git a/plugins/kolab_auth/kolab_auth.php b/plugins/kolab_auth/kolab_auth.php index c25e694a..fc0158ba 100644 --- a/plugins/kolab_auth/kolab_auth.php +++ b/plugins/kolab_auth/kolab_auth.php @@ -208,7 +208,19 @@ class kolab_auth extends rcube_plugin if (!empty($this->data['user_email'])) { // addresses list is supported if (array_key_exists('email_list', $args)) { - $args['email_list'] = array_unique($this->data['user_email']); + $email_list = array_unique($this->data['user_email']); + + // add organization to the list + if (!empty($this->data['user_organization'])) { + foreach ($email_list as $idx => $email) { + $email_list[$idx] = array( + 'organization' => $this->data['user_organization'], + 'email' => $email, + ); + } + } + + $args['email_list'] = $email_list; } else { $args['user_email'] = $this->data['user_email'][0]; @@ -256,19 +268,6 @@ class kolab_auth extends rcube_plugin */ public function authenticate($args) { - $ldap = self::ldap(); - if (!$ldap || !$ldap->ready) { - $args['abort'] = true; - return $args; - } - - $rcmail = rcube::get_instance(); - $admin_login = $rcmail->config->get('kolab_auth_admin_login'); - $admin_pass = $rcmail->config->get('kolab_auth_admin_password'); - $login_attr = $rcmail->config->get('kolab_auth_login'); - $name_attr = $rcmail->config->get('kolab_auth_name'); - $email_attr = $rcmail->config->get('kolab_auth_email'); - // get username and host $host = $args['host']; $user = $args['user']; @@ -280,6 +279,12 @@ class kolab_auth extends rcube_plugin return $args; } + $ldap = self::ldap(); + if (!$ldap || !$ldap->ready) { + $args['abort'] = true; + return $args; + } + // Find user record in LDAP $record = $this->get_user_record($user, $host); @@ -288,7 +293,14 @@ class kolab_auth extends rcube_plugin return $args; } - $role_attr = $rcmail->config->get('kolab_auth_role'); + $rcmail = rcube::get_instance(); + $admin_login = $rcmail->config->get('kolab_auth_admin_login'); + $admin_pass = $rcmail->config->get('kolab_auth_admin_password'); + $login_attr = $rcmail->config->get('kolab_auth_login'); + $name_attr = $rcmail->config->get('kolab_auth_name'); + $email_attr = $rcmail->config->get('kolab_auth_email'); + $org_attr = $rcmail->config->get('kolab_auth_organization'); + $role_attr = $rcmail->config->get('kolab_auth_role'); if (!empty($role_attr) && !empty($record[$role_attr])) { $_SESSION['user_roledns'] = (array)($record[$role_attr]); @@ -389,6 +401,14 @@ class kolab_auth extends rcube_plugin $this->data['user_email'] = array_merge((array)$this->data['user_email'], (array)$email); } } + // Organization name for identity (first log in) + foreach ((array)$org_attr as $field) { + $organization = is_array($record[$field]) ? $record[$field][0] : $record[$field]; + if (!empty($organization)) { + $this->data['user_organization'] = $organization; + break; + } + } // Log "Login As" usage if (!empty($origname)) { diff --git a/plugins/kolab_auth/package.xml b/plugins/kolab_auth/package.xml index b32d3cfa..2d75d83f 100644 --- a/plugins/kolab_auth/package.xml +++ b/plugins/kolab_auth/package.xml @@ -18,9 +18,9 @@ machniak@kolabsys.com yes - 2012-12-04 + 2012-12-19 - 0.5 + 0.6 0.1