Completed
Pull Request — master (#3218)
by Vars
46:46 queued 34:29
created
apps/user_ldap/lib/Command/CreateEmptyConfig.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -33,39 +33,39 @@
 block discarded – undo
33 33
 use Symfony\Component\Console\Output\OutputInterface;
34 34
 
35 35
 class CreateEmptyConfig extends Command {
36
-	/** @var \OCA\User_LDAP\Helper */
37
-	protected $helper;
36
+    /** @var \OCA\User_LDAP\Helper */
37
+    protected $helper;
38 38
 
39
-	/**
40
-	 * @param Helper $helper
41
-	 */
42
-	public function __construct(Helper $helper) {
43
-		$this->helper = $helper;
44
-		parent::__construct();
45
-	}
39
+    /**
40
+     * @param Helper $helper
41
+     */
42
+    public function __construct(Helper $helper) {
43
+        $this->helper = $helper;
44
+        parent::__construct();
45
+    }
46 46
 
47
-	protected function configure() {
48
-		$this
49
-			->setName('ldap:create-empty-config')
50
-			->setDescription('creates an empty LDAP configuration')
51
-			->addOption(
52
-				'only-print-prefix',
53
-				'p',
54
-				InputOption::VALUE_NONE,
55
-				'outputs only the prefix'
56
-			)
57
-		;
58
-	}
47
+    protected function configure() {
48
+        $this
49
+            ->setName('ldap:create-empty-config')
50
+            ->setDescription('creates an empty LDAP configuration')
51
+            ->addOption(
52
+                'only-print-prefix',
53
+                'p',
54
+                InputOption::VALUE_NONE,
55
+                'outputs only the prefix'
56
+            )
57
+        ;
58
+    }
59 59
 
60
-	protected function execute(InputInterface $input, OutputInterface $output) {
61
-		$configPrefix = $this->helper->getNextServerConfigurationPrefix();
62
-		$configHolder = new Configuration($configPrefix);
63
-		$configHolder->saveConfiguration();
60
+    protected function execute(InputInterface $input, OutputInterface $output) {
61
+        $configPrefix = $this->helper->getNextServerConfigurationPrefix();
62
+        $configHolder = new Configuration($configPrefix);
63
+        $configHolder->saveConfiguration();
64 64
 
65
-		$prose = '';
66
-		if(!$input->getOption('only-print-prefix')) {
67
-			$prose = 'Created new configuration with configID ';
68
-		}
69
-		$output->writeln($prose . "{$configPrefix}");
70
-	}
65
+        $prose = '';
66
+        if(!$input->getOption('only-print-prefix')) {
67
+            $prose = 'Created new configuration with configID ';
68
+        }
69
+        $output->writeln($prose . "{$configPrefix}");
70
+    }
71 71
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Command/ShowConfig.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -35,77 +35,77 @@
 block discarded – undo
35 35
 use OCA\User_LDAP\Configuration;
36 36
 
37 37
 class ShowConfig extends Command {
38
-	/** @var \OCA\User_LDAP\Helper */
39
-	protected $helper;
38
+    /** @var \OCA\User_LDAP\Helper */
39
+    protected $helper;
40 40
 
41
-	/**
42
-	 * @param Helper $helper
43
-	 */
44
-	public function __construct(Helper $helper) {
45
-		$this->helper = $helper;
46
-		parent::__construct();
47
-	}
41
+    /**
42
+     * @param Helper $helper
43
+     */
44
+    public function __construct(Helper $helper) {
45
+        $this->helper = $helper;
46
+        parent::__construct();
47
+    }
48 48
 
49
-	protected function configure() {
50
-		$this
51
-			->setName('ldap:show-config')
52
-			->setDescription('shows the LDAP configuration')
53
-			->addArgument(
54
-					'configID',
55
-					InputArgument::OPTIONAL,
56
-					'will show the configuration of the specified id'
57
-				     )
58
-			->addOption(
59
-					'show-password',
60
-					null,
61
-					InputOption::VALUE_NONE,
62
-					'show ldap bind password'
63
-				     )
64
-		;
65
-	}
49
+    protected function configure() {
50
+        $this
51
+            ->setName('ldap:show-config')
52
+            ->setDescription('shows the LDAP configuration')
53
+            ->addArgument(
54
+                    'configID',
55
+                    InputArgument::OPTIONAL,
56
+                    'will show the configuration of the specified id'
57
+                        )
58
+            ->addOption(
59
+                    'show-password',
60
+                    null,
61
+                    InputOption::VALUE_NONE,
62
+                    'show ldap bind password'
63
+                        )
64
+        ;
65
+    }
66 66
 
67
-	protected function execute(InputInterface $input, OutputInterface $output) {
68
-		$availableConfigs = $this->helper->getServerConfigurationPrefixes();
69
-		$configID = $input->getArgument('configID');
70
-		if(!is_null($configID)) {
71
-			$configIDs[] = $configID;
72
-			if(!in_array($configIDs[0], $availableConfigs)) {
73
-				$output->writeln("Invalid configID");
74
-				return;
75
-			}
76
-		} else {
77
-			$configIDs = $availableConfigs;
78
-		}
67
+    protected function execute(InputInterface $input, OutputInterface $output) {
68
+        $availableConfigs = $this->helper->getServerConfigurationPrefixes();
69
+        $configID = $input->getArgument('configID');
70
+        if(!is_null($configID)) {
71
+            $configIDs[] = $configID;
72
+            if(!in_array($configIDs[0], $availableConfigs)) {
73
+                $output->writeln("Invalid configID");
74
+                return;
75
+            }
76
+        } else {
77
+            $configIDs = $availableConfigs;
78
+        }
79 79
 
80
-		$this->renderConfigs($configIDs, $output, $input->getOption('show-password'));
81
-	}
80
+        $this->renderConfigs($configIDs, $output, $input->getOption('show-password'));
81
+    }
82 82
 
83
-	/**
84
-	 * prints the LDAP configuration(s)
85
-	 * @param string[] configID(s)
86
-	 * @param OutputInterface $output
87
-	 * @param bool $withPassword      Set to TRUE to show plaintext passwords in output
88
-	 */
89
-	protected function renderConfigs($configIDs, $output, $withPassword) {
90
-		foreach($configIDs as $id) {
91
-			$configHolder = new Configuration($id);
92
-			$configuration = $configHolder->getConfiguration();
93
-			ksort($configuration);
83
+    /**
84
+     * prints the LDAP configuration(s)
85
+     * @param string[] configID(s)
86
+     * @param OutputInterface $output
87
+     * @param bool $withPassword      Set to TRUE to show plaintext passwords in output
88
+     */
89
+    protected function renderConfigs($configIDs, $output, $withPassword) {
90
+        foreach($configIDs as $id) {
91
+            $configHolder = new Configuration($id);
92
+            $configuration = $configHolder->getConfiguration();
93
+            ksort($configuration);
94 94
 
95
-			$table = new Table($output);
96
-			$table->setHeaders(array('Configuration', $id));
97
-			$rows = array();
98
-			foreach($configuration as $key => $value) {
99
-				if($key === 'ldapAgentPassword' && !$withPassword) {
100
-					$value = '***';
101
-				}
102
-				if(is_array($value)) {
103
-					$value = implode(';', $value);
104
-				}
105
-				$rows[] = array($key, $value);
106
-			}
107
-			$table->setRows($rows);
108
-			$table->render($output);
109
-		}
110
-	}
95
+            $table = new Table($output);
96
+            $table->setHeaders(array('Configuration', $id));
97
+            $rows = array();
98
+            foreach($configuration as $key => $value) {
99
+                if($key === 'ldapAgentPassword' && !$withPassword) {
100
+                    $value = '***';
101
+                }
102
+                if(is_array($value)) {
103
+                    $value = implode(';', $value);
104
+                }
105
+                $rows[] = array($key, $value);
106
+            }
107
+            $table->setRows($rows);
108
+            $table->render($output);
109
+        }
110
+    }
111 111
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/LDAPUtility.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@
 block discarded – undo
26 26
 namespace OCA\User_LDAP;
27 27
 
28 28
 abstract class LDAPUtility {
29
-	protected $ldap;
29
+    protected $ldap;
30 30
 
31
-	/**
32
-	 * constructor, make sure the subclasses call this one!
33
-	 * @param ILDAPWrapper $ldapWrapper an instance of an ILDAPWrapper
34
-	 */
35
-	public function __construct(ILDAPWrapper $ldapWrapper) {
36
-		$this->ldap = $ldapWrapper;
37
-	}
31
+    /**
32
+     * constructor, make sure the subclasses call this one!
33
+     * @param ILDAPWrapper $ldapWrapper an instance of an ILDAPWrapper
34
+     */
35
+    public function __construct(ILDAPWrapper $ldapWrapper) {
36
+        $this->ldap = $ldapWrapper;
37
+    }
38 38
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Settings/Section.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -28,55 +28,55 @@
 block discarded – undo
28 28
 use OCP\Settings\IIconSection;
29 29
 
30 30
 class Section implements IIconSection {
31
-	/** @var IL10N */
32
-	private $l;
33
-	/** @var IURLGenerator */
34
-	private $url;
31
+    /** @var IL10N */
32
+    private $l;
33
+    /** @var IURLGenerator */
34
+    private $url;
35 35
 
36
-	/**
37
-	 * @param IURLGenerator $url
38
-	 * @param IL10N $l
39
-	 */
40
-	public function __construct(IURLGenerator $url, IL10N $l) {
41
-		$this->url = $url;
42
-		$this->l = $l;
43
-	}
36
+    /**
37
+     * @param IURLGenerator $url
38
+     * @param IL10N $l
39
+     */
40
+    public function __construct(IURLGenerator $url, IL10N $l) {
41
+        $this->url = $url;
42
+        $this->l = $l;
43
+    }
44 44
 
45
-	/**
46
-	 * returns the ID of the section. It is supposed to be a lower case string,
47
-	 * e.g. 'ldap'
48
-	 *
49
-	 * @returns string
50
-	 */
51
-	public function getID() {
52
-		return 'ldap';
53
-	}
45
+    /**
46
+     * returns the ID of the section. It is supposed to be a lower case string,
47
+     * e.g. 'ldap'
48
+     *
49
+     * @returns string
50
+     */
51
+    public function getID() {
52
+        return 'ldap';
53
+    }
54 54
 
55
-	/**
56
-	 * returns the translated name as it should be displayed, e.g. 'LDAP / AD
57
-	 * integration'. Use the L10N service to translate it.
58
-	 *
59
-	 * @return string
60
-	 */
61
-	public function getName() {
62
-		return $this->l->t('LDAP / AD integration');
63
-	}
55
+    /**
56
+     * returns the translated name as it should be displayed, e.g. 'LDAP / AD
57
+     * integration'. Use the L10N service to translate it.
58
+     *
59
+     * @return string
60
+     */
61
+    public function getName() {
62
+        return $this->l->t('LDAP / AD integration');
63
+    }
64 64
 
65
-	/**
66
-	 * @return int whether the form should be rather on the top or bottom of
67
-	 * the settings navigation. The sections are arranged in ascending order of
68
-	 * the priority values. It is required to return a value between 0 and 99.
69
-	 *
70
-	 * E.g.: 70
71
-	 */
72
-	public function getPriority() {
73
-		return 25;
74
-	}
65
+    /**
66
+     * @return int whether the form should be rather on the top or bottom of
67
+     * the settings navigation. The sections are arranged in ascending order of
68
+     * the priority values. It is required to return a value between 0 and 99.
69
+     *
70
+     * E.g.: 70
71
+     */
72
+    public function getPriority() {
73
+        return 25;
74
+    }
75 75
 
76
-	/**
77
-	 * {@inheritdoc}
78
-	 */
79
-	public function getIcon() {
80
-		return $this->url->imagePath('user_ldap', 'app-dark.svg');
81
-	}
76
+    /**
77
+     * {@inheritdoc}
78
+     */
79
+    public function getIcon() {
80
+        return $this->url->imagePath('user_ldap', 'app-dark.svg');
81
+    }
82 82
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Settings/Admin.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -31,59 +31,59 @@
 block discarded – undo
31 31
 use OCP\Template;
32 32
 
33 33
 class Admin implements ISettings {
34
-	/** @var IL10N */
35
-	private $l;
34
+    /** @var IL10N */
35
+    private $l;
36 36
 
37
-	/**
38
-	 * @param IL10N $l
39
-	 */
40
-	public function __construct(IL10N $l) {
41
-		$this->l = $l;
42
-	}
37
+    /**
38
+     * @param IL10N $l
39
+     */
40
+    public function __construct(IL10N $l) {
41
+        $this->l = $l;
42
+    }
43 43
 
44
-	/**
45
-	 * @return TemplateResponse
46
-	 */
47
-	public function getForm() {
48
-		$helper = new Helper(\OC::$server->getConfig());
49
-		$prefixes = $helper->getServerConfigurationPrefixes();
50
-		$hosts = $helper->getServerConfigurationHosts();
44
+    /**
45
+     * @return TemplateResponse
46
+     */
47
+    public function getForm() {
48
+        $helper = new Helper(\OC::$server->getConfig());
49
+        $prefixes = $helper->getServerConfigurationPrefixes();
50
+        $hosts = $helper->getServerConfigurationHosts();
51 51
 
52
-		$wControls = new Template('user_ldap', 'part.wizardcontrols');
53
-		$wControls = $wControls->fetchPage();
54
-		$sControls = new Template('user_ldap', 'part.settingcontrols');
55
-		$sControls = $sControls->fetchPage();
52
+        $wControls = new Template('user_ldap', 'part.wizardcontrols');
53
+        $wControls = $wControls->fetchPage();
54
+        $sControls = new Template('user_ldap', 'part.settingcontrols');
55
+        $sControls = $sControls->fetchPage();
56 56
 
57
-		$parameters['serverConfigurationPrefixes'] = $prefixes;
58
-		$parameters['serverConfigurationHosts'] = $hosts;
59
-		$parameters['settingControls'] = $sControls;
60
-		$parameters['wizardControls'] = $wControls;
57
+        $parameters['serverConfigurationPrefixes'] = $prefixes;
58
+        $parameters['serverConfigurationHosts'] = $hosts;
59
+        $parameters['settingControls'] = $sControls;
60
+        $parameters['wizardControls'] = $wControls;
61 61
 
62
-		// assign default values
63
-		$config = new Configuration('', false);
64
-		$defaults = $config->getDefaults();
65
-		foreach($defaults as $key => $default) {
66
-			$parameters[$key.'_default'] = $default;
67
-		}
62
+        // assign default values
63
+        $config = new Configuration('', false);
64
+        $defaults = $config->getDefaults();
65
+        foreach($defaults as $key => $default) {
66
+            $parameters[$key.'_default'] = $default;
67
+        }
68 68
 
69
-		return new TemplateResponse('user_ldap', 'settings', $parameters);
70
-	}
69
+        return new TemplateResponse('user_ldap', 'settings', $parameters);
70
+    }
71 71
 
72
-	/**
73
-	 * @return string the section ID, e.g. 'sharing'
74
-	 */
75
-	public function getSection() {
76
-		return 'ldap';
77
-	}
72
+    /**
73
+     * @return string the section ID, e.g. 'sharing'
74
+     */
75
+    public function getSection() {
76
+        return 'ldap';
77
+    }
78 78
 
79
-	/**
80
-	 * @return int whether the form should be rather on the top or bottom of
81
-	 * the admin section. The forms are arranged in ascending order of the
82
-	 * priority values. It is required to return a value between 0 and 100.
83
-	 *
84
-	 * E.g.: 70
85
-	 */
86
-	public function getPriority() {
87
-		return 5;
88
-	}
79
+    /**
80
+     * @return int whether the form should be rather on the top or bottom of
81
+     * the admin section. The forms are arranged in ascending order of the
82
+     * priority values. It is required to return a value between 0 and 100.
83
+     *
84
+     * E.g.: 70
85
+     */
86
+    public function getPriority() {
87
+        return 5;
88
+    }
89 89
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User_Proxy.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -33,285 +33,285 @@
 block discarded – undo
33 33
 use OCP\IConfig;
34 34
 
35 35
 class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP {
36
-	private $backends = array();
37
-	private $refBackend = null;
36
+    private $backends = array();
37
+    private $refBackend = null;
38 38
 
39
-	/**
40
-	 * Constructor
41
-	 * @param array $serverConfigPrefixes array containing the config Prefixes
42
-	 */
43
-	public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) {
44
-		parent::__construct($ldap);
45
-		foreach($serverConfigPrefixes as $configPrefix) {
46
-			$this->backends[$configPrefix] =
47
-				new User_LDAP($this->getAccess($configPrefix), $ocConfig);
48
-			if(is_null($this->refBackend)) {
49
-				$this->refBackend = &$this->backends[$configPrefix];
50
-			}
51
-		}
52
-	}
39
+    /**
40
+     * Constructor
41
+     * @param array $serverConfigPrefixes array containing the config Prefixes
42
+     */
43
+    public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) {
44
+        parent::__construct($ldap);
45
+        foreach($serverConfigPrefixes as $configPrefix) {
46
+            $this->backends[$configPrefix] =
47
+                new User_LDAP($this->getAccess($configPrefix), $ocConfig);
48
+            if(is_null($this->refBackend)) {
49
+                $this->refBackend = &$this->backends[$configPrefix];
50
+            }
51
+        }
52
+    }
53 53
 
54
-	/**
55
-	 * Tries the backends one after the other until a positive result is returned from the specified method
56
-	 * @param string $uid the uid connected to the request
57
-	 * @param string $method the method of the user backend that shall be called
58
-	 * @param array $parameters an array of parameters to be passed
59
-	 * @return mixed the result of the method or false
60
-	 */
61
-	protected function walkBackends($uid, $method, $parameters) {
62
-		$cacheKey = $this->getUserCacheKey($uid);
63
-		foreach($this->backends as $configPrefix => $backend) {
64
-			$instance = $backend;
65
-			if(!method_exists($instance, $method)
66
-				&& method_exists($this->getAccess($configPrefix), $method)) {
67
-				$instance = $this->getAccess($configPrefix);
68
-			}
69
-			if($result = call_user_func_array(array($instance, $method), $parameters)) {
70
-				$this->writeToCache($cacheKey, $configPrefix);
71
-				return $result;
72
-			}
73
-		}
74
-		return false;
75
-	}
54
+    /**
55
+     * Tries the backends one after the other until a positive result is returned from the specified method
56
+     * @param string $uid the uid connected to the request
57
+     * @param string $method the method of the user backend that shall be called
58
+     * @param array $parameters an array of parameters to be passed
59
+     * @return mixed the result of the method or false
60
+     */
61
+    protected function walkBackends($uid, $method, $parameters) {
62
+        $cacheKey = $this->getUserCacheKey($uid);
63
+        foreach($this->backends as $configPrefix => $backend) {
64
+            $instance = $backend;
65
+            if(!method_exists($instance, $method)
66
+                && method_exists($this->getAccess($configPrefix), $method)) {
67
+                $instance = $this->getAccess($configPrefix);
68
+            }
69
+            if($result = call_user_func_array(array($instance, $method), $parameters)) {
70
+                $this->writeToCache($cacheKey, $configPrefix);
71
+                return $result;
72
+            }
73
+        }
74
+        return false;
75
+    }
76 76
 
77
-	/**
78
-	 * Asks the backend connected to the server that supposely takes care of the uid from the request.
79
-	 * @param string $uid the uid connected to the request
80
-	 * @param string $method the method of the user backend that shall be called
81
-	 * @param array $parameters an array of parameters to be passed
82
-	 * @param mixed $passOnWhen the result matches this variable
83
-	 * @return mixed the result of the method or false
84
-	 */
85
-	protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) {
86
-		$cacheKey = $this->getUserCacheKey($uid);
87
-		$prefix = $this->getFromCache($cacheKey);
88
-		//in case the uid has been found in the past, try this stored connection first
89
-		if(!is_null($prefix)) {
90
-			if(isset($this->backends[$prefix])) {
91
-				$instance = $this->backends[$prefix];
92
-				if(!method_exists($instance, $method)
93
-					&& method_exists($this->getAccess($prefix), $method)) {
94
-					$instance = $this->getAccess($prefix);
95
-				}
96
-				$result = call_user_func_array(array($instance, $method), $parameters);
97
-				if($result === $passOnWhen) {
98
-					//not found here, reset cache to null if user vanished
99
-					//because sometimes methods return false with a reason
100
-					$userExists = call_user_func_array(
101
-						array($this->backends[$prefix], 'userExists'),
102
-						array($uid)
103
-					);
104
-					if(!$userExists) {
105
-						$this->writeToCache($cacheKey, null);
106
-					}
107
-				}
108
-				return $result;
109
-			}
110
-		}
111
-		return false;
112
-	}
77
+    /**
78
+     * Asks the backend connected to the server that supposely takes care of the uid from the request.
79
+     * @param string $uid the uid connected to the request
80
+     * @param string $method the method of the user backend that shall be called
81
+     * @param array $parameters an array of parameters to be passed
82
+     * @param mixed $passOnWhen the result matches this variable
83
+     * @return mixed the result of the method or false
84
+     */
85
+    protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) {
86
+        $cacheKey = $this->getUserCacheKey($uid);
87
+        $prefix = $this->getFromCache($cacheKey);
88
+        //in case the uid has been found in the past, try this stored connection first
89
+        if(!is_null($prefix)) {
90
+            if(isset($this->backends[$prefix])) {
91
+                $instance = $this->backends[$prefix];
92
+                if(!method_exists($instance, $method)
93
+                    && method_exists($this->getAccess($prefix), $method)) {
94
+                    $instance = $this->getAccess($prefix);
95
+                }
96
+                $result = call_user_func_array(array($instance, $method), $parameters);
97
+                if($result === $passOnWhen) {
98
+                    //not found here, reset cache to null if user vanished
99
+                    //because sometimes methods return false with a reason
100
+                    $userExists = call_user_func_array(
101
+                        array($this->backends[$prefix], 'userExists'),
102
+                        array($uid)
103
+                    );
104
+                    if(!$userExists) {
105
+                        $this->writeToCache($cacheKey, null);
106
+                    }
107
+                }
108
+                return $result;
109
+            }
110
+        }
111
+        return false;
112
+    }
113 113
 
114
-	/**
115
-	 * Check if backend implements actions
116
-	 * @param int $actions bitwise-or'ed actions
117
-	 * @return boolean
118
-	 *
119
-	 * Returns the supported actions as int to be
120
-	 * compared with OC_USER_BACKEND_CREATE_USER etc.
121
-	 */
122
-	public function implementsActions($actions) {
123
-		//it's the same across all our user backends obviously
124
-		return $this->refBackend->implementsActions($actions);
125
-	}
114
+    /**
115
+     * Check if backend implements actions
116
+     * @param int $actions bitwise-or'ed actions
117
+     * @return boolean
118
+     *
119
+     * Returns the supported actions as int to be
120
+     * compared with OC_USER_BACKEND_CREATE_USER etc.
121
+     */
122
+    public function implementsActions($actions) {
123
+        //it's the same across all our user backends obviously
124
+        return $this->refBackend->implementsActions($actions);
125
+    }
126 126
 
127
-	/**
128
-	 * Backend name to be shown in user management
129
-	 * @return string the name of the backend to be shown
130
-	 */
131
-	public function getBackendName() {
132
-		return $this->refBackend->getBackendName();
133
-	}
127
+    /**
128
+     * Backend name to be shown in user management
129
+     * @return string the name of the backend to be shown
130
+     */
131
+    public function getBackendName() {
132
+        return $this->refBackend->getBackendName();
133
+    }
134 134
 
135
-	/**
136
-	 * Get a list of all users
137
-	 *
138
-	 * @param string $search
139
-	 * @param null|int $limit
140
-	 * @param null|int $offset
141
-	 * @return string[] an array of all uids
142
-	 */
143
-	public function getUsers($search = '', $limit = 10, $offset = 0) {
144
-		//we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends
145
-		$users = array();
146
-		foreach($this->backends as $backend) {
147
-			$backendUsers = $backend->getUsers($search, $limit, $offset);
148
-			if (is_array($backendUsers)) {
149
-				$users = array_merge($users, $backendUsers);
150
-			}
151
-		}
152
-		return $users;
153
-	}
135
+    /**
136
+     * Get a list of all users
137
+     *
138
+     * @param string $search
139
+     * @param null|int $limit
140
+     * @param null|int $offset
141
+     * @return string[] an array of all uids
142
+     */
143
+    public function getUsers($search = '', $limit = 10, $offset = 0) {
144
+        //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends
145
+        $users = array();
146
+        foreach($this->backends as $backend) {
147
+            $backendUsers = $backend->getUsers($search, $limit, $offset);
148
+            if (is_array($backendUsers)) {
149
+                $users = array_merge($users, $backendUsers);
150
+            }
151
+        }
152
+        return $users;
153
+    }
154 154
 
155
-	/**
156
-	 * check if a user exists
157
-	 * @param string $uid the username
158
-	 * @return boolean
159
-	 */
160
-	public function userExists($uid) {
161
-		return $this->handleRequest($uid, 'userExists', array($uid));
162
-	}
155
+    /**
156
+     * check if a user exists
157
+     * @param string $uid the username
158
+     * @return boolean
159
+     */
160
+    public function userExists($uid) {
161
+        return $this->handleRequest($uid, 'userExists', array($uid));
162
+    }
163 163
 
164
-	/**
165
-	 * check if a user exists on LDAP
166
-	 * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user
167
-	 * name or an instance of that user
168
-	 * @return boolean
169
-	 */
170
-	public function userExistsOnLDAP($user) {
171
-		$id = ($user instanceof User) ? $user->getUsername() : $user;
172
-		return $this->handleRequest($id, 'userExistsOnLDAP', array($user));
173
-	}
164
+    /**
165
+     * check if a user exists on LDAP
166
+     * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user
167
+     * name or an instance of that user
168
+     * @return boolean
169
+     */
170
+    public function userExistsOnLDAP($user) {
171
+        $id = ($user instanceof User) ? $user->getUsername() : $user;
172
+        return $this->handleRequest($id, 'userExistsOnLDAP', array($user));
173
+    }
174 174
 
175
-	/**
176
-	 * Check if the password is correct
177
-	 * @param string $uid The username
178
-	 * @param string $password The password
179
-	 * @return bool
180
-	 *
181
-	 * Check if the password is correct without logging in the user
182
-	 */
183
-	public function checkPassword($uid, $password) {
184
-		return $this->handleRequest($uid, 'checkPassword', array($uid, $password));
185
-	}
175
+    /**
176
+     * Check if the password is correct
177
+     * @param string $uid The username
178
+     * @param string $password The password
179
+     * @return bool
180
+     *
181
+     * Check if the password is correct without logging in the user
182
+     */
183
+    public function checkPassword($uid, $password) {
184
+        return $this->handleRequest($uid, 'checkPassword', array($uid, $password));
185
+    }
186 186
 
187
-	/**
188
-	 * returns the username for the given login name, if available
189
-	 *
190
-	 * @param string $loginName
191
-	 * @return string|false
192
-	 */
193
-	public function loginName2UserName($loginName) {
194
-		$id = 'LOGINNAME,' . $loginName;
195
-		return $this->handleRequest($id, 'loginName2UserName', array($loginName));
196
-	}
187
+    /**
188
+     * returns the username for the given login name, if available
189
+     *
190
+     * @param string $loginName
191
+     * @return string|false
192
+     */
193
+    public function loginName2UserName($loginName) {
194
+        $id = 'LOGINNAME,' . $loginName;
195
+        return $this->handleRequest($id, 'loginName2UserName', array($loginName));
196
+    }
197 197
 	
198
-	/**
199
-	 * returns the username for the given LDAP DN, if available
200
-	 *
201
-	 * @param string $dn
202
-	 * @return string|false with the username
203
-	 */
204
-	public function dn2UserName($dn) {
205
-		$id = 'DN,' . $dn;
206
-		return $this->handleRequest($id, 'dn2UserName', array($dn));
207
-	}
198
+    /**
199
+     * returns the username for the given LDAP DN, if available
200
+     *
201
+     * @param string $dn
202
+     * @return string|false with the username
203
+     */
204
+    public function dn2UserName($dn) {
205
+        $id = 'DN,' . $dn;
206
+        return $this->handleRequest($id, 'dn2UserName', array($dn));
207
+    }
208 208
 
209
-	/**
210
-	 * get the user's home directory
211
-	 * @param string $uid the username
212
-	 * @return boolean
213
-	 */
214
-	public function getHome($uid) {
215
-		return $this->handleRequest($uid, 'getHome', array($uid));
216
-	}
209
+    /**
210
+     * get the user's home directory
211
+     * @param string $uid the username
212
+     * @return boolean
213
+     */
214
+    public function getHome($uid) {
215
+        return $this->handleRequest($uid, 'getHome', array($uid));
216
+    }
217 217
 
218
-	/**
219
-	 * get display name of the user
220
-	 * @param string $uid user ID of the user
221
-	 * @return string display name
222
-	 */
223
-	public function getDisplayName($uid) {
224
-		return $this->handleRequest($uid, 'getDisplayName', array($uid));
225
-	}
218
+    /**
219
+     * get display name of the user
220
+     * @param string $uid user ID of the user
221
+     * @return string display name
222
+     */
223
+    public function getDisplayName($uid) {
224
+        return $this->handleRequest($uid, 'getDisplayName', array($uid));
225
+    }
226 226
 
227
-	/**
228
-	 * checks whether the user is allowed to change his avatar in ownCloud
229
-	 * @param string $uid the ownCloud user name
230
-	 * @return boolean either the user can or cannot
231
-	 */
232
-	public function canChangeAvatar($uid) {
233
-		return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true);
234
-	}
227
+    /**
228
+     * checks whether the user is allowed to change his avatar in ownCloud
229
+     * @param string $uid the ownCloud user name
230
+     * @return boolean either the user can or cannot
231
+     */
232
+    public function canChangeAvatar($uid) {
233
+        return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true);
234
+    }
235 235
 
236
-	/**
237
-	 * Get a list of all display names and user ids.
238
-	 * @param string $search
239
-	 * @param string|null $limit
240
-	 * @param string|null $offset
241
-	 * @return array an array of all displayNames (value) and the corresponding uids (key)
242
-	 */
243
-	public function getDisplayNames($search = '', $limit = null, $offset = null) {
244
-		//we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends
245
-		$users = array();
246
-		foreach($this->backends as $backend) {
247
-			$backendUsers = $backend->getDisplayNames($search, $limit, $offset);
248
-			if (is_array($backendUsers)) {
249
-				$users = $users + $backendUsers;
250
-			}
251
-		}
252
-		return $users;
253
-	}
236
+    /**
237
+     * Get a list of all display names and user ids.
238
+     * @param string $search
239
+     * @param string|null $limit
240
+     * @param string|null $offset
241
+     * @return array an array of all displayNames (value) and the corresponding uids (key)
242
+     */
243
+    public function getDisplayNames($search = '', $limit = null, $offset = null) {
244
+        //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends
245
+        $users = array();
246
+        foreach($this->backends as $backend) {
247
+            $backendUsers = $backend->getDisplayNames($search, $limit, $offset);
248
+            if (is_array($backendUsers)) {
249
+                $users = $users + $backendUsers;
250
+            }
251
+        }
252
+        return $users;
253
+    }
254 254
 
255
-	/**
256
-	 * delete a user
257
-	 * @param string $uid The username of the user to delete
258
-	 * @return bool
259
-	 *
260
-	 * Deletes a user
261
-	 */
262
-	public function deleteUser($uid) {
263
-		return $this->handleRequest($uid, 'deleteUser', array($uid));
264
-	}
255
+    /**
256
+     * delete a user
257
+     * @param string $uid The username of the user to delete
258
+     * @return bool
259
+     *
260
+     * Deletes a user
261
+     */
262
+    public function deleteUser($uid) {
263
+        return $this->handleRequest($uid, 'deleteUser', array($uid));
264
+    }
265 265
 	
266
-	/**
267
-	 * Set password
268
-	 * @param string $uid The username
269
-	 * @param string $password The new password
270
-	 * @return bool
271
-	 *
272
-	 */
273
-	public function setPassword($uid, $password) {
274
-		return $this->handleRequest($uid, 'setPassword', array($uid, $password));
275
-	}
266
+    /**
267
+     * Set password
268
+     * @param string $uid The username
269
+     * @param string $password The new password
270
+     * @return bool
271
+     *
272
+     */
273
+    public function setPassword($uid, $password) {
274
+        return $this->handleRequest($uid, 'setPassword', array($uid, $password));
275
+    }
276 276
 
277
-	/**
278
-	 * @return bool
279
-	 */
280
-	public function hasUserListings() {
281
-		return $this->refBackend->hasUserListings();
282
-	}
277
+    /**
278
+     * @return bool
279
+     */
280
+    public function hasUserListings() {
281
+        return $this->refBackend->hasUserListings();
282
+    }
283 283
 
284
-	/**
285
-	 * Count the number of users
286
-	 * @return int|bool
287
-	 */
288
-	public function countUsers() {
289
-		$users = false;
290
-		foreach($this->backends as $backend) {
291
-			$backendUsers = $backend->countUsers();
292
-			if ($backendUsers !== false) {
293
-				$users += $backendUsers;
294
-			}
295
-		}
296
-		return $users;
297
-	}
284
+    /**
285
+     * Count the number of users
286
+     * @return int|bool
287
+     */
288
+    public function countUsers() {
289
+        $users = false;
290
+        foreach($this->backends as $backend) {
291
+            $backendUsers = $backend->countUsers();
292
+            if ($backendUsers !== false) {
293
+                $users += $backendUsers;
294
+            }
295
+        }
296
+        return $users;
297
+    }
298 298
 
299
-	/**
300
-	 * Return access for LDAP interaction.
301
-	 * @param string $uid
302
-	 * @return Access instance of Access for LDAP interaction
303
-	 */
304
-	public function getLDAPAccess($uid) {
305
-		return $this->handleRequest($uid, 'getLDAPAccess', array($uid));
306
-	}
299
+    /**
300
+     * Return access for LDAP interaction.
301
+     * @param string $uid
302
+     * @return Access instance of Access for LDAP interaction
303
+     */
304
+    public function getLDAPAccess($uid) {
305
+        return $this->handleRequest($uid, 'getLDAPAccess', array($uid));
306
+    }
307 307
 	
308
-	/**
309
-	 * Return a new LDAP connection for the specified user.
310
-	 * The connection needs to be closed manually.
311
-	 * @param string $uid
312
-	 * @return resource of the LDAP connection
313
-	 */
314
-	public function getNewLDAPConnection($uid) {
315
-		return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid));
316
-	}
308
+    /**
309
+     * Return a new LDAP connection for the specified user.
310
+     * The connection needs to be closed manually.
311
+     * @param string $uid
312
+     * @return resource of the LDAP connection
313
+     */
314
+    public function getNewLDAPConnection($uid) {
315
+        return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid));
316
+    }
317 317
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/FilesystemHelper.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -29,19 +29,19 @@
 block discarded – undo
