diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-10-24 18:26:48 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-11-20 18:31:39 +0100 |
commit | cb3af1dce294ab058162b3c4d1a0feb84465dd0b (patch) | |
tree | 7eeaf57c690e58771323e6f11e5b4a121d69fcbd /apps/user_ldap/lib | |
parent | 288acb55a0384b0608b9df0e64dcf62b1fdc7387 (diff) | |
download | nextcloud-server-cb3af1dce294ab058162b3c4d1a0feb84465dd0b.tar.gz nextcloud-server-cb3af1dce294ab058162b3c4d1a0feb84465dd0b.zip |
detect user display name attribute and return user count depending on its presence
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/wizard.php | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index 1d7701440e9..c5db4c66cc0 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -56,7 +56,7 @@ class Wizard extends LDAPUtility { Wizard::$l = \OC::$server->getL10N('user_ldap'); } $this->access = $access; - $this->result = new WizardResult; + $this->result = new WizardResult(); } public function __destruct() { @@ -120,7 +120,11 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function countUsers() { - $filter = $this->configuration->ldapUserFilter; + $this->detectUserDisplayNameAttribute(); + $filter = $this->access->combineFilterWithAnd(array( + $this->configuration->ldapUserFilter, + $this->configuration->ldapUserDisplayName . '=*' + )); $usersTotal = $this->countEntries($filter, 'users'); $usersTotal = ($usersTotal !== false) ? $usersTotal : 0; @@ -152,6 +156,47 @@ class Wizard extends LDAPUtility { } /** + * detects the display name attribute. If a setting is already present that + * returns at least one hit, the detection will be canceled. + * @return WizardResult|bool + */ + public function detectUserDisplayNameAttribute() { + if(!$this->checkRequirements(array('ldapHost', + 'ldapPort', + 'ldapBase', + 'ldapUserFilter', + ))) { + return false; + } + + $attr = $this->configuration->ldapUserDisplayName; + if($attr !== 'displayName' && !empty($attr)) { + // most likely not the default value with upper case N, + // verify it still produces a result + $count = intval($this->countUsersWithAttribute($attr)); + if($count > 0) { + //no change, but we sent it back to make sure the user interface + //is still correct, even if the ajax call was cancelled inbetween + $this->result->addChange('ldap_display_name', $attr); + return $this->result; + } + } + + // first attribute that has at least one result wins + $displayNameAttrs = array('displayname', 'cn'); + foreach ($displayNameAttrs as $attr) { + $count = intval($this->countUsersWithAttribute($attr)); + + if($count > 0) { + $this->applyFind('ldap_display_name', $attr); + return $this->result; + } + }; + + throw new \Exception(self::$t->l('Could not detect user display name attribute. Please specify it yourself in advanced ldap settings.')); + } + + /** * detects the most often used email attribute for users applying to the * user list filter. If a setting is already present that returns at least * one hit, the detection will be canceled. |