aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2013-10-10 01:21:05 +0200
committerArthur Schiwon <blizzz@owncloud.com>2013-10-17 19:13:28 +0200
commit109ddde944ae17621c4680d9c7172eb585b1626d (patch)
treee3c68ab17b4d1acbf6a8c1e866df723688bb7e0a /apps/user_ldap/lib
parent5606b60f36e0f6c34c18694a2a19f6446c6b2618 (diff)
downloadnextcloud-server-109ddde944ae17621c4680d9c7172eb585b1626d.tar.gz
nextcloud-server-109ddde944ae17621c4680d9c7172eb585b1626d.zip
Wizard: autodetection of group-member-assoc attribute
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r--apps/user_ldap/lib/wizard.php61
-rw-r--r--apps/user_ldap/lib/wizardresult.php7
2 files changed, 67 insertions, 1 deletions
diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php
index 86cf8d75af6..2538fe4a2c5 100644
--- a/apps/user_ldap/lib/wizard.php
+++ b/apps/user_ldap/lib/wizard.php
@@ -230,6 +230,26 @@ class Wizard extends LDAPUtility {
return $this->result;
}
+ public function determineGroupMemberAssoc() {
+ if(!$this->checkRequirements(array('ldapHost',
+ 'ldapPort',
+ 'ldapAgentName',
+ 'ldapAgentPassword',
+ 'ldapGroupFilter',
+ ))) {
+ return false;
+ }
+ $attribute = $this->detectGroupMemberAssoc();
+ if($attribute === false) {
+ return false;
+ }
+ $this->configuration->setConfiguration(array('ldapGroupMemberAssocAttr' => $attribute));
+ //so it will be saved on destruct
+ $this->result->markChange();
+
+ return $this->result;
+ }
+
/**
* @brief detects the available object classes
* @returns the instance's WizardResult instance
@@ -463,6 +483,47 @@ class Wizard extends LDAPUtility {
}
/**
+ * @brief tries to detect the group member association attribute which is
+ * one of 'uniqueMember', 'memberUid', 'member'
+ * @return mixed, string with the attribute name, false on error
+ */
+ private function detectGroupMemberAssoc() {
+ $possibleAttrs = array('uniqueMember', 'memberUid', 'member', 'unfugasdfasdfdfa');
+ $filter = $this->configuration->ldapGroupFilter;
+ if(empty($filter)) {
+ return false;
+ }
+ $cr = $this->getConnection();
+ if(!$cr) {
+ throw new \Excpetion('Could not connect to LDAP');
+ }
+ $base = $this->configuration->ldapBase[0];
+ $rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs);
+ if(!$this->ldap->isResource($rr)) {
+ return false;
+ }
+ $er = $this->ldap->firstEntry($cr, $rr);
+ while(is_resource($er)) {
+ $dn = $this->ldap->getDN($cr, $er);
+ $attrs = $this->ldap->getAttributes($cr, $er);
+ $result = array();
+ for($i = 0; $i < count($possibleAttrs); $i++) {
+ if(isset($attrs[$possibleAttrs[$i]])) {
+ $result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count'];
+ }
+ }
+ if(!empty($result)) {
+ natsort($result);
+ return key($result);
+ }
+
+ $er = $this->ldap->nextEntry($cr, $er);
+ }
+
+ return false;
+ }
+
+ /**
* @brief Checks whether for a given BaseDN results will be returned
* @param $base the BaseDN to test
* @return bool true on success, false otherwise
diff --git a/apps/user_ldap/lib/wizardresult.php b/apps/user_ldap/lib/wizardresult.php
index 4c3b563c0c2..542f106cad8 100644
--- a/apps/user_ldap/lib/wizardresult.php
+++ b/apps/user_ldap/lib/wizardresult.php
@@ -26,11 +26,16 @@ namespace OCA\user_ldap\lib;
class WizardResult {
protected $changes = array();
protected $options = array();
+ protected $markedChange = false;
public function addChange($key, $value) {
$this->changes[$key] = $value;
}
+ public function markChange() {
+ $this->markedChange = true;
+ }
+
public function addOptions($key, $values) {
if(!is_array($values)) {
$values = array($values);
@@ -39,7 +44,7 @@ class WizardResult {
}
public function hasChanges() {
- return count($this->changes) > 0;
+ return (count($this->changes) > 0 || $this->markedChange);
}
public function getResultArray() {