29 29
  */
30 30
 class FilesystemHelper {
31 31
 
32
-	/**
33
-	 * @brief states whether the filesystem was loaded
34
-	 * @return bool
35
-	 */
36
-	public function isLoaded() {
37
-		return \OC\Files\Filesystem::$loaded;
38
-	}
32
+    /**
33
+     * @brief states whether the filesystem was loaded
34
+     * @return bool
35
+     */
36
+    public function isLoaded() {
37
+        return \OC\Files\Filesystem::$loaded;
38
+    }
39 39
 
40
-	/**
41
-	 * @brief initializes the filesystem for the given user
42
-	 * @param string $uid the ownCloud username of the user
43
-	 */
44
-	public function setup($uid) {
45
-		\OC_Util::setupFS($uid);
46
-	}
40
+    /**
41
+     * @brief initializes the filesystem for the given user
42
+     * @param string $uid the ownCloud username of the user
43
+     */
44
+    public function setup($uid) {
45
+        \OC_Util::setupFS($uid);
46
+    }
47 47
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/LDAPProvider.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -33,155 +33,155 @@
 block discarded – undo
33 33
  */
34 34
 class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport {
35 35
 
36
-	private $backend;
37
-	private $logger;
38
-	private $helper;
39
-	private $deletedUsersIndex;
36
+    private $backend;
37
+    private $logger;
38
+    private $helper;
39
+    private $deletedUsersIndex;
40 40
 	
41
-	/**
42
-	 * Create new LDAPProvider
43
-	 * @param \OCP\IServerContainer $serverContainer
44
-	 * @throws \Exception if user_ldap app was not enabled
45
-	 */
46
-	public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) {
47
-		$this->logger = $serverContainer->getLogger();
48
-		$this->helper = $helper;
49
-		$this->deletedUsersIndex = $deletedUsersIndex;
50
-		foreach ($serverContainer->getUserManager()->getBackends() as $backend){
51
-			$this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']);
52
-			if ($backend instanceof IUserLDAP) {
53
-				$this->backend = $backend;
54
-				return;
55
-			}
41
+    /**
42
+     * Create new LDAPProvider
43
+     * @param \OCP\IServerContainer $serverContainer
44
+     * @throws \Exception if user_ldap app was not enabled
45
+     */
46
+    public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) {
47
+        $this->logger = $serverContainer->getLogger();
48
+        $this->helper = $helper;
49
+        $this->deletedUsersIndex = $deletedUsersIndex;
50
+        foreach ($serverContainer->getUserManager()->getBackends() as $backend){
51
+            $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']);
52
+            if ($backend instanceof IUserLDAP) {
53
+                $this->backend = $backend;
54
+                return;
55
+            }
56 56
         }
57
-		throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled');
58
-	}
57
+        throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled');
58
+    }
59 59
 	
60
-	/**
61
-	 * Translate an user id to LDAP DN
62
-	 * @param string $uid user id
63
-	 * @return string with the LDAP DN
64
-	 * @throws \Exception if translation was unsuccessful
65
-	 */
66
-	public function getUserDN($uid) {
67
-		if(!$this->backend->userExists($uid)){
68
-			throw new \Exception('User id not found in LDAP');
69
-		}
70
-		$result = $this->backend->getLDAPAccess($uid)->username2dn($uid);
71
-		if(!$result){
72
-			throw new \Exception('Translation to LDAP DN unsuccessful');
73
-		}
74
-		return $result;
75
-	}
60
+    /**
61
+     * Translate an user id to LDAP DN
62
+     * @param string $uid user id
63
+     * @return string with the LDAP DN
64
+     * @throws \Exception if translation was unsuccessful
65
+     */
66
+    public function getUserDN($uid) {
67
+        if(!$this->backend->userExists($uid)){
68
+            throw new \Exception('User id not found in LDAP');
69
+        }
70
+        $result = $this->backend->getLDAPAccess($uid)->username2dn($uid);
71
+        if(!$result){
72
+            throw new \Exception('Translation to LDAP DN unsuccessful');
73
+        }
74
+        return $result;
75
+    }
76 76
 	
77
-	/**
78
-	 * Translate a LDAP DN to an internal user name. If there is no mapping between 
79
-	 * the DN and the user name, a new one will be created.
80
-	 * @param string $dn LDAP DN
81
-	 * @return string with the internal user name
82
-	 * @throws \Exception if translation was unsuccessful
83
-	 */
84
-	public function getUserName($dn) {
85
-		$result = $this->backend->dn2UserName($dn);
86
-		if(!$result){
87
-			throw new \Exception('Translation to internal user name unsuccessful');
88
-		}
89
-		return $result;
90
-	}
77
+    /**
78
+     * Translate a LDAP DN to an internal user name. If there is no mapping between 
79
+     * the DN and the user name, a new one will be created.
80
+     * @param string $dn LDAP DN
81
+     * @return string with the internal user name
82
+     * @throws \Exception if translation was unsuccessful
83
+     */
84
+    public function getUserName($dn) {
85
+        $result = $this->backend->dn2UserName($dn);
86
+        if(!$result){
87
+            throw new \Exception('Translation to internal user name unsuccessful');
88
+        }
89
+        return $result;
90
+    }
91 91
 	
92
-	/**
93
-	 * Convert a stored DN so it can be used as base parameter for LDAP queries.
94
-	 * @param string $dn the DN in question
95
-	 * @return string
96
-	 */
97
-	public function DNasBaseParameter($dn) {
98
-		return $this->helper->DNasBaseParameter($dn);
99
-	}
92
+    /**
93
+     * Convert a stored DN so it can be used as base parameter for LDAP queries.
94
+     * @param string $dn the DN in question
95
+     * @return string
96
+     */
97
+    public function DNasBaseParameter($dn) {
98
+        return $this->helper->DNasBaseParameter($dn);
99
+    }
100 100
 	
101
-	/**
102
-	 * Sanitize a DN received from the LDAP server.
103
-	 * @param array $dn the DN in question
104
-	 * @return array the sanitized DN
105
-	 */
106
-	public function sanitizeDN($dn) {
107
-		return $this->helper->sanitizeDN($dn);
108
-	}
101
+    /**
102
+     * Sanitize a DN received from the LDAP server.
103
+     * @param array $dn the DN in question
104
+     * @return array the sanitized DN
105
+     */
106
+    public function sanitizeDN($dn) {
107
+        return $this->helper->sanitizeDN($dn);
108
+    }
109 109
 	
110
-	/**
111
-	 * Return a new LDAP connection resource for the specified user. 
112
-	 * The connection must be closed manually.
113
-	 * @param string $uid user id
114
-	 * @return resource of the LDAP connection
115
-	 * @throws \Exception if user id was not found in LDAP
116
-	 */
117
-	public function getLDAPConnection($uid) {
118
-		if(!$this->backend->userExists($uid)){
119
-			throw new \Exception('User id not found in LDAP');
120
-		}
121
-		return $this->backend->getNewLDAPConnection($uid);
122
-	}
110
+    /**
111
+     * Return a new LDAP connection resource for the specified user. 
112
+     * The connection must be closed manually.
113
+     * @param string $uid user id
114
+     * @return resource of the LDAP connection
115
+     * @throws \Exception if user id was not found in LDAP
116
+     */
117
+    public function getLDAPConnection($uid) {
118
+        if(!$this->backend->userExists($uid)){
119
+            throw new \Exception('User id not found in LDAP');
120
+        }
121
+        return $this->backend->getNewLDAPConnection($uid);
122
+    }
123 123
 	
124
-	/**
125
-	 * Get the LDAP base for users.
126
-	 * @param string $uid user id
127
-	 * @return string the base for users
128
-	 * @throws \Exception if user id was not found in LDAP
129
-	 */
130
-	public function getLDAPBaseUsers($uid) {
131
-		if(!$this->backend->userExists($uid)){
132
-			throw new \Exception('User id not found in LDAP');
133
-		}	
134
-		return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users'];
135
-	}
124
+    /**
125
+     * Get the LDAP base for users.
126
+     * @param string $uid user id
127
+     * @return string the base for users
128
+     * @throws \Exception if user id was not found in LDAP
129
+     */
130
+    public function getLDAPBaseUsers($uid) {
131
+        if(!$this->backend->userExists($uid)){
132
+            throw new \Exception('User id not found in LDAP');
133
+        }	
134
+        return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users'];
135
+    }
136 136
 	
137
-	/**
138
-	 * Get the LDAP base for groups.
139
-	 * @param string $uid user id
140
-	 * @return string the base for groups
141
-	 * @throws \Exception if user id was not found in LDAP
142
-	 */
143
-	public function getLDAPBaseGroups($uid) {
144
-		if(!$this->backend->userExists($uid)){
145
-			throw new \Exception('User id not found in LDAP');
146
-		}
147
-		return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups'];
148
-	}
137
+    /**
138
+     * Get the LDAP base for groups.
139
+     * @param string $uid user id
140
+     * @return string the base for groups
141
+     * @throws \Exception if user id was not found in LDAP
142
+     */
143
+    public function getLDAPBaseGroups($uid) {
144
+        if(!$this->backend->userExists($uid)){
145
+            throw new \Exception('User id not found in LDAP');
146
+        }
147
+        return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups'];
148
+    }
149 149
 	
150
-	/**
151
-	 * Clear the cache if a cache is used, otherwise do nothing.
152
-	 * @param string $uid user id
153
-	 * @throws \Exception if user id was not found in LDAP
154
-	 */
155
-	public function clearCache($uid) {
156
-		if(!$this->backend->userExists($uid)){
157
-			throw new \Exception('User id not found in LDAP');
158
-		}
159
-		$this->backend->getLDAPAccess($uid)->getConnection()->clearCache();
160
-	}
150
+    /**
151
+     * Clear the cache if a cache is used, otherwise do nothing.
152
+     * @param string $uid user id
153
+     * @throws \Exception if user id was not found in LDAP
154
+     */
155
+    public function clearCache($uid) {
156
+        if(!$this->backend->userExists($uid)){
157
+            throw new \Exception('User id not found in LDAP');
158
+        }
159
+        $this->backend->getLDAPAccess($uid)->getConnection()->clearCache();
160
+    }
161 161
 	
162
-	/**
163
-	 * Check whether a LDAP DN exists
164
-	 * @param string $dn LDAP DN
165
-	 * @return bool whether the DN exists
166
-	 */
167
-	public function dnExists($dn) {
168
-		$result = $this->backend->dn2UserName($dn);
169
-		return !$result ? false : true;
170
-	}
162
+    /**
163
+     * Check whether a LDAP DN exists
164
+     * @param string $dn LDAP DN
165
+     * @return bool whether the DN exists
166
+     */
167
+    public function dnExists($dn) {
168
+        $result = $this->backend->dn2UserName($dn);
169
+        return !$result ? false : true;
170
+    }
171 171
 	
172
-	/**
173
-	 * Flag record for deletion.
174
-	 * @param string $uid user id
175
-	 */
176
-	public function flagRecord($uid) {
177
-		$this->deletedUsersIndex->markUser($uid);
178
-	}
172
+    /**
173
+     * Flag record for deletion.
174
+     * @param string $uid user id
175
+     */
176
+    public function flagRecord($uid) {
177
+        $this->deletedUsersIndex->markUser($uid);
178
+    }
179 179
 	
180
-	/**
181
-	 * Unflag record for deletion.
182
-	 * @param string $uid user id
183
-	 */
184
-	public function unflagRecord($uid) {
185
-		//do nothing
186
-	}
180
+    /**
181
+     * Unflag record for deletion.
182
+     * @param string $uid user id
183
+     */
184
+    public function unflagRecord($uid) {
185
+        //do nothing
186
+    }
187 187
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User_LDAP.php 1 patch
Indentation   +485 added lines, -485 removed lines patch added patch discarded remove patch
@@ -44,492 +44,492 @@
 block discarded – undo
44 44
 use OCP\Util;
45 45
 
46 46
 class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP {
47
-	/** @var string[] $homesToKill */
48
-	protected $homesToKill = array();
49
-
50
-	/** @var \OCP\IConfig */
51
-	protected $ocConfig;
52
-
53
-	/**
54
-	 * @param Access $access
55
-	 * @param \OCP\IConfig $ocConfig
56
-	 */
57
-	public function __construct(Access $access, IConfig $ocConfig) {
58
-		parent::__construct($access);
59
-		$this->ocConfig = $ocConfig;
60
-	}
61
-
62
-	/**
63
-	 * checks whether the user is allowed to change his avatar in ownCloud
64
-	 * @param string $uid the ownCloud user name
65
-	 * @return boolean either the user can or cannot
66
-	 */
67
-	public function canChangeAvatar($uid) {
68
-		$user = $this->access->userManager->get($uid);
69
-		if(!$user instanceof User) {
70
-			return false;
71
-		}
72
-		if($user->getAvatarImage() === false) {
73
-			return true;
74
-		}
75
-
76
-		return false;
77
-	}
78
-
79
-	/**
80
-	 * returns the username for the given login name, if available
81
-	 *
82
-	 * @param string $loginName
83
-	 * @return string|false
84
-	 */
85
-	public function loginName2UserName($loginName) {
86
-		$cacheKey = 'loginName2UserName-'.$loginName;
87
-		$username = $this->access->connection->getFromCache($cacheKey);
88
-		if(!is_null($username)) {
89
-			return $username;
90
-		}
91
-
92
-		try {
93
-			$ldapRecord = $this->getLDAPUserByLoginName($loginName);
94
-			$user = $this->access->userManager->get($ldapRecord['dn'][0]);
95
-			if($user instanceof OfflineUser) {
96
-				// this path is not really possible, however get() is documented
97
-				// to return User or OfflineUser so we are very defensive here.
98
-				$this->access->connection->writeToCache($cacheKey, false);
99
-				return false;
100
-			}
101
-			$username = $user->getUsername();
102
-			$this->access->connection->writeToCache($cacheKey, $username);
103
-			return $username;
104
-		} catch (NotOnLDAP $e) {
105
-			$this->access->connection->writeToCache($cacheKey, false);
106
-			return false;
107
-		}
108
-	}
47
+    /** @var string[] $homesToKill */
48
+    protected $homesToKill = array();
49
+
50
+    /** @var \OCP\IConfig */
51
+    protected $ocConfig;
52
+
53
+    /**
54
+     * @param Access $access
55
+     * @param \OCP\IConfig $ocConfig
56
+     */
57
+    public function __construct(Access $access, IConfig $ocConfig) {
58
+        parent::__construct($access);
59
+        $this->ocConfig = $ocConfig;
60
+    }
61
+
62
+    /**
63
+     * checks whether the user is allowed to change his avatar in ownCloud
64
+     * @param string $uid the ownCloud user name
65
+     * @return boolean either the user can or cannot
66
+     */
67
+    public function canChangeAvatar($uid) {
68
+        $user = $this->access->userManager->get($uid);
69
+        if(!$user instanceof User) {
70
+            return false;
71
+        }
72
+        if($user->getAvatarImage() === false) {
73
+            return true;
74
+        }
75
+
76
+        return false;
77
+    }
78
+
79
+    /**
80
+     * returns the username for the given login name, if available
81
+     *
82
+     * @param string $loginName
83
+     * @return string|false
84
+     */
85
+    public function loginName2UserName($loginName) {
86
+        $cacheKey = 'loginName2UserName-'.$loginName;
87
+        $username = $this->access->connection->getFromCache($cacheKey);
88
+        if(!is_null($username)) {
89
+            return $username;
90
+        }
91
+
92
+        try {
93
+            $ldapRecord = $this->getLDAPUserByLoginName($loginName);
94
+            $user = $this->access->userManager->get($ldapRecord['dn'][0]);
95
+            if($user instanceof OfflineUser) {
96
+                // this path is not really possible, however get() is documented
97
+                // to return User or OfflineUser so we are very defensive here.
98
+                $this->access->connection->writeToCache($cacheKey, false);
99
+                return false;
100
+            }
101
+            $username = $user->getUsername();
102
+            $this->access->connection->writeToCache($cacheKey, $username);
103
+            return $username;
104
+        } catch (NotOnLDAP $e) {
105
+            $this->access->connection->writeToCache($cacheKey, false);
106
+            return false;
107
+        }
108
+    }
109 109
 	
110
-	/**
111
-	 * returns the username for the given LDAP DN, if available
112
-	 *
113
-	 * @param string $dn
114
-	 * @return string|false with the username
115
-	 */
116
-	public function dn2UserName($dn) {
117
-		return $this->access->dn2username($dn);
118
-	}
119
-
120
-	/**
121
-	 * returns an LDAP record based on a given login name
122
-	 *
123
-	 * @param string $loginName
124
-	 * @return array
125
-	 * @throws NotOnLDAP
126
-	 */
127
-	public function getLDAPUserByLoginName($loginName) {
128
-		//find out dn of the user name
129
-		$attrs = $this->access->userManager->getAttributes();
130
-		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
131
-		if(count($users) < 1) {
132
-			throw new NotOnLDAP('No user available for the given login name on ' .
133
-				$this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
134
-		}
135
-		return $users[0];
136
-	}
137
-
138
-	/**
139
-	 * Check if the password is correct without logging in the user
140
-	 *
141
-	 * @param string $uid The username
142
-	 * @param string $password The password
143
-	 * @return false|string
144
-	 */
145
-	public function checkPassword($uid, $password) {
146
-		try {
147
-			$ldapRecord = $this->getLDAPUserByLoginName($uid);
148
-		} catch(NotOnLDAP $e) {
149
-			if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
150
-				\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
151
-			}
152
-			return false;
153
-		}
154
-		$dn = $ldapRecord['dn'][0];
155
-		$user = $this->access->userManager->get($dn);
156
-
157
-		if(!$user instanceof User) {
158
-			Util::writeLog('user_ldap',
159
-				'LDAP Login: Could not get user object for DN ' . $dn .
160
-				'. Maybe the LDAP entry has no set display name attribute?',
161
-				Util::WARN);
162
-			return false;
163
-		}
164
-		if($user->getUsername() !== false) {
165
-			//are the credentials OK?
166
-			if(!$this->access->areCredentialsValid($dn, $password)) {
167
-				return false;
168
-			}
169
-
170
-			$this->access->cacheUserExists($user->getUsername());
171
-			$user->processAttributes($ldapRecord);
172
-			$user->markLogin();
173
-
174
-			return $user->getUsername();
175
-		}
176
-
177
-		return false;
178
-	}
179
-
180
-	/**
181
-	 * Set password
182
-	 * @param string $uid The username
183
-	 * @param string $password The new password
184
-	 * @return bool
185
-	 */
186
-	public function setPassword($uid, $password) {
187
-		$user = $this->access->userManager->get($uid);
188
-
189
-		if(!$user instanceof User) {
190
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
191
-				'. Maybe the LDAP entry has no set display name attribute?');
192
-		}
193
-		if($user->getUsername() !== false) {
194
-			return $this->access->setPassword($user->getDN(), $password);
195
-		}
196
-
197
-		return false;
198
-	}
199
-
200
-	/**
201
-	 * Get a list of all users
202
-	 *
203
-	 * @param string $search
204
-	 * @param integer $limit
205
-	 * @param integer $offset
206
-	 * @return string[] an array of all uids
207
-	 */
208
-	public function getUsers($search = '', $limit = 10, $offset = 0) {
209
-		$search = $this->access->escapeFilterPart($search, true);
210
-		$cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
211
-
212
-		//check if users are cached, if so return
213
-		$ldap_users = $this->access->connection->getFromCache($cachekey);
214
-		if(!is_null($ldap_users)) {
215
-			return $ldap_users;
216
-		}
217
-
218
-		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
219
-		// error. With a limit of 0, we get 0 results. So we pass null.
220
-		if($limit <= 0) {
221
-			$limit = null;
222
-		}
223
-		$filter = $this->access->combineFilterWithAnd(array(
224
-			$this->access->connection->ldapUserFilter,
225
-			$this->access->connection->ldapUserDisplayName . '=*',
226
-			$this->access->getFilterPartForUserSearch($search)
227
-		));
228
-
229
-		Util::writeLog('user_ldap',
230
-			'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
231
-			Util::DEBUG);
232
-		//do the search and translate results to owncloud names
233
-		$ldap_users = $this->access->fetchListOfUsers(
234
-			$filter,
235
-			$this->access->userManager->getAttributes(true),
236
-			$limit, $offset);
237
-		$ldap_users = $this->access->ownCloudUserNames($ldap_users);
238
-		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
239
-
240
-		$this->access->connection->writeToCache($cachekey, $ldap_users);
241
-		return $ldap_users;
242
-	}
243
-
244
-	/**
245
-	 * checks whether a user is still available on LDAP
246
-	 *
247
-	 * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user
248
-	 * name or an instance of that user
249
-	 * @return bool
250
-	 * @throws \Exception
251
-	 * @throws \OC\ServerNotAvailableException
252
-	 */
253
-	public function userExistsOnLDAP($user) {
254
-		if(is_string($user)) {
255
-			$user = $this->access->userManager->get($user);
256
-		}
257
-		if(is_null($user)) {
258
-			return false;
259
-		}
260
-
261
-		$dn = $user->getDN();
262
-		//check if user really still exists by reading its entry
263
-		if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
264
-			$lcr = $this->access->connection->getConnectionResource();
265
-			if(is_null($lcr)) {
266
-				throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
267
-			}
268
-
269
-			try {
270
-				$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
271
-				if(!$uuid) {
272
-					return false;
273
-				}
274
-				$newDn = $this->access->getUserDnByUuid($uuid);
275
-				//check if renamed user is still valid by reapplying the ldap filter
276
-				if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
277
-					return false;
278
-				}
279
-				$this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
280
-				return true;
281
-			} catch (\Exception $e) {
282
-				return false;
283
-			}
284
-		}
285
-
286
-		if($user instanceof OfflineUser) {
287
-			$user->unmark();
288
-		}
289
-
290
-		return true;
291
-	}
292
-
293
-	/**
294
-	 * check if a user exists
295
-	 * @param string $uid the username
296
-	 * @return boolean
297
-	 * @throws \Exception when connection could not be established
298
-	 */
299
-	public function userExists($uid) {
300
-		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
301
-		if(!is_null($userExists)) {
302
-			return (bool)$userExists;
303
-		}
304
-		//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
305
-		$user = $this->access->userManager->get($uid);
306
-
307
-		if(is_null($user)) {
308
-			Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
309
-				$this->access->connection->ldapHost, Util::DEBUG);
310
-			$this->access->connection->writeToCache('userExists'.$uid, false);
311
-			return false;
312
-		} else if($user instanceof OfflineUser) {
313
-			//express check for users marked as deleted. Returning true is
314
-			//necessary for cleanup
315
-			return true;
316
-		}
317
-
318
-		$result = $this->userExistsOnLDAP($user);
319
-		$this->access->connection->writeToCache('userExists'.$uid, $result);
320
-		if($result === true) {
321
-			$user->update();
322
-		}
323
-		return $result;
324
-	}
325
-
326
-	/**
327
-	* returns whether a user was deleted in LDAP
328
-	*
329
-	* @param string $uid The username of the user to delete
330
-	* @return bool
331
-	*/
332
-	public function deleteUser($uid) {
333
-		$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
334
-		if(intval($marked) === 0) {
335
-			\OC::$server->getLogger()->notice(
336
-				'User '.$uid . ' is not marked as deleted, not cleaning up.',
337
-				array('app' => 'user_ldap'));
338
-			return false;
339
-		}
340
-		\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
341
-			array('app' => 'user_ldap'));
342
-
343
-		//Get Home Directory out of user preferences so we can return it later,
344
-		//necessary for removing directories as done by OC_User.
345
-		$home = $this->ocConfig->getUserValue($uid, 'user_ldap', 'homePath', '');
346
-		$this->homesToKill[$uid] = $home;
347
-		$this->access->getUserMapper()->unmap($uid);
348
-
349
-		return true;
350
-	}
351
-
352
-	/**
353
-	 * get the user's home directory
354
-	 *
355
-	 * @param string $uid the username
356
-	 * @return bool|string
357
-	 * @throws NoUserException
358
-	 * @throws \Exception
359
-	 */
360
-	public function getHome($uid) {
361
-		if(isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) {
362
-			//a deleted user who needs some clean up
363
-			return $this->homesToKill[$uid];
364
-		}
365
-
366
-		// user Exists check required as it is not done in user proxy!
367
-		if(!$this->userExists($uid)) {
368
-			return false;
369
-		}
370
-
371
-		$cacheKey = 'getHome'.$uid;
372
-		$path = $this->access->connection->getFromCache($cacheKey);
373
-		if(!is_null($path)) {
374
-			return $path;
375
-		}
376
-
377
-		$user = $this->access->userManager->get($uid);
378
-		if(is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) {
379
-			throw new NoUserException($uid . ' is not a valid user anymore');
380
-		}
381
-		if($user instanceof OfflineUser) {
382
-			// apparently this user survived the userExistsOnLDAP check,
383
-			// we request the user instance again in order to retrieve a User
384
-			// instance instead
385
-			$user = $this->access->userManager->get($uid);
386
-		}
387
-		$path = $user->getHomePath();
388
-		$this->access->cacheUserHome($uid, $path);
389
-
390
-		return $path;
391
-	}
392
-
393
-	/**
394
-	 * get display name of the user
395
-	 * @param string $uid user ID of the user
396
-	 * @return string|false display name
397
-	 */
398
-	public function getDisplayName($uid) {
399
-		if(!$this->userExists($uid)) {
400
-			return false;
401
-		}
402
-
403
-		$cacheKey = 'getDisplayName'.$uid;
404
-		if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
405
-			return $displayName;
406
-		}
407
-
408
-		//Check whether the display name is configured to have a 2nd feature
409
-		$additionalAttribute = $this->access->connection->ldapUserDisplayName2;
410
-		$displayName2 = '';
411
-		if ($additionalAttribute !== '') {
412
-			$displayName2 = $this->access->readAttribute(
413
-				$this->access->username2dn($uid),
414
-				$additionalAttribute);
415
-		}
416
-
417
-		$displayName = $this->access->readAttribute(
418
-			$this->access->username2dn($uid),
419
-			$this->access->connection->ldapUserDisplayName);
420
-
421
-		if($displayName && (count($displayName) > 0)) {
422
-			$displayName = $displayName[0];
423
-
424
-			if (is_array($displayName2)){
425
-				$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
426
-			}
427
-
428
-			$user = $this->access->userManager->get($uid);
429
-			if ($user instanceof User) {
430
-				$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
431
-				$this->access->connection->writeToCache($cacheKey, $displayName);
432
-			}
433
-			if ($user instanceof OfflineUser) {
434
-				/** @var OfflineUser $user*/
435
-				$displayName = $user->getDisplayName();
436
-			}
437
-			return $displayName;
438
-		}
439
-
440
-		return null;
441
-	}
442
-
443
-	/**
444
-	 * Get a list of all display names
445
-	 *
446
-	 * @param string $search
447
-	 * @param string|null $limit
448
-	 * @param string|null $offset
449
-	 * @return array an array of all displayNames (value) and the corresponding uids (key)
450
-	 */
451
-	public function getDisplayNames($search = '', $limit = null, $offset = null) {
452
-		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
453
-		if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
454
-			return $displayNames;
455
-		}
456
-
457
-		$displayNames = array();
458
-		$users = $this->getUsers($search, $limit, $offset);
459
-		foreach ($users as $user) {
460
-			$displayNames[$user] = $this->getDisplayName($user);
461
-		}
462
-		$this->access->connection->writeToCache($cacheKey, $displayNames);
463
-		return $displayNames;
464
-	}
465
-
466
-	/**
467
-	* Check if backend implements actions
468
-	* @param int $actions bitwise-or'ed actions
469
-	* @return boolean
470
-	*
471
-	* Returns the supported actions as int to be
472
-	* compared with OC_USER_BACKEND_CREATE_USER etc.
473
-	*/
474
-	public function implementsActions($actions) {
475
-		return (bool)((Backend::CHECK_PASSWORD
476
-			| Backend::GET_HOME
477
-			| Backend::GET_DISPLAYNAME
478
-			| Backend::PROVIDE_AVATAR
479
-			| Backend::COUNT_USERS
480
-			| ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0))
481
-			& $actions);
482
-	}
483
-
484
-	/**
485
-	 * @return bool
486
-	 */
487
-	public function hasUserListings() {
488
-		return true;
489
-	}
490
-
491
-	/**
492
-	 * counts the users in LDAP
493
-	 *
494
-	 * @return int|bool
495
-	 */
496
-	public function countUsers() {
497
-		$filter = $this->access->getFilterForUserCount();
498
-		$cacheKey = 'countUsers-'.$filter;
499
-		if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
500
-			return $entries;
501
-		}
502
-		$entries = $this->access->countUsers($filter);
503
-		$this->access->connection->writeToCache($cacheKey, $entries);
504
-		return $entries;
505
-	}
506
-
507
-	/**
508
-	 * Backend name to be shown in user management
509
-	 * @return string the name of the backend to be shown
510
-	 */
511
-	public function getBackendName(){
512
-		return 'LDAP';
513
-	}
110
+    /**
111
+     * returns the username for the given LDAP DN, if available
112
+     *
113
+     * @param string $dn
114
+     * @return string|false with the username
115
+     */
116
+    public function dn2UserName($dn) {
117
+        return $this->access->dn2username($dn);
118
+    }
119
+
120
+    /**
121
+     * returns an LDAP record based on a given login name
122
+     *
123
+     * @param string $loginName
124
+     * @return array
125
+     * @throws NotOnLDAP
126
+     */
127
+    public function getLDAPUserByLoginName($loginName) {
128
+        //find out dn of the user name
129
+        $attrs = $this->access->userManager->getAttributes();
130
+        $users = $this->access->fetchUsersByLoginName($loginName, $attrs);
131
+        if(count($users) < 1) {
132
+            throw new NotOnLDAP('No user available for the given login name on ' .
133
+                $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
134
+        }
135
+        return $users[0];
136
+    }
137
+
138
+    /**
139
+     * Check if the password is correct without logging in the user
140
+     *
141
+     * @param string $uid The username
142
+     * @param string $password The password
143
+     * @return false|string
144
+     */
145
+    public function checkPassword($uid, $password) {
146
+        try {
147
+            $ldapRecord = $this->getLDAPUserByLoginName($uid);
148
+        } catch(NotOnLDAP $e) {
149
+            if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
150
+                \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
151
+            }
152
+            return false;
153
+        }
154
+        $dn = $ldapRecord['dn'][0];
155
+        $user = $this->access->userManager->get($dn);
156
+
157
+        if(!$user instanceof User) {
158
+            Util::writeLog('user_ldap',
159
+                'LDAP Login: Could not get user object for DN ' . $dn .
160
+                '. Maybe the LDAP entry has no set display name attribute?',
161
+                Util::WARN);
162
+            return false;
163
+        }
164
+        if($user->getUsername() !== false) {
165
+            //are the credentials OK?
166
+            if(!$this->access->areCredentialsValid($dn, $password)) {
167
+                return false;
168
+            }
169
+
170
+            $this->access->cacheUserExists($user->getUsername());
171
+            $user->processAttributes($ldapRecord);
172
+            $user->markLogin();
173
+
174
+            return $user->getUsername();
175
+        }
176
+
177
+        return false;
178
+    }
179
+
180
+    /**
181
+     * Set password
182
+     * @param string $uid The username
183
+     * @param string $password The new password
184
+     * @return bool
185
+     */
186
+    public function setPassword($uid, $password) {
187
+        $user = $this->access->userManager->get($uid);
188
+
189
+        if(!$user instanceof User) {
190
+            throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
191
+                '. Maybe the LDAP entry has no set display name attribute?');
192
+        }
193
+        if($user->getUsername() !== false) {
194
+            return $this->access->setPassword($user->getDN(), $password);
195
+        }
196
+
197
+        return false;
198
+    }
199
+
200
+    /**
201
+     * Get a list of all users
202
+     *
203
+     * @param string $search
204
+     * @param integer $limit
205
+     * @param integer $offset
206
+     * @return string[] an array of all uids
207
+     */
208
+    public function getUsers($search = '', $limit = 10, $offset = 0) {
209
+        $search = $this->access->escapeFilterPart($search, true);
210
+        $cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
211
+
212
+        //check if users are cached, if so return
213
+        $ldap_users = $this->access->connection->getFromCache($cachekey);
214
+        if(!is_null($ldap_users)) {
215
+            return $ldap_users;
216
+        }
217
+
218
+        // if we'd pass -1 to LDAP search, we'd end up in a Protocol
219
+        // error. With a limit of 0, we get 0 results. So we pass null.
220
+        if($limit <= 0) {
221
+            $limit = null;
222
+        }
223
+        $filter = $this->access->combineFilterWithAnd(array(
224
+            $this->access->connection->ldapUserFilter,
225
+            $this->access->connection->ldapUserDisplayName . '=*',
226
+            $this->access->getFilterPartForUserSearch($search)
227
+        ));
228
+
229
+        Util::writeLog('user_ldap',
230
+            'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
231
+            Util::DEBUG);
232
+        //do the search and translate results to owncloud names
233
+        $ldap_users = $this->access->fetchListOfUsers(
234
+            $filter,
235
+            $this->access->userManager->getAttributes(true),
236
+            $limit, $offset);
237
+        $ldap_users = $this->access->ownCloudUserNames($ldap_users);
238
+        Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
239
+
240
+        $this->access->connection->writeToCache($cachekey, $ldap_users);
241
+        return $ldap_users;
242
+    }
243
+
244
+    /**
245
+     * checks whether a user is still available on LDAP
246
+     *
247
+     * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user
248
+     * name or an instance of that user
249
+     * @return bool
250
+     * @throws \Exception
251
+     * @throws \OC\ServerNotAvailableException
252
+     */
253
+    public function userExistsOnLDAP($user) {
254
+        if(is_string($user)) {
255
+            $user = $this->access->userManager->get($user);
256
+        }
257
+        if(is_null($user)) {
258
+            return false;
259
+        }
260
+
261
+        $dn = $user->getDN();
262
+        //check if user really still exists by reading its entry
263
+        if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
264
+            $lcr = $this->access->connection->getConnectionResource();
265
+            if(is_null($lcr)) {
266
+                throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
267
+            }
268
+
269
+            try {
270
+                $uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
271
+                if(!$uuid) {
272
+                    return false;
273
+                }
274
+                $newDn = $this->access->getUserDnByUuid($uuid);
275
+                //check if renamed user is still valid by reapplying the ldap filter
276
+                if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
277
+                    return false;
278
+                }
279
+                $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
280
+                return true;
281
+            } catch (\Exception $e) {
282
+                return false;
283
+            }
284
+        }
285
+
286
+        if($user instanceof OfflineUser) {
287
+            $user->unmark();
288
+        }
289
+
290
+        return true;
291
+    }
292
+
293
+    /**
294
+     * check if a user exists
295
+     * @param string $uid the username
296
+     * @return boolean
297
+     * @throws \Exception when connection could not be established
298
+     */
299
+    public function userExists($uid) {
300
+        $userExists = $this->access->connection->getFromCache('userExists'.$uid);
301
+        if(!is_null($userExists)) {
302
+            return (bool)$userExists;
303
+        }
304
+        //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
305
+        $user = $this->access->userManager->get($uid);
306
+
307
+        if(is_null($user)) {
308
+            Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
309
+                $this->access->connection->ldapHost, Util::DEBUG);
310
+            $this->access->connection->writeToCache('userExists'.$uid, false);
311
+            return false;
312
+        } else if($user instanceof OfflineUser) {
313
+            //express check for users marked as deleted. Returning true is
314
+            //necessary for cleanup
315
+            return true;
316
+        }
317
+
318
+        $result = $this->userExistsOnLDAP($user);
319
+        $this->access->connection->writeToCache('userExists'.$uid, $result);
320
+        if($result === true) {
321
+            $user->update();
322
+        }
323
+        return $result;
324
+    }
325
+
326
+    /**
327
+     * returns whether a user was deleted in LDAP
328
+     *
329
+     * @param string $uid The username of the user to delete
330
+     * @return bool
331
+     */
332
+    public function deleteUser($uid) {
333
+        $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
334
+        if(intval($marked) === 0) {
335
+            \OC::$server->getLogger()->notice(
336
+                'User '.$uid . ' is not marked as deleted, not cleaning up.',
337
+                array('app' => 'user_ldap'));
338
+            return false;
339
+        }
340
+        \OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
341
+            array('app' => 'user_ldap'));
342
+
343
+        //Get Home Directory out of user preferences so we can return it later,
344
+        //necessary for removing directories as done by OC_User.
345
+        $home = $this->ocConfig->getUserValue($uid, 'user_ldap', 'homePath', '');
346
+        $this->homesToKill[$uid] = $home;
347
+        $this->access->getUserMapper()->unmap($uid);
348
+
349
+        return true;
350
+    }
351
+
352
+    /**
353
+     * get the user's home directory
354
+     *
355
+     * @param string $uid the username
356
+     * @return bool|string
357
+     * @throws NoUserException
358
+     * @throws \Exception
359
+     */
360
+    public function getHome($uid) {
361
+        if(isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) {
362
+            //a deleted user who needs some clean up
363
+            return $this->homesToKill[$uid];
364
+        }
365
+
366
+        // user Exists check required as it is not done in user proxy!
367
+        if(!$this->userExists($uid)) {
368
+            return false;
369
+        }
370
+
371
+        $cacheKey = 'getHome'.$uid;
372
+        $path = $this->access->connection->getFromCache($cacheKey);
373
+        if(!is_null($path)) {
374
+            return $path;
375
+        }
376
+
377
+        $user = $this->access->userManager->get($uid);
378
+        if(is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) {
379
+            throw new NoUserException($uid . ' is not a valid user anymore');
380
+        }
381
+        if($user instanceof OfflineUser) {
382
+            // apparently this user survived the userExistsOnLDAP check,
383
+            // we request the user instance again in order to retrieve a User
384
+            // instance instead
385
+            $user = $this->access->userManager->get($uid);
386
+        }
387
+        $path = $user->getHomePath();
388
+        $this->access->cacheUserHome($uid, $path);
389
+
390
+        return $path;
391
+    }
392
+
393
+    /**
394
+     * get display name of the user
395
+     * @param string $uid user ID of the user
396
+     * @return string|false display name
397
+     */
398
+    public function getDisplayName($uid) {
399
+        if(!$this->userExists($uid)) {
400
+            return false;
401
+        }
402
+
403
+        $cacheKey = 'getDisplayName'.$uid;
404
+        if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
405
+            return $displayName;
406
+        }
407
+
408
+        //Check whether the display name is configured to have a 2nd feature
409
+        $additionalAttribute = $this->access->connection->ldapUserDisplayName2;
410
+        $displayName2 = '';
411
+        if ($additionalAttribute !== '') {
412
+            $displayName2 = $this->access->readAttribute(
413
+                $this->access->username2dn($uid),
414
+                $additionalAttribute);
415
+        }
416
+
417
+        $displayName = $this->access->readAttribute(
418
+            $this->access->username2dn($uid),
419
+            $this->access->connection->ldapUserDisplayName);
420
+
421
+        if($displayName && (count($displayName) > 0)) {
422
+            $displayName = $displayName[0];
423
+
424
+            if (is_array($displayName2)){
425
+                $displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
426
+            }
427
+
428
+            $user = $this->access->userManager->get($uid);
429
+            if ($user instanceof User) {
430
+                $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
431
+                $this->access->connection->writeToCache($cacheKey, $displayName);
432
+            }
433
+            if ($user instanceof OfflineUser) {
434
+                /** @var OfflineUser $user*/
435
+                $displayName = $user->getDisplayName();
436
+            }
437
+            return $displayName;
438
+        }
439
+
440
+        return null;
441
+    }
442
+
443
+    /**
444
+     * Get a list of all display names
445
+     *
446
+     * @param string $search
447
+     * @param string|null $limit
448
+     * @param string|null $offset
449
+     * @return array an array of all displayNames (value) and the corresponding uids (key)
450
+     */
451
+    public function getDisplayNames($search = '', $limit = null, $offset = null) {
452
+        $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
453
+        if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
454
+            return $displayNames;
455
+        }
456
+
457
+        $displayNames = array();
458
+        $users = $this->getUsers($search, $limit, $offset);
459
+        foreach ($users as $user) {
460
+            $displayNames[$user] = $this->getDisplayName($user);
461
+        }
462
+        $this->access->connection->writeToCache($cacheKey, $displayNames);
463
+        return $displayNames;
464
+    }
465
+
466
+    /**
467
+     * Check if backend implements actions
468
+     * @param int $actions bitwise-or'ed actions
469
+     * @return boolean
470
+     *
471
+     * Returns the supported actions as int to be
472
+     * compared with OC_USER_BACKEND_CREATE_USER etc.
473
+     */
474
+    public function implementsActions($actions) {
475
+        return (bool)((Backend::CHECK_PASSWORD
476
+            | Backend::GET_HOME
477
+            | Backend::GET_DISPLAYNAME
478
+            | Backend::PROVIDE_AVATAR
479
+            | Backend::COUNT_USERS
480
+            | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0))
481
+            & $actions);
482
+    }
483
+
484
+    /**
485
+     * @return bool
486
+     */
487
+    public function hasUserListings() {
488
+        return true;
489
+    }
490
+
491
+    /**
492
+     * counts the users in LDAP
493
+     *
494
+     * @return int|bool
495
+     */
496
+    public function countUsers() {
497
+        $filter = $this->access->getFilterForUserCount();
498
+        $cacheKey = 'countUsers-'.$filter;
499
+        if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
500
+            return $entries;
501
+        }
502
+        $entries = $this->access->countUsers($filter);
503
+        $this->access->connection->writeToCache($cacheKey, $entries);
504
+        return $entries;
505
+    }
506
+
507
+    /**
508
+     * Backend name to be shown in user management
509
+     * @return string the name of the backend to be shown
510
+     */
511
+    public function getBackendName(){
512
+        return 'LDAP';
513
+    }
514 514
 	
