Completed
Pull Request — master (#5689)
by Blizzz
28:25 queued 10:53
created
apps/user_ldap/lib/User/OfflineUser.php 1 patch
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -29,205 +29,205 @@
 block discarded – undo
29 29
 use OCP\IDBConnection;
30 30
 
31 31
 class OfflineUser {
32
-	/**
33
-	 * @var string $ocName
34
-	 */
35
-	protected $ocName;
36
-	/**
37
-	 * @var string $dn
38
-	 */
39
-	protected $dn;
40
-	/**
41
-	 * @var string $uid the UID as provided by LDAP
42
-	 */
43
-	protected $uid;
44
-	/**
45
-	 * @var string $displayName
46
-	 */
47
-	protected $displayName;
48
-	/**
49
-	 * @var string $homePath
50
-	 */
51
-	protected $homePath;
52
-	/**
53
-	 * @var string $lastLogin the timestamp of the last login
54
-	 */
55
-	protected $lastLogin;
56
-	/**
57
-	 * @var string $email
58
-	 */
59
-	protected $email;
60
-	/**
61
-	 * @var bool $hasActiveShares
62
-	 */
63
-	protected $hasActiveShares;
64
-	/**
65
-	 * @var IConfig $config
66
-	 */
67
-	protected $config;
68
-	/**
69
-	 * @var IDBConnection $db
70
-	 */
71
-	protected $db;
72
-	/**
73
-	 * @var \OCA\User_LDAP\Mapping\UserMapping
74
-	 */
75
-	protected $mapping;
76
-
77
-	/**
78
-	 * @param string $ocName
79
-	 * @param IConfig $config
80
-	 * @param IDBConnection $db
81
-	 * @param \OCA\User_LDAP\Mapping\UserMapping $mapping
82
-	 */
83
-	public function __construct($ocName, IConfig $config, IDBConnection $db, UserMapping $mapping) {
84
-		$this->ocName = $ocName;
85
-		$this->config = $config;
86
-		$this->db = $db;
87
-		$this->mapping = $mapping;
88
-		$this->fetchDetails();
89
-	}
90
-
91
-	/**
92
-	 * remove the Delete-flag from the user.
93
-	 */
94
-	public function unmark() {
95
-		$this->config->setUserValue($this->ocName, 'user_ldap', 'isDeleted', '0');
96
-	}
97
-
98
-	/**
99
-	 * exports the user details in an assoc array
100
-	 * @return array
101
-	 */
102
-	public function export() {
103
-		$data = array();
104
-		$data['ocName'] = $this->getOCName();
105
-		$data['dn'] = $this->getDN();
106
-		$data['uid'] = $this->getUID();
107
-		$data['displayName'] = $this->getDisplayName();
108
-		$data['homePath'] = $this->getHomePath();
109
-		$data['lastLogin'] = $this->getLastLogin();
110
-		$data['email'] = $this->getEmail();
111
-		$data['hasActiveShares'] = $this->getHasActiveShares();
112
-
113
-		return $data;
114
-	}
115
-
116
-	/**
117
-	 * getter for Nextcloud internal name
118
-	 * @return string
119
-	 */
120
-	public function getOCName() {
121
-		return $this->ocName;
122
-	}
123
-
124
-	/**
125
-	 * getter for LDAP uid
126
-	 * @return string
127
-	 */
128
-	public function getUID() {
129
-		return $this->uid;
130
-	}
131
-
132
-	/**
133
-	 * getter for LDAP DN
134
-	 * @return string
135
-	 */
136
-	public function getDN() {
137
-		return $this->dn;
138
-	}
139
-
140
-	/**
141
-	 * getter for display name
142
-	 * @return string
143
-	 */
144
-	public function getDisplayName() {
145
-		return $this->displayName;
146
-	}
147
-
148
-	/**
149
-	 * getter for email
150
-	 * @return string
151
-	 */
152
-	public function getEmail() {
153
-		return $this->email;
154
-	}
155
-
156
-	/**
157
-	 * getter for home directory path
158
-	 * @return string
159
-	 */
160
-	public function getHomePath() {
161
-		return $this->homePath;
162
-	}
163
-
164
-	/**
165
-	 * getter for the last login timestamp
166
-	 * @return int
167
-	 */
168
-	public function getLastLogin() {
169
-		return intval($this->lastLogin);
170
-	}
171
-
172
-	/**
173
-	 * getter for having active shares
174
-	 * @return bool
175
-	 */
176
-	public function getHasActiveShares() {
177
-		return $this->hasActiveShares;
178
-	}
179
-
180
-	/**
181
-	 * reads the user details
182
-	 */
183
-	protected function fetchDetails() {
184
-		$properties = array (
185
-			'displayName' => 'user_ldap',
186
-			'uid'         => 'user_ldap',
187
-			'homePath'    => 'user_ldap',
188
-			'email'       => 'settings',
189
-			'lastLogin'   => 'login'
190
-		);
191
-		foreach($properties as $property => $app) {
192
-			$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
193
-		}
194
-
195
-		$dn = $this->mapping->getDNByName($this->ocName);
196
-		$this->dn = ($dn !== false) ? $dn : '';
197
-
198
-		$this->determineShares();
199
-	}
200
-
201
-
202
-	/**
203
-	 * finds out whether the user has active shares. The result is stored in
204
-	 * $this->hasActiveShares
205
-	 */
206
-	protected function determineShares() {
207
-		$query = $this->db->prepare('
32
+    /**
33
+     * @var string $ocName
34
+     */
35
+    protected $ocName;
36
+    /**
37
+     * @var string $dn
38
+     */
39
+    protected $dn;
40
+    /**
41
+     * @var string $uid the UID as provided by LDAP
42
+     */
43
+    protected $uid;
44
+    /**
45
+     * @var string $displayName
46
+     */
47
+    protected $displayName;
48
+    /**
49
+     * @var string $homePath
50
+     */
51
+    protected $homePath;
52
+    /**
53
+     * @var string $lastLogin the timestamp of the last login
54
+     */
55
+    protected $lastLogin;
56
+    /**
57
+     * @var string $email
58
+     */
59
+    protected $email;
60
+    /**
61
+     * @var bool $hasActiveShares
62
+     */
63
+    protected $hasActiveShares;
64
+    /**
65
+     * @var IConfig $config
66
+     */
67
+    protected $config;
68
+    /**
69
+     * @var IDBConnection $db
70
+     */
71
+    protected $db;
72
+    /**
73
+     * @var \OCA\User_LDAP\Mapping\UserMapping
74
+     */
75
+    protected $mapping;
76
+
77
+    /**
78
+     * @param string $ocName
79
+     * @param IConfig $config
80
+     * @param IDBConnection $db
81
+     * @param \OCA\User_LDAP\Mapping\UserMapping $mapping
82
+     */
83
+    public function __construct($ocName, IConfig $config, IDBConnection $db, UserMapping $mapping) {
84
+        $this->ocName = $ocName;
85
+        $this->config = $config;
86
+        $this->db = $db;
87
+        $this->mapping = $mapping;
88
+        $this->fetchDetails();
89
+    }
90
+
91
+    /**
92
+     * remove the Delete-flag from the user.
93
+     */
94
+    public function unmark() {
95
+        $this->config->setUserValue($this->ocName, 'user_ldap', 'isDeleted', '0');
96
+    }
97
+
98
+    /**
99
+     * exports the user details in an assoc array
100
+     * @return array
101
+     */
102
+    public function export() {
103
+        $data = array();
104
+        $data['ocName'] = $this->getOCName();
105
+        $data['dn'] = $this->getDN();
106
+        $data['uid'] = $this->getUID();
107
+        $data['displayName'] = $this->getDisplayName();
108
+        $data['homePath'] = $this->getHomePath();
109
+        $data['lastLogin'] = $this->getLastLogin();
110
+        $data['email'] = $this->getEmail();
111
+        $data['hasActiveShares'] = $this->getHasActiveShares();
112
+
113
+        return $data;
114
+    }
115
+
116
+    /**
117
+     * getter for Nextcloud internal name
118
+     * @return string
119
+     */
120
+    public function getOCName() {
121
+        return $this->ocName;
122
+    }
123
+
124
+    /**
125
+     * getter for LDAP uid
126
+     * @return string
127
+     */
128
+    public function getUID() {
129
+        return $this->uid;
130
+    }
131
+
132
+    /**
133
+     * getter for LDAP DN
134
+     * @return string
135
+     */
136
+    public function getDN() {
137
+        return $this->dn;
138
+    }
139
+
140
+    /**
141
+     * getter for display name
142
+     * @return string
143
+     */
144
+    public function getDisplayName() {
145
+        return $this->displayName;
146
+    }
147
+
148
+    /**
149
+     * getter for email
150
+     * @return string
151
+     */
152
+    public function getEmail() {
153
+        return $this->email;
154
+    }
155
+
156
+    /**
157
+     * getter for home directory path
158
+     * @return string
159
+     */
160
+    public function getHomePath() {
161
+        return $this->homePath;
162
+    }
163
+
164
+    /**
165
+     * getter for the last login timestamp
166
+     * @return int
167
+     */
168
+    public function getLastLogin() {
169
+        return intval($this->lastLogin);
170
+    }
171
+
172
+    /**
173
+     * getter for having active shares
174
+     * @return bool
175
+     */
176
+    public function getHasActiveShares() {
177
+        return $this->hasActiveShares;
178
+    }
179
+
180
+    /**
181
+     * reads the user details
182
+     */
183
+    protected function fetchDetails() {
184
+        $properties = array (
185
+            'displayName' => 'user_ldap',
186
+            'uid'         => 'user_ldap',
187
+            'homePath'    => 'user_ldap',
188
+            'email'       => 'settings',
189
+            'lastLogin'   => 'login'
190
+        );
191
+        foreach($properties as $property => $app) {
192
+            $this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
193
+        }
194
+
195
+        $dn = $this->mapping->getDNByName($this->ocName);
196
+        $this->dn = ($dn !== false) ? $dn : '';
197
+
198
+        $this->determineShares();
199
+    }
200
+
201
+
202
+    /**
203
+     * finds out whether the user has active shares. The result is stored in
204
+     * $this->hasActiveShares
205
+     */
206
+    protected function determineShares() {
207
+        $query = $this->db->prepare('
208 208
 			SELECT COUNT(`uid_owner`)
209 209
 			FROM `*PREFIX*share`
210 210
 			WHERE `uid_owner` = ?
211 211
 		', 1);
212
-		$query->execute(array($this->ocName));
213
-		$sResult = $query->fetchColumn(0);
214
-		if(intval($sResult) === 1) {
215
-			$this->hasActiveShares = true;
216
-			return;
217
-		}
218
-
219
-		$query = $this->db->prepare('
212
+        $query->execute(array($this->ocName));
213
+        $sResult = $query->fetchColumn(0);
214
+        if(intval($sResult) === 1) {
215
+            $this->hasActiveShares = true;
216
+            return;
217
+        }
218
+
219
+        $query = $this->db->prepare('
220 220
 			SELECT COUNT(`owner`)
221 221
 			FROM `*PREFIX*share_external`
222 222
 			WHERE `owner` = ?
223 223
 		', 1);
224
-		$query->execute(array($this->ocName));
225
-		$sResult = $query->fetchColumn(0);
226
-		if(intval($sResult) === 1) {
227
-			$this->hasActiveShares = true;
228
-			return;
229
-		}
230
-
231
-		$this->hasActiveShares = false;
232
-	}
224
+        $query->execute(array($this->ocName));
225
+        $sResult = $query->fetchColumn(0);
226
+        if(intval($sResult) === 1) {
227
+            $this->hasActiveShares = true;
228
+            return;
229
+        }
230
+
231
+        $this->hasActiveShares = false;
232
+    }
233 233
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User_LDAP.php 2 patches
Indentation   +514 added lines, -514 removed lines patch added patch discarded remove patch
@@ -46,521 +46,521 @@
 block discarded – undo
46 46
 use OCP\Util;
47 47
 
48 48
 class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP {
49
-	/** @var \OCP\IConfig */
50
-	protected $ocConfig;
51
-
52
-	/** @var INotificationManager */
53
-	protected $notificationManager;
54
-
55
-	/** @var string */
56
-	protected $currentUserInDeletionProcess;
57
-
58
-	/**
59
-	 * @param Access $access
60
-	 * @param \OCP\IConfig $ocConfig
61
-	 * @param \OCP\Notification\IManager $notificationManager
62
-	 */
63
-	public function __construct(Access $access, IConfig $ocConfig, INotificationManager $notificationManager) {
64
-		parent::__construct($access);
65
-		$this->ocConfig = $ocConfig;
66
-		$this->notificationManager = $notificationManager;
67
-		$this->registerHooks();
68
-	}
69
-
70
-	protected function registerHooks() {
71
-		Util::connectHook('OC_User','pre_deleteUser', $this, 'preDeleteUser');
72
-		Util::connectHook('OC_User','post_deleteUser', $this, 'postDeleteUser');
73
-	}
74
-
75
-	public function preDeleteUser(array $param) {
76
-		$user = $param[0];
77
-		if(!$user instanceof IUser) {
78
-			throw new \RuntimeException('IUser expected');
79
-		}
80
-		$this->currentUserInDeletionProcess = $user->getUID();
81
-	}
82
-
83
-	public function postDeleteUser() {
84
-		$this->currentUserInDeletionProcess = null;
85
-	}
86
-
87
-	/**
88
-	 * checks whether the user is allowed to change his avatar in Nextcloud
89
-	 * @param string $uid the Nextcloud user name
90
-	 * @return boolean either the user can or cannot
91
-	 */
92
-	public function canChangeAvatar($uid) {
93
-		$user = $this->access->userManager->get($uid);
94
-		if(!$user instanceof User) {
95
-			return false;
96
-		}
97
-		if($user->getAvatarImage() === false) {
98
-			return true;
99
-		}
100
-
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * returns the username for the given login name, if available
106
-	 *
107
-	 * @param string $loginName
108
-	 * @return string|false
109
-	 */
110
-	public function loginName2UserName($loginName) {
111
-		$cacheKey = 'loginName2UserName-'.$loginName;
112
-		$username = $this->access->connection->getFromCache($cacheKey);
113
-		if(!is_null($username)) {
114
-			return $username;
115
-		}
116
-
117
-		try {
118
-			$ldapRecord = $this->getLDAPUserByLoginName($loginName);
119
-			$user = $this->access->userManager->get($ldapRecord['dn'][0]);
120
-			if($user instanceof OfflineUser) {
121
-				// this path is not really possible, however get() is documented
122
-				// to return User or OfflineUser so we are very defensive here.
123
-				$this->access->connection->writeToCache($cacheKey, false);
124
-				return false;
125
-			}
126
-			$username = $user->getUsername();
127
-			$this->access->connection->writeToCache($cacheKey, $username);
128
-			return $username;
129
-		} catch (NotOnLDAP $e) {
130
-			$this->access->connection->writeToCache($cacheKey, false);
131
-			return false;
132
-		}
133
-	}
49
+    /** @var \OCP\IConfig */
50
+    protected $ocConfig;
51
+
52
+    /** @var INotificationManager */
53
+    protected $notificationManager;
54
+
55
+    /** @var string */
56
+    protected $currentUserInDeletionProcess;
57
+
58
+    /**
59
+     * @param Access $access
60
+     * @param \OCP\IConfig $ocConfig
61
+     * @param \OCP\Notification\IManager $notificationManager
62
+     */
63
+    public function __construct(Access $access, IConfig $ocConfig, INotificationManager $notificationManager) {
64
+        parent::__construct($access);
65
+        $this->ocConfig = $ocConfig;
66
+        $this->notificationManager = $notificationManager;
67
+        $this->registerHooks();
68
+    }
69
+
70
+    protected function registerHooks() {
71
+        Util::connectHook('OC_User','pre_deleteUser', $this, 'preDeleteUser');
72
+        Util::connectHook('OC_User','post_deleteUser', $this, 'postDeleteUser');
73
+    }
74
+
75
+    public function preDeleteUser(array $param) {
76
+        $user = $param[0];
77
+        if(!$user instanceof IUser) {
78
+            throw new \RuntimeException('IUser expected');
79
+        }
80
+        $this->currentUserInDeletionProcess = $user->getUID();
81
+    }
82
+
83
+    public function postDeleteUser() {
84
+        $this->currentUserInDeletionProcess = null;
85
+    }
86
+
87
+    /**
88
+     * checks whether the user is allowed to change his avatar in Nextcloud
89
+     * @param string $uid the Nextcloud user name
90
+     * @return boolean either the user can or cannot
91
+     */
92
+    public function canChangeAvatar($uid) {
93
+        $user = $this->access->userManager->get($uid);
94
+        if(!$user instanceof User) {
95
+            return false;
96
+        }
97
+        if($user->getAvatarImage() === false) {
98
+            return true;
99
+        }
100
+
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * returns the username for the given login name, if available
106
+     *
107
+     * @param string $loginName
108
+     * @return string|false
109
+     */
110
+    public function loginName2UserName($loginName) {
111
+        $cacheKey = 'loginName2UserName-'.$loginName;
112
+        $username = $this->access->connection->getFromCache($cacheKey);
113
+        if(!is_null($username)) {
114
+            return $username;
115
+        }
116
+
117
+        try {
118
+            $ldapRecord = $this->getLDAPUserByLoginName($loginName);
119
+            $user = $this->access->userManager->get($ldapRecord['dn'][0]);
120
+            if($user instanceof OfflineUser) {
121
+                // this path is not really possible, however get() is documented
122
+                // to return User or OfflineUser so we are very defensive here.
123
+                $this->access->connection->writeToCache($cacheKey, false);
124
+                return false;
125
+            }
126
+            $username = $user->getUsername();
127
+            $this->access->connection->writeToCache($cacheKey, $username);
128
+            return $username;
129
+        } catch (NotOnLDAP $e) {
130
+            $this->access->connection->writeToCache($cacheKey, false);
131
+            return false;
132
+        }
133
+    }
134 134
 	
135
-	/**
136
-	 * returns the username for the given LDAP DN, if available
137
-	 *
138
-	 * @param string $dn
139
-	 * @return string|false with the username
140
-	 */
141
-	public function dn2UserName($dn) {
142
-		return $this->access->dn2username($dn);
143
-	}
144
-
145
-	/**
146
-	 * returns an LDAP record based on a given login name
147
-	 *
148
-	 * @param string $loginName
149
-	 * @return array
150
-	 * @throws NotOnLDAP
151
-	 */
152
-	public function getLDAPUserByLoginName($loginName) {
153
-		//find out dn of the user name
154
-		$attrs = $this->access->userManager->getAttributes();
155
-		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
156
-		if(count($users) < 1) {
157
-			throw new NotOnLDAP('No user available for the given login name on ' .
158
-				$this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
159
-		}
160
-		return $users[0];
161
-	}
162
-
163
-	/**
164
-	 * Check if the password is correct without logging in the user
165
-	 *
166
-	 * @param string $uid The username
167
-	 * @param string $password The password
168
-	 * @return false|string
169
-	 */
170
-	public function checkPassword($uid, $password) {
171
-		try {
172
-			$ldapRecord = $this->getLDAPUserByLoginName($uid);
173
-		} catch(NotOnLDAP $e) {
174
-			if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
175
-				\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
176
-			}
177
-			return false;
178
-		}
179
-		$dn = $ldapRecord['dn'][0];
180
-		$user = $this->access->userManager->get($dn);
181
-
182
-		if(!$user instanceof User) {
183
-			Util::writeLog('user_ldap',
184
-				'LDAP Login: Could not get user object for DN ' . $dn .
185
-				'. Maybe the LDAP entry has no set display name attribute?',
186
-				Util::WARN);
187
-			return false;
188
-		}
189
-		if($user->getUsername() !== false) {
190
-			//are the credentials OK?
191
-			if(!$this->access->areCredentialsValid($dn, $password)) {
192
-				return false;
193
-			}
194
-
195
-			$this->access->cacheUserExists($user->getUsername());
196
-			$user->processAttributes($ldapRecord);
197
-			$user->markLogin();
198
-
199
-			return $user->getUsername();
200
-		}
201
-
202
-		return false;
203
-	}
204
-
205
-	/**
206
-	 * Set password
207
-	 * @param string $uid The username
208
-	 * @param string $password The new password
209
-	 * @return bool
210
-	 */
211
-	public function setPassword($uid, $password) {
212
-		$user = $this->access->userManager->get($uid);
213
-
214
-		if(!$user instanceof User) {
215
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
216
-				'. Maybe the LDAP entry has no set display name attribute?');
217
-		}
218
-		if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
219
-			$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
220
-			$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
221
-			if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
222
-				//remove last password expiry warning if any
223
-				$notification = $this->notificationManager->createNotification();
224
-				$notification->setApp('user_ldap')
225
-					->setUser($uid)
226
-					->setObject('pwd_exp_warn', $uid)
227
-				;
228
-				$this->notificationManager->markProcessed($notification);
229
-			}
230
-			return true;
231
-		}
232
-
233
-		return false;
234
-	}
235
-
236
-	/**
237
-	 * Get a list of all users
238
-	 *
239
-	 * @param string $search
240
-	 * @param integer $limit
241
-	 * @param integer $offset
242
-	 * @return string[] an array of all uids
243
-	 */
244
-	public function getUsers($search = '', $limit = 10, $offset = 0) {
245
-		$search = $this->access->escapeFilterPart($search, true);
246
-		$cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
247
-
248
-		//check if users are cached, if so return
249
-		$ldap_users = $this->access->connection->getFromCache($cachekey);
250
-		if(!is_null($ldap_users)) {
251
-			return $ldap_users;
252
-		}
253
-
254
-		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
255
-		// error. With a limit of 0, we get 0 results. So we pass null.
256
-		if($limit <= 0) {
257
-			$limit = null;
258
-		}
259
-		$filter = $this->access->combineFilterWithAnd(array(
260
-			$this->access->connection->ldapUserFilter,
261
-			$this->access->connection->ldapUserDisplayName . '=*',
262
-			$this->access->getFilterPartForUserSearch($search)
263
-		));
264
-
265
-		Util::writeLog('user_ldap',
266
-			'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
267
-			Util::DEBUG);
268
-		//do the search and translate results to owncloud names
269
-		$ldap_users = $this->access->fetchListOfUsers(
270
-			$filter,
271
-			$this->access->userManager->getAttributes(true),
272
-			$limit, $offset);
273
-		$ldap_users = $this->access->nextcloudUserNames($ldap_users);
274
-		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
275
-
276
-		$this->access->connection->writeToCache($cachekey, $ldap_users);
277
-		return $ldap_users;
278
-	}
279
-
280
-	/**
281
-	 * checks whether a user is still available on LDAP
282
-	 *
283
-	 * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
284
-	 * name or an instance of that user
285
-	 * @return bool
286
-	 * @throws \Exception
287
-	 * @throws \OC\ServerNotAvailableException
288
-	 */
289
-	public function userExistsOnLDAP($user) {
290
-		if(is_string($user)) {
291
-			$user = $this->access->userManager->get($user);
292
-		}
293
-		if(is_null($user)) {
294
-			return false;
295
-		}
296
-
297
-		$dn = $user->getDN();
298
-		//check if user really still exists by reading its entry
299
-		if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
300
-			$lcr = $this->access->connection->getConnectionResource();
301
-			if(is_null($lcr)) {
302
-				throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
303
-			}
304
-
305
-			try {
306
-				$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
307
-				if(!$uuid) {
308
-					return false;
309
-				}
310
-				$newDn = $this->access->getUserDnByUuid($uuid);
311
-				//check if renamed user is still valid by reapplying the ldap filter
312
-				if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
313
-					return false;
314
-				}
315
-				$this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
316
-				return true;
317
-			} catch (\Exception $e) {
318
-				return false;
319
-			}
320
-		}
321
-
322
-		if($user instanceof OfflineUser) {
323
-			$user->unmark();
324
-		}
325
-
326
-		return true;
327
-	}
328
-
329
-	/**
330
-	 * check if a user exists
331
-	 * @param string $uid the username
332
-	 * @return boolean
333
-	 * @throws \Exception when connection could not be established
334
-	 */
335
-	public function userExists($uid) {
336
-		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
337
-		if(!is_null($userExists)) {
338
-			return (bool)$userExists;
339
-		}
340
-		//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
341
-		$user = $this->access->userManager->get($uid);
342
-
343
-		if(is_null($user)) {
344
-			Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
345
-				$this->access->connection->ldapHost, Util::DEBUG);
346
-			$this->access->connection->writeToCache('userExists'.$uid, false);
347
-			return false;
348
-		} else if($user instanceof OfflineUser) {
349
-			//express check for users marked as deleted. Returning true is
350
-			//necessary for cleanup
351
-			return true;
352
-		}
353
-
354
-		$result = $this->userExistsOnLDAP($user);
355
-		$this->access->connection->writeToCache('userExists'.$uid, $result);
356
-		if($result === true) {
357
-			$user->update();
358
-		}
359
-		return $result;
360
-	}
361
-
362
-	/**
363
-	* returns whether a user was deleted in LDAP
364
-	*
365
-	* @param string $uid The username of the user to delete
366
-	* @return bool
367
-	*/
368
-	public function deleteUser($uid) {
369
-		$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
370
-		if(intval($marked) === 0) {
371
-			\OC::$server->getLogger()->notice(
372
-				'User '.$uid . ' is not marked as deleted, not cleaning up.',
373
-				array('app' => 'user_ldap'));
374
-			return false;
375
-		}
376
-		\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
377
-			array('app' => 'user_ldap'));
378
-
379
-		//Get Home Directory out of user preferences so we can return it later,
380
-		//necessary for removing directories as done by OC_User.
381
-		$this->access->getUserMapper()->unmap($uid);
382
-		$this->access->userManager->invalidate($uid);
383
-		return true;
384
-	}
385
-
386
-	/**
387
-	 * get the user's home directory
388
-	 *
389
-	 * @param string $uid the username
390
-	 * @return bool|string
391
-	 * @throws NoUserException
392
-	 * @throws \Exception
393
-	 */
394
-	public function getHome($uid) {
395
-		// user Exists check required as it is not done in user proxy!
396
-		if(!$this->userExists($uid)) {
397
-			return false;
398
-		}
399
-
400
-		$cacheKey = 'getHome'.$uid;
401
-		$path = $this->access->connection->getFromCache($cacheKey);
402
-		if(!is_null($path)) {
403
-			return $path;
404
-		}
405
-
406
-		// early return path if it is a deleted user
407
-		$user = $this->access->userManager->get($uid);
408
-		if($user instanceof OfflineUser) {
409
-			if($this->currentUserInDeletionProcess === $user->getUID()) {
410
-				return $user->getHomePath();
411
-			} else {
412
-				throw new NoUserException($uid . ' is not a valid user anymore');
413
-			}
414
-		} else if ($user === null) {
415
-			throw new NoUserException($uid . ' is not a valid user anymore');
416
-		}
417
-
418
-		$path = $user->getHomePath();
419
-		$this->access->cacheUserHome($uid, $path);
420
-
421
-		return $path;
422
-	}
423
-
424
-	/**
425
-	 * get display name of the user
426
-	 * @param string $uid user ID of the user
427
-	 * @return string|false display name
428
-	 */
429
-	public function getDisplayName($uid) {
430
-		if(!$this->userExists($uid)) {
431
-			return false;
432
-		}
433
-
434
-		$cacheKey = 'getDisplayName'.$uid;
435
-		if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
436
-			return $displayName;
437
-		}
438
-
439
-		//Check whether the display name is configured to have a 2nd feature
440
-		$additionalAttribute = $this->access->connection->ldapUserDisplayName2;
441
-		$displayName2 = '';
442
-		if ($additionalAttribute !== '') {
443
-			$displayName2 = $this->access->readAttribute(
444
-				$this->access->username2dn($uid),
445
-				$additionalAttribute);
446
-		}
447
-
448
-		$displayName = $this->access->readAttribute(
449
-			$this->access->username2dn($uid),
450
-			$this->access->connection->ldapUserDisplayName);
451
-
452
-		if($displayName && (count($displayName) > 0)) {
453
-			$displayName = $displayName[0];
454
-
455
-			if (is_array($displayName2)){
456
-				$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
457
-			}
458
-
459
-			$user = $this->access->userManager->get($uid);
460
-			if ($user instanceof User) {
461
-				$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
462
-				$this->access->connection->writeToCache($cacheKey, $displayName);
463
-			}
464
-			if ($user instanceof OfflineUser) {
465
-				/** @var OfflineUser $user*/
466
-				$displayName = $user->getDisplayName();
467
-			}
468
-			return $displayName;
469
-		}
470
-
471
-		return null;
472
-	}
473
-
474
-	/**
475
-	 * Get a list of all display names
476
-	 *
477
-	 * @param string $search
478
-	 * @param string|null $limit
479
-	 * @param string|null $offset
480
-	 * @return array an array of all displayNames (value) and the corresponding uids (key)
481
-	 */
482
-	public function getDisplayNames($search = '', $limit = null, $offset = null) {
483
-		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
484
-		if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
485
-			return $displayNames;
486
-		}
487
-
488
-		$displayNames = array();
489
-		$users = $this->getUsers($search, $limit, $offset);
490
-		foreach ($users as $user) {
491
-			$displayNames[$user] = $this->getDisplayName($user);
492
-		}
493
-		$this->access->connection->writeToCache($cacheKey, $displayNames);
494
-		return $displayNames;
495
-	}
496
-
497
-	/**
498
-	* Check if backend implements actions
499
-	* @param int $actions bitwise-or'ed actions
500
-	* @return boolean
501
-	*
502
-	* Returns the supported actions as int to be
503
-	* compared with OC_USER_BACKEND_CREATE_USER etc.
504
-	*/
505
-	public function implementsActions($actions) {
506
-		return (bool)((Backend::CHECK_PASSWORD
507
-			| Backend::GET_HOME
508
-			| Backend::GET_DISPLAYNAME
509
-			| Backend::PROVIDE_AVATAR
510
-			| Backend::COUNT_USERS
511
-			| ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0))
512
-			& $actions);
513
-	}
514
-
515
-	/**
516
-	 * @return bool
517
-	 */
518
-	public function hasUserListings() {
519
-		return true;
520
-	}
521
-
522
-	/**
523
-	 * counts the users in LDAP
524
-	 *
525
-	 * @return int|bool
526
-	 */
527
-	public function countUsers() {
528
-		$filter = $this->access->getFilterForUserCount();
529
-		$cacheKey = 'countUsers-'.$filter;
530
-		if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
531
-			return $entries;
532
-		}
533
-		$entries = $this->access->countUsers($filter);
534
-		$this->access->connection->writeToCache($cacheKey, $entries);
535
-		return $entries;
536
-	}
537
-
538
-	/**
539
-	 * Backend name to be shown in user management
540
-	 * @return string the name of the backend to be shown
541
-	 */
542
-	public function getBackendName(){
543
-		return 'LDAP';
544
-	}
135
+    /**
136
+     * returns the username for the given LDAP DN, if available
137
+     *
138
+     * @param string $dn
139
+     * @return string|false with the username
140
+     */
141
+    public function dn2UserName($dn) {
142
+        return $this->access->dn2username($dn);
143
+    }
144
+
145
+    /**
146
+     * returns an LDAP record based on a given login name
147
+     *
148
+     * @param string $loginName
149
+     * @return array
150
+     * @throws NotOnLDAP
151
+     */
152
+    public function getLDAPUserByLoginName($loginName) {
153
+        //find out dn of the user name
154
+        $attrs = $this->access->userManager->getAttributes();
155
+        $users = $this->access->fetchUsersByLoginName($loginName, $attrs);
156
+        if(count($users) < 1) {
157
+            throw new NotOnLDAP('No user available for the given login name on ' .
158
+                $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
159
+        }
160
+        return $users[0];
161
+    }
162
+
163
+    /**
164
+     * Check if the password is correct without logging in the user
165
+     *
166
+     * @param string $uid The username
167
+     * @param string $password The password
168
+     * @return false|string
169
+     */
170
+    public function checkPassword($uid, $password) {
171
+        try {
172
+            $ldapRecord = $this->getLDAPUserByLoginName($uid);
173
+        } catch(NotOnLDAP $e) {
174
+            if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
175
+                \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
176
+            }
177
+            return false;
178
+        }
179
+        $dn = $ldapRecord['dn'][0];
180
+        $user = $this->access->userManager->get($dn);
181
+
182
+        if(!$user instanceof User) {
183
+            Util::writeLog('user_ldap',
184
+                'LDAP Login: Could not get user object for DN ' . $dn .
185
+                '. Maybe the LDAP entry has no set display name attribute?',
186
+                Util::WARN);
187
+            return false;
188
+        }
189
+        if($user->getUsername() !== false) {
190
+            //are the credentials OK?
191
+            if(!$this->access->areCredentialsValid($dn, $password)) {
192
+                return false;
193
+            }
194
+
195
+            $this->access->cacheUserExists($user->getUsername());
196
+            $user->processAttributes($ldapRecord);
197
+            $user->markLogin();
198
+
199
+            return $user->getUsername();
200
+        }
201
+
202
+        return false;
203
+    }
204
+
205
+    /**
206
+     * Set password
207
+     * @param string $uid The username
208
+     * @param string $password The new password
209
+     * @return bool
210
+     */
211
+    public function setPassword($uid, $password) {
212
+        $user = $this->access->userManager->get($uid);
213
+
214
+        if(!$user instanceof User) {
215
+            throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
216
+                '. Maybe the LDAP entry has no set display name attribute?');
217
+        }
218
+        if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
219
+            $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
220
+            $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
221
+            if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
222
+                //remove last password expiry warning if any
223
+                $notification = $this->notificationManager->createNotification();
224
+                $notification->setApp('user_ldap')
225
+                    ->setUser($uid)
226
+                    ->setObject('pwd_exp_warn', $uid)
227
+                ;
228
+                $this->notificationManager->markProcessed($notification);
229
+            }
230
+            return true;
231
+        }
232
+
233
+        return false;
234
+    }
235
+
236
+    /**
237
+     * Get a list of all users
238
+     *
239
+     * @param string $search
240
+     * @param integer $limit
241
+     * @param integer $offset
242
+     * @return string[] an array of all uids
243
+     */
244
+    public function getUsers($search = '', $limit = 10, $offset = 0) {
245
+        $search = $this->access->escapeFilterPart($search, true);
246
+        $cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
247
+
248
+        //check if users are cached, if so return
249
+        $ldap_users = $this->access->connection->getFromCache($cachekey);
250
+        if(!is_null($ldap_users)) {
251
+            return $ldap_users;
252
+        }
253
+
254
+        // if we'd pass -1 to LDAP search, we'd end up in a Protocol
255
+        // error. With a limit of 0, we get 0 results. So we pass null.
256
+        if($limit <= 0) {
257
+            $limit = null;
258
+        }
259
+        $filter = $this->access->combineFilterWithAnd(array(
260
+            $this->access->connection->ldapUserFilter,
261
+            $this->access->connection->ldapUserDisplayName . '=*',
262
+            $this->access->getFilterPartForUserSearch($search)
263
+        ));
264
+
265
+        Util::writeLog('user_ldap',
266
+            'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
267
+            Util::DEBUG);
268
+        //do the search and translate results to owncloud names
269
+        $ldap_users = $this->access->fetchListOfUsers(
270
+            $filter,
271
+            $this->access->userManager->getAttributes(true),
272
+            $limit, $offset);
273
+        $ldap_users = $this->access->nextcloudUserNames($ldap_users);
274
+        Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
275
+
276
+        $this->access->connection->writeToCache($cachekey, $ldap_users);
277
+        return $ldap_users;
278
+    }
279
+
280
+    /**
281
+     * checks whether a user is still available on LDAP
282
+     *
283
+     * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
284
+     * name or an instance of that user
285
+     * @return bool
286
+     * @throws \Exception
287
+     * @throws \OC\ServerNotAvailableException
288
+     */
289
+    public function userExistsOnLDAP($user) {
290
+        if(is_string($user)) {
291
+            $user = $this->access->userManager->get($user);
292
+        }
293
+        if(is_null($user)) {
294
+            return false;
295
+        }
296
+
297
+        $dn = $user->getDN();
298
+        //check if user really still exists by reading its entry
299
+        if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
300
+            $lcr = $this->access->connection->getConnectionResource();
301
+            if(is_null($lcr)) {
302
+                throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
303
+            }
304
+
305
+            try {
306
+                $uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
307
+                if(!$uuid) {
308
+                    return false;
309
+                }
310
+                $newDn = $this->access->getUserDnByUuid($uuid);
311
+                //check if renamed user is still valid by reapplying the ldap filter
312
+                if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
313
+                    return false;
314
+                }
315
+                $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
316
+                return true;
317
+            } catch (\Exception $e) {
318
+                return false;
319
+            }
320
+        }
321
+
322
+        if($user instanceof OfflineUser) {
323
+            $user->unmark();
324
+        }
325
+
326
+        return true;
327
+    }
328
+
329
+    /**
330
+     * check if a user exists
331
+     * @param string $uid the username
332
+     * @return boolean
333
+     * @throws \Exception when connection could not be established
334
+     */
335
+    public function userExists($uid) {
336
+        $userExists = $this->access->connection->getFromCache('userExists'.$uid);
337
+        if(!is_null($userExists)) {
338
+            return (bool)$userExists;
339
+        }
340
+        //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
341
+        $user = $this->access->userManager->get($uid);
342
+
343
+        if(is_null($user)) {
344
+            Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
345
+                $this->access->connection->ldapHost, Util::DEBUG);
346
+            $this->access->connection->writeToCache('userExists'.$uid, false);
347
+            return false;
348
+        } else if($user instanceof OfflineUser) {
349
+            //express check for users marked as deleted. Returning true is
350
+            //necessary for cleanup
351
+            return true;
352
+        }
353
+
354
+        $result = $this->userExistsOnLDAP($user);
355
+        $this->access->connection->writeToCache('userExists'.$uid, $result);
356
+        if($result === true) {
357
+            $user->update();
358
+        }
359
+        return $result;
360
+    }
361
+
362
+    /**
363
+     * returns whether a user was deleted in LDAP
364
+     *
365
+     * @param string $uid The username of the user to delete
366
+     * @return bool
367
+     */
368
+    public function deleteUser($uid) {
369
+        $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
370
+        if(intval($marked) === 0) {
371
+            \OC::$server->getLogger()->notice(
372
+                'User '.$uid . ' is not marked as deleted, not cleaning up.',
373
+                array('app' => 'user_ldap'));
374
+            return false;
375
+        }
376
+        \OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
377
+            array('app' => 'user_ldap'));
378
+
379
+        //Get Home Directory out of user preferences so we can return it later,
380
+        //necessary for removing directories as done by OC_User.
381
+        $this->access->getUserMapper()->unmap($uid);
382
+        $this->access->userManager->invalidate($uid);
383
+        return true;
384
+    }
385
+
386
+    /**
387
+     * get the user's home directory
388
+     *
389
+     * @param string $uid the username
390
+     * @return bool|string
391
+     * @throws NoUserException
392
+     * @throws \Exception
393
+     */
394
+    public function getHome($uid) {
395
+        // user Exists check required as it is not done in user proxy!
396
+        if(!$this->userExists($uid)) {
397
+            return false;
398
+        }
399
+
400
+        $cacheKey = 'getHome'.$uid;
401
+        $path = $this->access->connection->getFromCache($cacheKey);
402
+        if(!is_null($path)) {
403
+            return $path;
404
+        }
405
+
406
+        // early return path if it is a deleted user
407
+        $user = $this->access->userManager->get($uid);
408
+        if($user instanceof OfflineUser) {
409
+            if($this->currentUserInDeletionProcess === $user->getUID()) {
410
+                return $user->getHomePath();
411
+            } else {
412
+                throw new NoUserException($uid . ' is not a valid user anymore');
413
+            }
414
+        } else if ($user === null) {
415
+            throw new NoUserException($uid . ' is not a valid user anymore');
416
+        }
417
+
418
+        $path = $user->getHomePath();
419
+        $this->access->cacheUserHome($uid, $path);
420
+
421
+        return $path;
422
+    }
423
+
424
+    /**
425
+     * get display name of the user
426
+     * @param string $uid user ID of the user
427
+     * @return string|false display name
428
+     */
429
+    public function getDisplayName($uid) {
430
+        if(!$this->userExists($uid)) {
431
+            return false;
432
+        }
433
+
434
+        $cacheKey = 'getDisplayName'.$uid;
435
+        if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
436
+            return $displayName;
437
+        }
438
+
439
+        //Check whether the display name is configured to have a 2nd feature
440
+        $additionalAttribute = $this->access->connection->ldapUserDisplayName2;
441
+        $displayName2 = '';
442
+        if ($additionalAttribute !== '') {
443
+            $displayName2 = $this->access->readAttribute(
444
+                $this->access->username2dn($uid),
445
+                $additionalAttribute);
446
+        }
447
+
448
+        $displayName = $this->access->readAttribute(
449
+            $this->access->username2dn($uid),
450
+            $this->access->connection->ldapUserDisplayName);
451
+
452
+        if($displayName && (count($displayName) > 0)) {
453
+            $displayName = $displayName[0];
454
+
455
+            if (is_array($displayName2)){
456
+                $displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
457
+            }
458
+
459
+            $user = $this->access->userManager->get($uid);
460
+            if ($user instanceof User) {
461
+                $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
462
+                $this->access->connection->writeToCache($cacheKey, $displayName);
463
+            }
464
+            if ($user instanceof OfflineUser) {
465
+                /** @var OfflineUser $user*/
466
+                $displayName = $user->getDisplayName();
467
+            }
468
+            return $displayName;
469
+        }
470
+
471
+        return null;
472
+    }
473
+
474
+    /**
475
+     * Get a list of all display names
476
+     *
477
+     * @param string $search
478
+     * @param string|null $limit
479
+     * @param string|null $offset
480
+     * @return array an array of all displayNames (value) and the corresponding uids (key)
481
+     */
482
+    public function getDisplayNames($search = '', $limit = null, $offset = null) {
483
+        $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
484
+        if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
485
+            return $displayNames;
486
+        }
487
+
488
+        $displayNames = array();
489
+        $users = $this->getUsers($search, $limit, $offset);
490
+        foreach ($users as $user) {
491
+            $displayNames[$user] = $this->getDisplayName($user);
492
+        }
493
+        $this->access->connection->writeToCache($cacheKey, $displayNames);
494
+        return $displayNames;
495
+    }
496
+
497
+    /**
498
+     * Check if backend implements actions
499
+     * @param int $actions bitwise-or'ed actions
500
+     * @return boolean
501
+     *
502
+     * Returns the supported actions as int to be
503
+     * compared with OC_USER_BACKEND_CREATE_USER etc.
504
+     */
505
+    public function implementsActions($actions) {
506
+        return (bool)((Backend::CHECK_PASSWORD
507
+            | Backend::GET_HOME
508
+            | Backend::GET_DISPLAYNAME
509
+            | Backend::PROVIDE_AVATAR
510
+            | Backend::COUNT_USERS
511
+            | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0))
512
+            & $actions);
513
+    }
514
+
515
+    /**
516
+     * @return bool
517
+     */
518
+    public function hasUserListings() {
519
+        return true;
520
+    }
521
+
522
+    /**
523
+     * counts the users in LDAP
524
+     *
525
+     * @return int|bool
526
+     */
527
+    public function countUsers() {
528
+        $filter = $this->access->getFilterForUserCount();
529
+        $cacheKey = 'countUsers-'.$filter;
530
+        if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
531
+            return $entries;
532
+        }
533
+        $entries = $this->access->countUsers($filter);
534
+        $this->access->connection->writeToCache($cacheKey, $entries);
535
+        return $entries;
536
+    }
537
+
538
+    /**
539
+     * Backend name to be shown in user management
540
+     * @return string the name of the backend to be shown
541
+     */
542
+    public function getBackendName(){
543
+        return 'LDAP';
544
+    }
545 545
 	
546
-	/**
547
-	 * Return access for LDAP interaction.
548
-	 * @param string $uid
549
-	 * @return Access instance of Access for LDAP interaction
550
-	 */
551
-	public function getLDAPAccess($uid) {
552
-		return $this->access;
553
-	}
546
+    /**
547
+     * Return access for LDAP interaction.
548
+     * @param string $uid
549
+     * @return Access instance of Access for LDAP interaction
550
+     */
551
+    public function getLDAPAccess($uid) {
552
+        return $this->access;
553
+    }
554 554
 	
555
-	/**
556
-	 * Return LDAP connection resource from a cloned connection.
557
-	 * The cloned connection needs to be closed manually.
558
-	 * of the current access.
559
-	 * @param string $uid
560
-	 * @return resource of the LDAP connection
561
-	 */
562
-	public function getNewLDAPConnection($uid) {
563
-		$connection = clone $this->access->getConnection();
564
-		return $connection->getConnectionResource();
565
-	}
555
+    /**
556
+     * Return LDAP connection resource from a cloned connection.
557
+     * The cloned connection needs to be closed manually.
558
+     * of the current access.
559
+     * @param string $uid
560
+     * @return resource of the LDAP connection
561
+     */
562
+    public function getNewLDAPConnection($uid) {
563
+        $connection = clone $this->access->getConnection();
564
+        return $connection->getConnectionResource();
565
+    }
566 566
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -68,13 +68,13 @@  discard block
 block discarded – undo