515
-	/**
516
-	 * Return access for LDAP interaction.
517
-	 * @param string $uid
518
-	 * @return Access instance of Access for LDAP interaction
519
-	 */
520
-	public function getLDAPAccess($uid) {
521
-		return $this->access;
522
-	}
515
+    /**
516
+     * Return access for LDAP interaction.
517
+     * @param string $uid
518
+     * @return Access instance of Access for LDAP interaction
519
+     */
520
+    public function getLDAPAccess($uid) {
521
+        return $this->access;
522
+    }
523 523
 	
524
-	/**
525
-	 * Return LDAP connection resource from a cloned connection.
526
-	 * The cloned connection needs to be closed manually.
527
-	 * of the current access.
528
-	 * @param string $uid
529
-	 * @return resource of the LDAP connection
530
-	 */
531
-	public function getNewLDAPConnection($uid) {
532
-		$connection = clone $this->access->getConnection();
533
-		return $connection->getConnectionResource();
534
-	}
524
+    /**
525
+     * Return LDAP connection resource from a cloned connection.
526
+     * The cloned connection needs to be closed manually.
527
+     * of the current access.
528
+     * @param string $uid
529
+     * @return resource of the LDAP connection
530
+     */
531
+    public function getNewLDAPConnection($uid) {
532
+        $connection = clone $this->access->getConnection();
533
+        return $connection->getConnectionResource();
534
+    }
535 535
 }
Please login to merge, or discard this patch.