68 68
 	}
69 69
 
70 70
 	protected function registerHooks() {
71
-		Util::connectHook('OC_User','pre_deleteUser', $this, 'preDeleteUser');
72
-		Util::connectHook('OC_User','post_deleteUser', $this, 'postDeleteUser');
71
+		Util::connectHook('OC_User', 'pre_deleteUser', $this, 'preDeleteUser');
72
+		Util::connectHook('OC_User', 'post_deleteUser', $this, 'postDeleteUser');
73 73
 	}
74 74
 
75 75
 	public function preDeleteUser(array $param) {
76 76
 		$user = $param[0];
77
-		if(!$user instanceof IUser) {
77
+		if (!$user instanceof IUser) {
78 78
 			throw new \RuntimeException('IUser expected');
79 79
 		}
80 80
 		$this->currentUserInDeletionProcess = $user->getUID();
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public function canChangeAvatar($uid) {
93 93
 		$user = $this->access->userManager->get($uid);
94
-		if(!$user instanceof User) {
94
+		if (!$user instanceof User) {
95 95
 			return false;
96 96
 		}
97
-		if($user->getAvatarImage() === false) {
97
+		if ($user->getAvatarImage() === false) {
98 98
 			return true;
99 99
 		}
100 100
 
@@ -110,14 +110,14 @@  discard block
 block discarded – undo
110 110
 	public function loginName2UserName($loginName) {
111 111
 		$cacheKey = 'loginName2UserName-'.$loginName;
112 112
 		$username = $this->access->connection->getFromCache($cacheKey);
113
-		if(!is_null($username)) {
113
+		if (!is_null($username)) {
114 114
 			return $username;
115 115
 		}
116 116
 
117 117
 		try {
118 118
 			$ldapRecord = $this->getLDAPUserByLoginName($loginName);
119 119
 			$user = $this->access->userManager->get($ldapRecord['dn'][0]);
120
-			if($user instanceof OfflineUser) {
120
+			if ($user instanceof OfflineUser) {
121 121
 				// this path is not really possible, however get() is documented
122 122
 				// to return User or OfflineUser so we are very defensive here.
123 123
 				$this->access->connection->writeToCache($cacheKey, false);
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
 		//find out dn of the user name
154 154
 		$attrs = $this->access->userManager->getAttributes();
155 155
 		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
156
-		if(count($users) < 1) {
157
-			throw new NotOnLDAP('No user available for the given login name on ' .
158
-				$this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
156
+		if (count($users) < 1) {
157
+			throw new NotOnLDAP('No user available for the given login name on '.
158
+				$this->access->connection->ldapHost.':'.$this->access->connection->ldapPort);
159 159
 		}
160 160
 		return $users[0];
161 161
 	}
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 	public function checkPassword($uid, $password) {
171 171
 		try {
172 172
 			$ldapRecord = $this->getLDAPUserByLoginName($uid);
173
-		} catch(NotOnLDAP $e) {
174
-			if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
173
+		} catch (NotOnLDAP $e) {
174
+			if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
175 175
 				\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
176 176
 			}
177 177
 			return false;
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
 		$dn = $ldapRecord['dn'][0];
180 180
 		$user = $this->access->userManager->get($dn);
181 181
 
182
-		if(!$user instanceof User) {
182
+		if (!$user instanceof User) {
183 183
 			Util::writeLog('user_ldap',
184
-				'LDAP Login: Could not get user object for DN ' . $dn .
184
+				'LDAP Login: Could not get user object for DN '.$dn.
185 185
 				'. Maybe the LDAP entry has no set display name attribute?',
186 186
 				Util::WARN);
187 187
 			return false;
188 188
 		}
189
-		if($user->getUsername() !== false) {
189
+		if ($user->getUsername() !== false) {
190 190
 			//are the credentials OK?
191
-			if(!$this->access->areCredentialsValid($dn, $password)) {
191
+			if (!$this->access->areCredentialsValid($dn, $password)) {
192 192
 				return false;
193 193
 			}
194 194
 
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
 	public function setPassword($uid, $password) {
212 212
 		$user = $this->access->userManager->get($uid);
213 213
 
214
-		if(!$user instanceof User) {
215
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
214
+		if (!$user instanceof User) {
215
+			throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid.
216 216
 				'. Maybe the LDAP entry has no set display name attribute?');
217 217
 		}
218
-		if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
218
+		if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
219 219
 			$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
220 220
 			$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
221 221
 			if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
@@ -247,18 +247,18 @@  discard block
 block discarded – undo
247 247
 
248 248
 		//check if users are cached, if so return
249 249
 		$ldap_users = $this->access->connection->getFromCache($cachekey);
250
-		if(!is_null($ldap_users)) {
250
+		if (!is_null($ldap_users)) {
251 251
 			return $ldap_users;
252 252
 		}
253 253
 
254 254
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
255 255
 		// error. With a limit of 0, we get 0 results. So we pass null.
256
-		if($limit <= 0) {
256
+		if ($limit <= 0) {
257 257
 			$limit = null;
258 258
 		}
259 259
 		$filter = $this->access->combineFilterWithAnd(array(
260 260
 			$this->access->connection->ldapUserFilter,
261
-			$this->access->connection->ldapUserDisplayName . '=*',
261
+			$this->access->connection->ldapUserDisplayName.'=*',
262 262
 			$this->access->getFilterPartForUserSearch($search)
263 263
 		));
264 264
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 			$this->access->userManager->getAttributes(true),
272 272
 			$limit, $offset);
273 273
 		$ldap_users = $this->access->nextcloudUserNames($ldap_users);
274
-		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
274
+		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG);
275 275
 
276 276
 		$this->access->connection->writeToCache($cachekey, $ldap_users);
277 277
 		return $ldap_users;
@@ -287,29 +287,29 @@  discard block
 block discarded – undo
287 287
 	 * @throws \OC\ServerNotAvailableException
288 288
 	 */
289 289
 	public function userExistsOnLDAP($user) {
290
-		if(is_string($user)) {
290
+		if (is_string($user)) {
291 291
 			$user = $this->access->userManager->get($user);
292 292
 		}
293
-		if(is_null($user)) {
293
+		if (is_null($user)) {
294 294
 			return false;
295 295
 		}
296 296
 
297 297
 		$dn = $user->getDN();
298 298
 		//check if user really still exists by reading its entry
299
-		if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
299
+		if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
300 300
 			$lcr = $this->access->connection->getConnectionResource();
301
-			if(is_null($lcr)) {
302
-				throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
301
+			if (is_null($lcr)) {
302
+				throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost);
303 303
 			}
304 304
 
305 305
 			try {
306 306
 				$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
307
-				if(!$uuid) {
307
+				if (!$uuid) {
308 308
 					return false;
309 309
 				}
310 310
 				$newDn = $this->access->getUserDnByUuid($uuid);
311 311
 				//check if renamed user is still valid by reapplying the ldap filter
312
-				if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
312
+				if (!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
313 313
 					return false;
314 314
 				}
315 315
 				$this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 			}
320 320
 		}
321 321
 
322
-		if($user instanceof OfflineUser) {
322
+		if ($user instanceof OfflineUser) {
323 323
 			$user->unmark();
324 324
 		}
325 325
 
@@ -334,18 +334,18 @@  discard block
 block discarded – undo
334 334
 	 */
335 335
 	public function userExists($uid) {
336 336
 		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
337
-		if(!is_null($userExists)) {
338
-			return (bool)$userExists;
337
+		if (!is_null($userExists)) {
338
+			return (bool) $userExists;
339 339
 		}
340 340
 		//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
341 341
 		$user = $this->access->userManager->get($uid);
342 342
 
343
-		if(is_null($user)) {
343
+		if (is_null($user)) {
344 344
 			Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
345 345
 				$this->access->connection->ldapHost, Util::DEBUG);
346 346
 			$this->access->connection->writeToCache('userExists'.$uid, false);
347 347
 			return false;
348
-		} else if($user instanceof OfflineUser) {
348
+		} else if ($user instanceof OfflineUser) {
349 349
 			//express check for users marked as deleted. Returning true is
350 350
 			//necessary for cleanup
351 351
 			return true;
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 
354 354
 		$result = $this->userExistsOnLDAP($user);
355 355
 		$this->access->connection->writeToCache('userExists'.$uid, $result);
356
-		if($result === true) {
356
+		if ($result === true) {
357 357
 			$user->update();
358 358
 		}
359 359
 		return $result;
@@ -367,13 +367,13 @@  discard block
 block discarded – undo
367 367
 	*/
368 368
 	public function deleteUser($uid) {
369 369
 		$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
370
-		if(intval($marked) === 0) {
370
+		if (intval($marked) === 0) {
371 371
 			\OC::$server->getLogger()->notice(
372
-				'User '.$uid . ' is not marked as deleted, not cleaning up.',
372
+				'User '.$uid.' is not marked as deleted, not cleaning up.',
373 373
 				array('app' => 'user_ldap'));
374 374
 			return false;
375 375
 		}
376
-		\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
376
+		\OC::$server->getLogger()->info('Cleaning up after user '.$uid,
377 377
 			array('app' => 'user_ldap'));
378 378
 
379 379
 		//Get Home Directory out of user preferences so we can return it later,
@@ -393,26 +393,26 @@  discard block
 block discarded – undo
393 393
 	 */
394 394
 	public function getHome($uid) {
395 395
 		// user Exists check required as it is not done in user proxy!
396
-		if(!$this->userExists($uid)) {
396
+		if (!$this->userExists($uid)) {
397 397
 			return false;
398 398
 		}
399 399
 
400 400
 		$cacheKey = 'getHome'.$uid;
401 401
 		$path = $this->access->connection->getFromCache($cacheKey);
402
-		if(!is_null($path)) {
402
+		if (!is_null($path)) {
403 403
 			return $path;
404 404
 		}
405 405
 
406 406
 		// early return path if it is a deleted user
407 407
 		$user = $this->access->userManager->get($uid);
408
-		if($user instanceof OfflineUser) {
409
-			if($this->currentUserInDeletionProcess === $user->getUID()) {
408
+		if ($user instanceof OfflineUser) {
409
+			if ($this->currentUserInDeletionProcess === $user->getUID()) {
410 410
 				return $user->getHomePath();
411 411
 			} else {
412
-				throw new NoUserException($uid . ' is not a valid user anymore');
412
+				throw new NoUserException($uid.' is not a valid user anymore');
413 413
 			}
414 414
 		} else if ($user === null) {
415
-			throw new NoUserException($uid . ' is not a valid user anymore');
415
+			throw new NoUserException($uid.' is not a valid user anymore');
416 416
 		}
417 417
 
418 418
 		$path = $user->getHomePath();
@@ -427,12 +427,12 @@  discard block
 block discarded – undo
427 427
 	 * @return string|false display name
428 428
 	 */
429 429
 	public function getDisplayName($uid) {
430
-		if(!$this->userExists($uid)) {
430
+		if (!$this->userExists($uid)) {
431 431
 			return false;
432 432
 		}
433 433
 
434 434
 		$cacheKey = 'getDisplayName'.$uid;
435
-		if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
435
+		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
436 436
 			return $displayName;
437 437
 		}
438 438
 
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
 			$this->access->username2dn($uid),
450 450
 			$this->access->connection->ldapUserDisplayName);
451 451
 
452
-		if($displayName && (count($displayName) > 0)) {
452
+		if ($displayName && (count($displayName) > 0)) {
453 453
 			$displayName = $displayName[0];
454 454
 
455
-			if (is_array($displayName2)){
455
+			if (is_array($displayName2)) {
456 456
 				$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
457 457
 			}
458 458
 
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 	 */
482 482
 	public function getDisplayNames($search = '', $limit = null, $offset = null) {
483 483
 		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
484
-		if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
484
+		if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
485 485
 			return $displayNames;
486 486
 		}
487 487
 
@@ -503,12 +503,12 @@  discard block
 block discarded – undo
503 503
 	* compared with OC_USER_BACKEND_CREATE_USER etc.
504 504
 	*/
505 505
 	public function implementsActions($actions) {
506
-		return (bool)((Backend::CHECK_PASSWORD
506
+		return (bool) ((Backend::CHECK_PASSWORD
507 507
 			| Backend::GET_HOME
508 508
 			| Backend::GET_DISPLAYNAME
509 509
 			| Backend::PROVIDE_AVATAR
510 510
 			| Backend::COUNT_USERS
511
-			| ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0))
511
+			| ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0))
512 512
 			& $actions);
513 513
 	}
514 514
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 	public function countUsers() {
528 528
 		$filter = $this->access->getFilterForUserCount();
529 529
 		$cacheKey = 'countUsers-'.$filter;
530
-		if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
530
+		if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
531 531
 			return $entries;
532 532
 		}
533 533
 		$entries = $this->access->countUsers($filter);
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 	 * Backend name to be shown in user management
540 540
 	 * @return string the name of the backend to be shown
541 541
 	 */
542
-	public function getBackendName(){
542
+	public function getBackendName() {
543 543
 		return 'LDAP';
544 544
 	}
545 545
 	
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/Manager.php 2 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -43,222 +43,222 @@
 block discarded – undo
43 43
  * cache
44 44
  */
45 45
 class Manager {
46
-	/** @var IUserTools */
47
-	protected $access;
46
+    /** @var IUserTools */
47
+    protected $access;
48 48
 
49
-	/** @var IConfig */
50
-	protected $ocConfig;
49
+    /** @var IConfig */
50
+    protected $ocConfig;
51 51
 
52
-	/** @var IDBConnection */
53
-	protected $db;
52
+    /** @var IDBConnection */
53
+    protected $db;
54 54
 
55
-	/** @var IUserManager */
56
-	protected $userManager;
55
+    /** @var IUserManager */
56
+    protected $userManager;
57 57
 
58
-	/** @var INotificationManager */
59
-	protected $notificationManager;
58
+    /** @var INotificationManager */
59
+    protected $notificationManager;
60 60
 
61
-	/** @var FilesystemHelper */
62
-	protected $ocFilesystem;
61
+    /** @var FilesystemHelper */
62
+    protected $ocFilesystem;
63 63
 
64
-	/** @var LogWrapper */
65
-	protected $ocLog;
64
+    /** @var LogWrapper */
65
+    protected $ocLog;
66 66
 
67
-	/** @var Image */
68
-	protected $image;
67
+    /** @var Image */
68
+    protected $image;
69 69
 
70
-	/** @param \OCP\IAvatarManager */
71
-	protected $avatarManager;
70
+    /** @param \OCP\IAvatarManager */
71
+    protected $avatarManager;
72 72
 
73
-	/**
74
-	 * @var CappedMemoryCache $usersByDN
75
-	 */
76
-	protected $usersByDN;
77
-	/**
78
-	 * @var CappedMemoryCache $usersByUid
79
-	 */
80
-	protected $usersByUid;
73
+    /**
74
+     * @var CappedMemoryCache $usersByDN
75
+     */
76
+    protected $usersByDN;
77
+    /**
78
+     * @var CappedMemoryCache $usersByUid
79
+     */
80
+    protected $usersByUid;
81 81
 
82
-	/**
83
-	 * @param IConfig $ocConfig
84
-	 * @param \OCA\User_LDAP\FilesystemHelper $ocFilesystem object that
85
-	 * gives access to necessary functions from the OC filesystem
86
-	 * @param  \OCA\User_LDAP\LogWrapper $ocLog
87
-	 * @param IAvatarManager $avatarManager
88
-	 * @param Image $image an empty image instance
89
-	 * @param IDBConnection $db
90
-	 * @throws \Exception when the methods mentioned above do not exist
91
-	 */
92
-	public function __construct(IConfig $ocConfig,
93
-								FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
94
-								IAvatarManager $avatarManager, Image $image,
95
-								IDBConnection $db, IUserManager $userManager,
96
-								INotificationManager $notificationManager) {
82
+    /**
83
+     * @param IConfig $ocConfig
84
+     * @param \OCA\User_LDAP\FilesystemHelper $ocFilesystem object that
85
+     * gives access to necessary functions from the OC filesystem
86
+     * @param  \OCA\User_LDAP\LogWrapper $ocLog
87
+     * @param IAvatarManager $avatarManager
88
+     * @param Image $image an empty image instance
89
+     * @param IDBConnection $db
90
+     * @throws \Exception when the methods mentioned above do not exist
91
+     */
92
+    public function __construct(IConfig $ocConfig,
93
+                                FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
94
+                                IAvatarManager $avatarManager, Image $image,
95
+                                IDBConnection $db, IUserManager $userManager,
96
+                                INotificationManager $notificationManager) {
97 97
 
98
-		$this->ocConfig            = $ocConfig;
99
-		$this->ocFilesystem        = $ocFilesystem;
100
-		$this->ocLog               = $ocLog;
101
-		$this->avatarManager       = $avatarManager;
102
-		$this->image               = $image;
103
-		$this->db                  = $db;
104
-		$this->userManager         = $userManager;
105
-		$this->notificationManager = $notificationManager;
106
-		$this->usersByDN           = new CappedMemoryCache();
107
-		$this->usersByUid          = new CappedMemoryCache();
108
-	}
98
+        $this->ocConfig            = $ocConfig;
99
+        $this->ocFilesystem        = $ocFilesystem;
100
+        $this->ocLog               = $ocLog;
101
+        $this->avatarManager       = $avatarManager;
102
+        $this->image               = $image;
103
+        $this->db                  = $db;
104
+        $this->userManager         = $userManager;
105
+        $this->notificationManager = $notificationManager;
106
+        $this->usersByDN           = new CappedMemoryCache();
107
+        $this->usersByUid          = new CappedMemoryCache();
108
+    }
109 109
 
110
-	/**
111
-	 * @brief binds manager to an instance of IUserTools (implemented by
112
-	 * Access). It needs to be assigned first before the manager can be used.
113
-	 * @param IUserTools
114
-	 */
115
-	public function setLdapAccess(IUserTools $access) {
116
-		$this->access = $access;
117
-	}
110
+    /**
111
+     * @brief binds manager to an instance of IUserTools (implemented by
112
+     * Access). It needs to be assigned first before the manager can be used.
113
+     * @param IUserTools
114
+     */
115
+    public function setLdapAccess(IUserTools $access) {
116
+        $this->access = $access;
117
+    }
118 118
 
119
-	/**
120
-	 * @brief creates an instance of User and caches (just runtime) it in the
121
-	 * property array
122
-	 * @param string $dn the DN of the user
123
-	 * @param string $uid the internal (owncloud) username
124
-	 * @return \OCA\User_LDAP\User\User
125
-	 */
126
-	private function createAndCache($dn, $uid) {
127
-		$this->checkAccess();
128
-		$user = new User($uid, $dn, $this->access, $this->ocConfig,
129
-			$this->ocFilesystem, clone $this->image, $this->ocLog,
130
-			$this->avatarManager, $this->userManager, 
131
-			$this->notificationManager);
132
-		$this->usersByDN[$dn]   = $user;
133
-		$this->usersByUid[$uid] = $user;
134
-		return $user;
135
-	}
119
+    /**
120
+     * @brief creates an instance of User and caches (just runtime) it in the
121
+     * property array
122
+     * @param string $dn the DN of the user
123
+     * @param string $uid the internal (owncloud) username
124
+     * @return \OCA\User_LDAP\User\User
125
+     */
126
+    private function createAndCache($dn, $uid) {
127
+        $this->checkAccess();
128
+        $user = new User($uid, $dn, $this->access, $this->ocConfig,
129
+            $this->ocFilesystem, clone $this->image, $this->ocLog,
130
+            $this->avatarManager, $this->userManager, 
131
+            $this->notificationManager);
132
+        $this->usersByDN[$dn]   = $user;
133
+        $this->usersByUid[$uid] = $user;
134
+        return $user;
135
+    }
136 136
 
137
-	/**
138
-	 * removes a user entry from the cache
139
-	 * @param $uid
140
-	 */
141
-	public function invalidate($uid) {
142
-		if(!isset($this->usersByUid[$uid])) {
143
-			return;
144
-		}
145
-		$dn = $this->usersByUid[$uid]->getDN();
146
-		unset($this->usersByUid[$uid]);
147
-		unset($this->usersByDN[$dn]);
148
-	}
137
+    /**
138
+     * removes a user entry from the cache
139
+     * @param $uid
140
+     */
141
+    public function invalidate($uid) {
142
+        if(!isset($this->usersByUid[$uid])) {
143
+            return;
144
+        }
145
+        $dn = $this->usersByUid[$uid]->getDN();
146
+        unset($this->usersByUid[$uid]);
147
+        unset($this->usersByDN[$dn]);
148
+    }
149 149
 
150
-	/**
151
-	 * @brief checks whether the Access instance has been set
152
-	 * @throws \Exception if Access has not been set
153
-	 * @return null
154
-	 */
155
-	private function checkAccess() {
156
-		if(is_null($this->access)) {
157
-			throw new \Exception('LDAP Access instance must be set first');
158
-		}
159
-	}
150
+    /**
151
+     * @brief checks whether the Access instance has been set
152
+     * @throws \Exception if Access has not been set
153
+     * @return null
154
+     */
155
+    private function checkAccess() {
156
+        if(is_null($this->access)) {
157
+            throw new \Exception('LDAP Access instance must be set first');
158
+        }
159
+    }
160 160
 
161
-	/**
162
-	 * returns a list of attributes that will be processed further, e.g. quota,
163
-	 * email, displayname, or others.
164
-	 * @param bool $minimal - optional, set to true to skip attributes with big
165
-	 * payload
166
-	 * @return string[]
167
-	 */
168
-	public function getAttributes($minimal = false) {
169
-		$attributes = array('dn', 'uid', 'samaccountname', 'memberof');
170
-		$possible = array(
171
-			$this->access->getConnection()->ldapQuotaAttribute,
172
-			$this->access->getConnection()->ldapEmailAttribute,
173
-			$this->access->getConnection()->ldapUserDisplayName,
174
-			$this->access->getConnection()->ldapUserDisplayName2,
175
-		);
176
-		foreach($possible as $attr) {
177
-			if(!is_null($attr)) {
178
-				$attributes[] = $attr;
179
-			}
180
-		}
161
+    /**
162
+     * returns a list of attributes that will be processed further, e.g. quota,
163
+     * email, displayname, or others.
164
+     * @param bool $minimal - optional, set to true to skip attributes with big
165
+     * payload
166
+     * @return string[]
167
+     */
168
+    public function getAttributes($minimal = false) {
169
+        $attributes = array('dn', 'uid', 'samaccountname', 'memberof');
170
+        $possible = array(
171
+            $this->access->getConnection()->ldapQuotaAttribute,
172
+            $this->access->getConnection()->ldapEmailAttribute,
173
+            $this->access->getConnection()->ldapUserDisplayName,
174
+            $this->access->getConnection()->ldapUserDisplayName2,
175
+        );
176
+        foreach($possible as $attr) {
177
+            if(!is_null($attr)) {
178
+                $attributes[] = $attr;
179
+            }
180
+        }
181 181
 
182
-		$homeRule = $this->access->getConnection()->homeFolderNamingRule;
183
-		if(strpos($homeRule, 'attr:') === 0) {
184
-			$attributes[] = substr($homeRule, strlen('attr:'));
185
-		}
182
+        $homeRule = $this->access->getConnection()->homeFolderNamingRule;
183
+        if(strpos($homeRule, 'attr:') === 0) {
184
+            $attributes[] = substr($homeRule, strlen('attr:'));
185
+        }
186 186
 
187
-		if(!$minimal) {
188
-			// attributes that are not really important but may come with big
189
-			// payload.
190
-			$attributes = array_merge($attributes, array(
191
-				'jpegphoto',
192
-				'thumbnailphoto'
193
-			));
194
-		}
187
+        if(!$minimal) {
188
+            // attributes that are not really important but may come with big
189
+            // payload.
190
+            $attributes = array_merge($attributes, array(
191
+                'jpegphoto',
192
+                'thumbnailphoto'
193
+            ));
194
+        }
195 195
 
196
-		return $attributes;
197
-	}
196
+        return $attributes;
197
+    }
198 198
 
199
-	/**
200
-	 * Checks whether the specified user is marked as deleted
201
-	 * @param string $id the Nextcloud user name
202
-	 * @return bool
203
-	 */
204
-	public function isDeletedUser($id) {
205
-		$isDeleted = $this->ocConfig->getUserValue(
206
-			$id, 'user_ldap', 'isDeleted', 0);
207
-		return intval($isDeleted) === 1;
208
-	}
199
+    /**
200
+     * Checks whether the specified user is marked as deleted
201
+     * @param string $id the Nextcloud user name
202
+     * @return bool
203
+     */
204
+    public function isDeletedUser($id) {
205
+        $isDeleted = $this->ocConfig->getUserValue(
206
+            $id, 'user_ldap', 'isDeleted', 0);
207
+        return intval($isDeleted) === 1;
208
+    }
209 209
 
210
-	/**
211
-	 * creates and returns an instance of OfflineUser for the specified user
212
-	 * @param string $id
213
-	 * @return \OCA\User_LDAP\User\OfflineUser
214
-	 */
215
-	public function getDeletedUser($id) {
216
-		return new OfflineUser(
217
-			$id,
218
-			$this->ocConfig,
219
-			$this->db,
220
-			$this->access->getUserMapper());
221
-	}
210
+    /**
211
+     * creates and returns an instance of OfflineUser for the specified user
212
+     * @param string $id
213
+     * @return \OCA\User_LDAP\User\OfflineUser
214
+     */
215
+    public function getDeletedUser($id) {
216
+        return new OfflineUser(
217
+            $id,
218
+            $this->ocConfig,
219
+            $this->db,
220
+            $this->access->getUserMapper());
221
+    }
222 222
 
223
-	/**
224
-	 * @brief returns a User object by it's Nextcloud username
225
-	 * @param string $id the DN or username of the user
226
-	 * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
227
-	 */
228
-	protected function createInstancyByUserName($id) {
229
-		//most likely a uid. Check whether it is a deleted user
230
-		if($this->isDeletedUser($id)) {
231
-			return $this->getDeletedUser($id);
232
-		}
233
-		$dn = $this->access->username2dn($id);
234
-		if($dn !== false) {
235
-			return $this->createAndCache($dn, $id);
236
-		}
237
-		return null;
238
-	}
223
+    /**
224
+     * @brief returns a User object by it's Nextcloud username
225
+     * @param string $id the DN or username of the user
226
+     * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
227
+     */
228
+    protected function createInstancyByUserName($id) {
229
+        //most likely a uid. Check whether it is a deleted user
230
+        if($this->isDeletedUser($id)) {
231
+            return $this->getDeletedUser($id);
232
+        }
233
+        $dn = $this->access->username2dn($id);
234
+        if($dn !== false) {
235
+            return $this->createAndCache($dn, $id);
236
+        }
237
+        return null;
238
+    }
239 239
 
240
-	/**
241
-	 * @brief returns a User object by it's DN or Nextcloud username
242
-	 * @param string $id the DN or username of the user
243
-	 * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
244
-	 * @throws \Exception when connection could not be established
245
-	 */
246
-	public function get($id) {
247
-		$this->checkAccess();
248
-		if(isset($this->usersByDN[$id])) {
249
-			return $this->usersByDN[$id];
250
-		} else if(isset($this->usersByUid[$id])) {
251
-			return $this->usersByUid[$id];
252
-		}
240
+    /**
241
+     * @brief returns a User object by it's DN or Nextcloud username
242
+     * @param string $id the DN or username of the user
243
+     * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
244
+     * @throws \Exception when connection could not be established
245
+     */
246
+    public function get($id) {
247
+        $this->checkAccess();
248
+        if(isset($this->usersByDN[$id])) {
249
+            return $this->usersByDN[$id];
250
+        } else if(isset($this->usersByUid[$id])) {
251
+            return $this->usersByUid[$id];
252
+        }
253 253
 
254
-		if($this->access->stringResemblesDN($id) ) {
255
-			$uid = $this->access->dn2username($id);
256
-			if($uid !== false) {
257
-				return $this->createAndCache($id, $uid);
258
-			}
259
-		}
254
+        if($this->access->stringResemblesDN($id) ) {
255
+            $uid = $this->access->dn2username($id);
256
+            if($uid !== false) {
257
+                return $this->createAndCache($id, $uid);
258
+            }
259
+        }
260 260
 
261
-		return $this->createInstancyByUserName($id);
262
-	}
261
+        return $this->createInstancyByUserName($id);
262
+    }
263 263
 
264 264
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	 * @param $uid
140 140
 	 */
141 141
 	public function invalidate($uid) {
142
-		if(!isset($this->usersByUid[$uid])) {
142
+		if (!isset($this->usersByUid[$uid])) {
143 143
 			return;
144 144
 		}
145 145
 		$dn = $this->usersByUid[$uid]->getDN();
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @return null
154 154
 	 */
155 155
 	private function checkAccess() {
156
-		if(is_null($this->access)) {
156
+		if (is_null($this->access)) {
157 157
 			throw new \Exception('LDAP Access instance must be set first');
158 158
 		}
159 159
 	}
@@ -173,18 +173,18 @@  discard block
 block discarded – undo
173 173
 			$this->access->getConnection()->ldapUserDisplayName,
174 174
 			$this->access->getConnection()->ldapUserDisplayName2,
175 175
 		);
176
-		foreach($possible as $attr) {
177
-			if(!is_null($attr)) {
176
+		foreach ($possible as $attr) {
177
+			if (!is_null($attr)) {
178 178
 				$attributes[] = $attr;
179 179
 			}
180 180
 		}
181 181
 
182 182
 		$homeRule = $this->access->getConnection()->homeFolderNamingRule;
183
-		if(strpos($homeRule, 'attr:') === 0) {
183
+		if (strpos($homeRule, 'attr:') === 0) {
184 184
 			$attributes[] = substr($homeRule, strlen('attr:'));
185 185
 		}
186 186
 
187
-		if(!$minimal) {
187
+		if (!$minimal) {
188 188
 			// attributes that are not really important but may come with big
189 189
 			// payload.
190 190
 			$attributes = array_merge($attributes, array(
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 	 */
228 228
 	protected function createInstancyByUserName($id) {
229 229
 		//most likely a uid. Check whether it is a deleted user
230
-		if($this->isDeletedUser($id)) {
230
+		if ($this->isDeletedUser($id)) {
231 231
 			return $this->getDeletedUser($id);
232 232
 		}
233 233
 		$dn = $this->access->username2dn($id);
234
-		if($dn !== false) {
234
+		if ($dn !== false) {
235 235
 			return $this->createAndCache($dn, $id);
236 236
 		}
237 237
 		return null;
@@ -245,15 +245,15 @@  discard block
 block discarded – undo
245 245
 	 */
246 246
 	public function get($id) {
247 247
 		$this->checkAccess();
248
-		if(isset($this->usersByDN[$id])) {
248
+		if (isset($this->usersByDN[$id])) {
249 249
 			return $this->usersByDN[$id];
250
-		} else if(isset($this->usersByUid[$id])) {
250
+		} else if (isset($this->usersByUid[$id])) {
251 251
 			return $this->usersByUid[$id];
252 252
 		}
253 253
 
254
-		if($this->access->stringResemblesDN($id) ) {
254
+		if ($this->access->stringResemblesDN($id)) {
255 255
 			$uid = $this->access->dn2username($id);
256
-			if($uid !== false) {
256
+			if ($uid !== false) {
257 257
 				return $this->createAndCache($id, $uid);
258 258
 			}
259 259
 		}
Please login to merge, or discard this patch.