Passed
Push — master ( b28cea...939433 )
by Blizzz
18:05 queued 10s
created
lib/public/LDAP/ILDAPProvider.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -34,137 +34,137 @@
 block discarded – undo
34 34
  * @since 11.0.0
35 35
  */
36 36
 interface ILDAPProvider {
37
-	/**
38
-	 * Translate a user id to LDAP DN.
39
-	 * @param string $uid user id
40
-	 * @return string
41
-	 * @since 11.0.0
42
-	 */
43
-	public function getUserDN($uid);
44
-
45
-	/**
46
-	 * Translate a group id to LDAP DN.
47
-	 * @param string $gid group id
48
-	 * @return string
49
-	 * @since 13.0.0
50
-	 */
51
-	public function getGroupDN($gid);
52
-
53
-	/**
54
-	 * Translate a LDAP DN to an internal user name.
55
-	 * @param string $dn LDAP DN
56
-	 * @return string with the internal user name
57
-	 * @throws \Exception if translation was unsuccessful
58
-	 * @since 11.0.0
59
-	 */
60
-	public function getUserName($dn);
61
-
62
-	/**
63
-	 * Convert a stored DN so it can be used as base parameter for LDAP queries.
64
-	 * @param string $dn the DN
65
-	 * @return string
66
-	 * @since 11.0.0
67
-	 */
68
-	public function DNasBaseParameter($dn);
69
-
70
-	/**
71
-	 * Sanitize a DN received from the LDAP server.
72
-	 * @param array $dn the DN in question
73
-	 * @return array the sanitized DN
74
-	 * @since 11.0.0
75
-	 */
76
-	public function sanitizeDN($dn);
77
-
78
-	/**
79
-	 * Return a new LDAP connection resource for the specified user.
80
-	 * @param string $uid user id
81
-	 * @return resource of the LDAP connection
82
-	 * @since 11.0.0
83
-	 */
84
-	public function getLDAPConnection($uid);
85
-
86
-	/**
87
-	 * Return a new LDAP connection resource for the specified group.
88
-	 * @param string $gid group id
89
-	 * @return resource of the LDAP connection
90
-	 * @since 13.0.0
91
-	 */
92
-	public function getGroupLDAPConnection($gid);
93
-
94
-	/**
95
-	 * Get the LDAP base for users.
96
-	 * @param string $uid user id
97
-	 * @return string the base for users
98
-	 * @throws \Exception if user id was not found in LDAP
99
-	 * @since 11.0.0
100
-	 */
101
-	public function getLDAPBaseUsers($uid);
102
-
103
-	/**
104
-	 * Get the LDAP base for groups.
105
-	 * @param string $uid user id
106
-	 * @return string the base for groups
107
-	 * @throws \Exception if user id was not found in LDAP
108
-	 * @since 11.0.0
109
-	 */
110
-	public function getLDAPBaseGroups($uid);
111
-
112
-	/**
113
-	 * Check whether a LDAP DN exists
114
-	 * @param string $dn LDAP DN
115
-	 * @return bool whether the DN exists
116
-	 * @since 11.0.0
117
-	 */
118
-	public function dnExists($dn);
119
-
120
-	/**
121
-	 * Clear the cache if a cache is used, otherwise do nothing.
122
-	 * @param string $uid user id
123
-	 * @since 11.0.0
124
-	 */
125
-	public function clearCache($uid);
126
-
127
-	/**
128
-	 * Clear the cache if a cache is used, otherwise do nothing.
129
-	 * @param string $gid group id
130
-	 * @since 13.0.0
131
-	 */
132
-	public function clearGroupCache($gid);
133
-
134
-	/**
135
-	 * Get the LDAP attribute name for the user's display name
136
-	 * @param string $uid user id
137
-	 * @return string the display name field
138
-	 * @throws \Exception if user id was not found in LDAP
139
-	 * @since 12.0.0
140
-	 */
141
-	public function getLDAPDisplayNameField($uid);
142
-
143
-	/**
144
-	 * Get the LDAP attribute name for the email
145
-	 * @param string $uid user id
146
-	 * @return string the email field
147
-	 * @throws \Exception if user id was not found in LDAP
148
-	 * @since 12.0.0
149
-	 */
150
-	public function getLDAPEmailField($uid);
151
-
152
-	/**
153
-	 * Get the LDAP attribute name for the type of association betweeen users and groups
154
-	 * @param string $gid group id
155
-	 * @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber', ''
156
-	 * @throws \Exception if group id was not found in LDAP
157
-	 * @since 13.0.0
158
-	 */
159
-	public function getLDAPGroupMemberAssoc($gid);
160
-
161
-	/**
162
-	 * Get an LDAP attribute for a nextcloud user
163
-	 * @param string $uid the nextcloud user id to get the attribute for
164
-	 * @param string $attribute the name of the attribute to read
165
-	 * @return string|null
166
-	 * @throws \Exception if user id was not found in LDAP
167
-	 * @since 21.0.0
168
-	 */
169
-	public function getUserAttribute(string $uid, string $attribute): ?string;
37
+    /**
38
+     * Translate a user id to LDAP DN.
39
+     * @param string $uid user id
40
+     * @return string
41
+     * @since 11.0.0
42
+     */
43
+    public function getUserDN($uid);
44
+
45
+    /**
46
+     * Translate a group id to LDAP DN.
47
+     * @param string $gid group id
48
+     * @return string
49
+     * @since 13.0.0
50
+     */
51
+    public function getGroupDN($gid);
52
+
53
+    /**
54
+     * Translate a LDAP DN to an internal user name.
55
+     * @param string $dn LDAP DN
56
+     * @return string with the internal user name
57
+     * @throws \Exception if translation was unsuccessful
58
+     * @since 11.0.0
59
+     */
60
+    public function getUserName($dn);
61
+
62
+    /**
63
+     * Convert a stored DN so it can be used as base parameter for LDAP queries.
64
+     * @param string $dn the DN
65
+     * @return string
66
+     * @since 11.0.0
67
+     */
68
+    public function DNasBaseParameter($dn);
69
+
70
+    /**
71
+     * Sanitize a DN received from the LDAP server.
72
+     * @param array $dn the DN in question
73
+     * @return array the sanitized DN
74
+     * @since 11.0.0
75
+     */
76
+    public function sanitizeDN($dn);
77
+
78
+    /**
79
+     * Return a new LDAP connection resource for the specified user.
80
+     * @param string $uid user id
81
+     * @return resource of the LDAP connection
82
+     * @since 11.0.0
83
+     */
84
+    public function getLDAPConnection($uid);
85
+
86
+    /**
87
+     * Return a new LDAP connection resource for the specified group.
88
+     * @param string $gid group id
89
+     * @return resource of the LDAP connection
90
+     * @since 13.0.0
91
+     */
92
+    public function getGroupLDAPConnection($gid);
93
+
94
+    /**
95
+     * Get the LDAP base for users.
96
+     * @param string $uid user id
97
+     * @return string the base for users
98
+     * @throws \Exception if user id was not found in LDAP
99
+     * @since 11.0.0
100
+     */
101
+    public function getLDAPBaseUsers($uid);
102
+
103
+    /**
104
+     * Get the LDAP base for groups.
105
+     * @param string $uid user id
106
+     * @return string the base for groups
107
+     * @throws \Exception if user id was not found in LDAP
108
+     * @since 11.0.0
109
+     */
110
+    public function getLDAPBaseGroups($uid);
111
+
112
+    /**
113
+     * Check whether a LDAP DN exists
114
+     * @param string $dn LDAP DN
115
+     * @return bool whether the DN exists
116
+     * @since 11.0.0
117
+     */
118
+    public function dnExists($dn);
119
+
120
+    /**
121
+     * Clear the cache if a cache is used, otherwise do nothing.
122
+     * @param string $uid user id
123
+     * @since 11.0.0
124
+     */
125
+    public function clearCache($uid);
126
+
127
+    /**
128
+     * Clear the cache if a cache is used, otherwise do nothing.
129
+     * @param string $gid group id
130
+     * @since 13.0.0
131
+     */
132
+    public function clearGroupCache($gid);
133
+
134
+    /**
135
+     * Get the LDAP attribute name for the user's display name
136
+     * @param string $uid user id
137
+     * @return string the display name field
138
+     * @throws \Exception if user id was not found in LDAP
139
+     * @since 12.0.0
140
+     */
141
+    public function getLDAPDisplayNameField($uid);
142
+
143
+    /**
144
+     * Get the LDAP attribute name for the email
145
+     * @param string $uid user id
146
+     * @return string the email field
147
+     * @throws \Exception if user id was not found in LDAP
148
+     * @since 12.0.0
149
+     */
150
+    public function getLDAPEmailField($uid);
151
+
152
+    /**
153
+     * Get the LDAP attribute name for the type of association betweeen users and groups
154
+     * @param string $gid group id
155
+     * @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber', ''
156
+     * @throws \Exception if group id was not found in LDAP
157
+     * @since 13.0.0
158
+     */
159
+    public function getLDAPGroupMemberAssoc($gid);
160
+
161
+    /**
162
+     * Get an LDAP attribute for a nextcloud user
163
+     * @param string $uid the nextcloud user id to get the attribute for
164
+     * @param string $attribute the name of the attribute to read
165
+     * @return string|null
166
+     * @throws \Exception if user id was not found in LDAP
167
+     * @since 21.0.0
168
+     */
169
+    public function getUserAttribute(string $uid, string $attribute): ?string;
170 170
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/LDAPProvider.php 2 patches
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -37,304 +37,304 @@
 block discarded – undo
37 37
  * LDAP provider for pulic access to the LDAP backend.
38 38
  */
39 39
 class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport {
40
-	private $userBackend;
41
-	private $groupBackend;
42
-	private $logger;
43
-	private $helper;
44
-	private $deletedUsersIndex;
40
+    private $userBackend;
41
+    private $groupBackend;
42
+    private $logger;
43
+    private $helper;
44
+    private $deletedUsersIndex;
45 45
 
46
-	/**
47
-	 * Create new LDAPProvider
48
-	 * @param \OCP\IServerContainer $serverContainer
49
-	 * @param Helper $helper
50
-	 * @param DeletedUsersIndex $deletedUsersIndex
51
-	 * @throws \Exception if user_ldap app was not enabled
52
-	 */
53
-	public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) {
54
-		$this->logger = $serverContainer->getLogger();
55
-		$this->helper = $helper;
56
-		$this->deletedUsersIndex = $deletedUsersIndex;
57
-		$userBackendFound = false;
58
-		$groupBackendFound = false;
59
-		foreach ($serverContainer->getUserManager()->getBackends() as $backend) {
60
-			$this->logger->debug('instance '.get_class($backend).' user backend.', ['app' => 'user_ldap']);
61
-			if ($backend instanceof IUserLDAP) {
62
-				$this->userBackend = $backend;
63
-				$userBackendFound = true;
64
-				break;
65
-			}
66
-		}
67
-		foreach ($serverContainer->getGroupManager()->getBackends() as $backend) {
68
-			$this->logger->debug('instance '.get_class($backend).' group backend.', ['app' => 'user_ldap']);
69
-			if ($backend instanceof IGroupLDAP) {
70
-				$this->groupBackend = $backend;
71
-				$groupBackendFound = true;
72
-				break;
73
-			}
74
-		}
46
+    /**
47
+     * Create new LDAPProvider
48
+     * @param \OCP\IServerContainer $serverContainer
49
+     * @param Helper $helper
50
+     * @param DeletedUsersIndex $deletedUsersIndex
51
+     * @throws \Exception if user_ldap app was not enabled
52
+     */
53
+    public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) {
54
+        $this->logger = $serverContainer->getLogger();
55
+        $this->helper = $helper;
56
+        $this->deletedUsersIndex = $deletedUsersIndex;
57
+        $userBackendFound = false;
58
+        $groupBackendFound = false;
59
+        foreach ($serverContainer->getUserManager()->getBackends() as $backend) {
60
+            $this->logger->debug('instance '.get_class($backend).' user backend.', ['app' => 'user_ldap']);
61
+            if ($backend instanceof IUserLDAP) {
62
+                $this->userBackend = $backend;
63
+                $userBackendFound = true;
64
+                break;
65
+            }
66
+        }
67
+        foreach ($serverContainer->getGroupManager()->getBackends() as $backend) {
68
+            $this->logger->debug('instance '.get_class($backend).' group backend.', ['app' => 'user_ldap']);
69
+            if ($backend instanceof IGroupLDAP) {
70
+                $this->groupBackend = $backend;
71
+                $groupBackendFound = true;
72
+                break;
73
+            }
74
+        }
75 75
 
76
-		if (!$userBackendFound or !$groupBackendFound) {
77
-			throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled');
78
-		}
79
-	}
76
+        if (!$userBackendFound or !$groupBackendFound) {
77
+            throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled');
78
+        }
79
+    }
80 80
 
81
-	/**
82
-	 * Translate an user id to LDAP DN
83
-	 * @param string $uid user id
84
-	 * @return string with the LDAP DN
85
-	 * @throws \Exception if translation was unsuccessful
86
-	 */
87
-	public function getUserDN($uid) {
88
-		if (!$this->userBackend->userExists($uid)) {
89
-			throw new \Exception('User id not found in LDAP');
90
-		}
91
-		$result = $this->userBackend->getLDAPAccess($uid)->username2dn($uid);
92
-		if (!$result) {
93
-			throw new \Exception('Translation to LDAP DN unsuccessful');
94
-		}
95
-		return $result;
96
-	}
81
+    /**
82
+     * Translate an user id to LDAP DN
83
+     * @param string $uid user id
84
+     * @return string with the LDAP DN
85
+     * @throws \Exception if translation was unsuccessful
86
+     */
87
+    public function getUserDN($uid) {
88
+        if (!$this->userBackend->userExists($uid)) {
89
+            throw new \Exception('User id not found in LDAP');
90
+        }
91
+        $result = $this->userBackend->getLDAPAccess($uid)->username2dn($uid);
92
+        if (!$result) {
93
+            throw new \Exception('Translation to LDAP DN unsuccessful');
94
+        }
95
+        return $result;
96
+    }
97 97
 
98
-	/**
99
-	 * Translate a group id to LDAP DN.
100
-	 * @param string $gid group id
101
-	 * @return string
102
-	 * @throws \Exception
103
-	 */
104
-	public function getGroupDN($gid) {
105
-		if (!$this->groupBackend->groupExists($gid)) {
106
-			throw new \Exception('Group id not found in LDAP');
107
-		}
108
-		$result = $this->groupBackend->getLDAPAccess($gid)->groupname2dn($gid);
109
-		if (!$result) {
110
-			throw new \Exception('Translation to LDAP DN unsuccessful');
111
-		}
112
-		return $result;
113
-	}
98
+    /**
99
+     * Translate a group id to LDAP DN.
100
+     * @param string $gid group id
101
+     * @return string
102
+     * @throws \Exception
103
+     */
104
+    public function getGroupDN($gid) {
105
+        if (!$this->groupBackend->groupExists($gid)) {
106
+            throw new \Exception('Group id not found in LDAP');
107
+        }
108
+        $result = $this->groupBackend->getLDAPAccess($gid)->groupname2dn($gid);
109
+        if (!$result) {
110
+            throw new \Exception('Translation to LDAP DN unsuccessful');
111
+        }
112
+        return $result;
113
+    }
114 114
 
115
-	/**
116
-	 * Translate a LDAP DN to an internal user name. If there is no mapping between
117
-	 * the DN and the user name, a new one will be created.
118
-	 * @param string $dn LDAP DN
119
-	 * @return string with the internal user name
120
-	 * @throws \Exception if translation was unsuccessful
121
-	 */
122
-	public function getUserName($dn) {
123
-		$result = $this->userBackend->dn2UserName($dn);
124
-		if (!$result) {
125
-			throw new \Exception('Translation to internal user name unsuccessful');
126
-		}
127
-		return $result;
128
-	}
115
+    /**
116
+     * Translate a LDAP DN to an internal user name. If there is no mapping between
117
+     * the DN and the user name, a new one will be created.
118
+     * @param string $dn LDAP DN
119
+     * @return string with the internal user name
120
+     * @throws \Exception if translation was unsuccessful
121
+     */
122
+    public function getUserName($dn) {
123
+        $result = $this->userBackend->dn2UserName($dn);
124
+        if (!$result) {
125
+            throw new \Exception('Translation to internal user name unsuccessful');
126
+        }
127
+        return $result;
128
+    }
129 129
 
130
-	/**
131
-	 * Convert a stored DN so it can be used as base parameter for LDAP queries.
132
-	 * @param string $dn the DN in question
133
-	 * @return string
134
-	 */
135
-	public function DNasBaseParameter($dn) {
136
-		return $this->helper->DNasBaseParameter($dn);
137
-	}
130
+    /**
131
+     * Convert a stored DN so it can be used as base parameter for LDAP queries.
132
+     * @param string $dn the DN in question
133
+     * @return string
134
+     */
135
+    public function DNasBaseParameter($dn) {
136
+        return $this->helper->DNasBaseParameter($dn);
137
+    }
138 138
 
139
-	/**
140
-	 * Sanitize a DN received from the LDAP server.
141
-	 * @param array $dn the DN in question
142
-	 * @return array the sanitized DN
143
-	 */
144
-	public function sanitizeDN($dn) {
145
-		return $this->helper->sanitizeDN($dn);
146
-	}
139
+    /**
140
+     * Sanitize a DN received from the LDAP server.
141
+     * @param array $dn the DN in question
142
+     * @return array the sanitized DN
143
+     */
144
+    public function sanitizeDN($dn) {
145
+        return $this->helper->sanitizeDN($dn);
146
+    }
147 147
 
148
-	/**
149
-	 * Return a new LDAP connection resource for the specified user.
150
-	 * The connection must be closed manually.
151
-	 * @param string $uid user id
152
-	 * @return resource of the LDAP connection
153
-	 * @throws \Exception if user id was not found in LDAP
154
-	 */
155
-	public function getLDAPConnection($uid) {
156
-		if (!$this->userBackend->userExists($uid)) {
157
-			throw new \Exception('User id not found in LDAP');
158
-		}
159
-		return $this->userBackend->getNewLDAPConnection($uid);
160
-	}
148
+    /**
149
+     * Return a new LDAP connection resource for the specified user.
150
+     * The connection must be closed manually.
151
+     * @param string $uid user id
152
+     * @return resource of the LDAP connection
153
+     * @throws \Exception if user id was not found in LDAP
154
+     */
155
+    public function getLDAPConnection($uid) {
156
+        if (!$this->userBackend->userExists($uid)) {
157
+            throw new \Exception('User id not found in LDAP');
158
+        }
159
+        return $this->userBackend->getNewLDAPConnection($uid);
160
+    }
161 161
 
162
-	/**
163
-	 * Return a new LDAP connection resource for the specified user.
164
-	 * The connection must be closed manually.
165
-	 * @param string $gid group id
166
-	 * @return resource of the LDAP connection
167
-	 * @throws \Exception if group id was not found in LDAP
168
-	 */
169
-	public function getGroupLDAPConnection($gid) {
170
-		if (!$this->groupBackend->groupExists($gid)) {
171
-			throw new \Exception('Group id not found in LDAP');
172
-		}
173
-		return $this->groupBackend->getNewLDAPConnection($gid);
174
-	}
162
+    /**
163
+     * Return a new LDAP connection resource for the specified user.
164
+     * The connection must be closed manually.
165
+     * @param string $gid group id
166
+     * @return resource of the LDAP connection
167
+     * @throws \Exception if group id was not found in LDAP
168
+     */
169
+    public function getGroupLDAPConnection($gid) {
170
+        if (!$this->groupBackend->groupExists($gid)) {
171
+            throw new \Exception('Group id not found in LDAP');
172
+        }
173
+        return $this->groupBackend->getNewLDAPConnection($gid);
174
+    }
175 175
 
176
-	/**
177
-	 * Get the LDAP base for users.
178
-	 * @param string $uid user id
179
-	 * @return string the base for users
180
-	 * @throws \Exception if user id was not found in LDAP
181
-	 */
182
-	public function getLDAPBaseUsers($uid) {
183
-		if (!$this->userBackend->userExists($uid)) {
184
-			throw new \Exception('User id not found in LDAP');
185
-		}
186
-		$access = $this->userBackend->getLDAPAccess($uid);
187
-		$bases = $access->getConnection()->ldapBaseUsers;
188
-		$dn = $this->getUserDN($uid);
189
-		foreach ($bases as $base) {
190
-			if ($access->isDNPartOfBase($dn, [$base])) {
191
-				return $base;
192
-			}
193
-		}
194
-		// should not occur, because the user does not qualify to use NC in this case
195
-		$this->logger->info(
196
-			'No matching user base found for user {dn}, available: {bases}.',
197
-			[
198
-				'app' => 'user_ldap',
199
-				'dn' => $dn,
200
-				'bases' => $bases,
201
-			]
202
-		);
203
-		return array_shift($bases);
204
-	}
176
+    /**
177
+     * Get the LDAP base for users.
178
+     * @param string $uid user id
179
+     * @return string the base for users
180
+     * @throws \Exception if user id was not found in LDAP
181
+     */
182
+    public function getLDAPBaseUsers($uid) {
183
+        if (!$this->userBackend->userExists($uid)) {
184
+            throw new \Exception('User id not found in LDAP');
185
+        }
186
+        $access = $this->userBackend->getLDAPAccess($uid);
187
+        $bases = $access->getConnection()->ldapBaseUsers;
188
+        $dn = $this->getUserDN($uid);
189
+        foreach ($bases as $base) {
190
+            if ($access->isDNPartOfBase($dn, [$base])) {
191
+                return $base;
192
+            }
193
+        }
194
+        // should not occur, because the user does not qualify to use NC in this case
195
+        $this->logger->info(
196
+            'No matching user base found for user {dn}, available: {bases}.',
197
+            [
198
+                'app' => 'user_ldap',
199
+                'dn' => $dn,
200
+                'bases' => $bases,
201
+            ]
202
+        );
203
+        return array_shift($bases);
204
+    }
205 205
 
206
-	/**
207
-	 * Get the LDAP base for groups.
208
-	 * @param string $uid user id
209
-	 * @return string the base for groups
210
-	 * @throws \Exception if user id was not found in LDAP
211
-	 */
212
-	public function getLDAPBaseGroups($uid) {
213
-		if (!$this->userBackend->userExists($uid)) {
214
-			throw new \Exception('User id not found in LDAP');
215
-		}
216
-		$bases = $this->userBackend->getLDAPAccess($uid)->getConnection()->ldapBaseGroups;
217
-		return array_shift($bases);
218
-	}
206
+    /**
207
+     * Get the LDAP base for groups.
208
+     * @param string $uid user id
209
+     * @return string the base for groups
210
+     * @throws \Exception if user id was not found in LDAP
211
+     */
212
+    public function getLDAPBaseGroups($uid) {
213
+        if (!$this->userBackend->userExists($uid)) {
214
+            throw new \Exception('User id not found in LDAP');
215
+        }
216
+        $bases = $this->userBackend->getLDAPAccess($uid)->getConnection()->ldapBaseGroups;
217
+        return array_shift($bases);
218
+    }
219 219
 
220
-	/**
221
-	 * Clear the cache if a cache is used, otherwise do nothing.
222
-	 * @param string $uid user id
223
-	 * @throws \Exception if user id was not found in LDAP
224
-	 */
225
-	public function clearCache($uid) {
226
-		if (!$this->userBackend->userExists($uid)) {
227
-			throw new \Exception('User id not found in LDAP');
228
-		}
229
-		$this->userBackend->getLDAPAccess($uid)->getConnection()->clearCache();
230
-	}
220
+    /**
221
+     * Clear the cache if a cache is used, otherwise do nothing.
222
+     * @param string $uid user id
223
+     * @throws \Exception if user id was not found in LDAP
224
+     */
225
+    public function clearCache($uid) {
226
+        if (!$this->userBackend->userExists($uid)) {
227
+            throw new \Exception('User id not found in LDAP');
228
+        }
229
+        $this->userBackend->getLDAPAccess($uid)->getConnection()->clearCache();
230
+    }
231 231
 
232
-	/**
233
-	 * Clear the cache if a cache is used, otherwise do nothing.
234
-	 * Acts on the LDAP connection of a group
235
-	 * @param string $gid group id
236
-	 * @throws \Exception if user id was not found in LDAP
237
-	 */
238
-	public function clearGroupCache($gid) {
239
-		if (!$this->groupBackend->groupExists($gid)) {
240
-			throw new \Exception('Group id not found in LDAP');
241
-		}
242
-		$this->groupBackend->getLDAPAccess($gid)->getConnection()->clearCache();
243
-	}
232
+    /**
233
+     * Clear the cache if a cache is used, otherwise do nothing.
234
+     * Acts on the LDAP connection of a group
235
+     * @param string $gid group id
236
+     * @throws \Exception if user id was not found in LDAP
237
+     */
238
+    public function clearGroupCache($gid) {
239
+        if (!$this->groupBackend->groupExists($gid)) {
240
+            throw new \Exception('Group id not found in LDAP');
241
+        }
242
+        $this->groupBackend->getLDAPAccess($gid)->getConnection()->clearCache();
243
+    }
244 244
 
245
-	/**
246
-	 * Check whether a LDAP DN exists
247
-	 * @param string $dn LDAP DN
248
-	 * @return bool whether the DN exists
249
-	 */
250
-	public function dnExists($dn) {
251
-		$result = $this->userBackend->dn2UserName($dn);
252
-		return !$result ? false : true;
253
-	}
245
+    /**
246
+     * Check whether a LDAP DN exists
247
+     * @param string $dn LDAP DN
248
+     * @return bool whether the DN exists
249
+     */
250
+    public function dnExists($dn) {
251
+        $result = $this->userBackend->dn2UserName($dn);
252
+        return !$result ? false : true;
253
+    }
254 254
 
255
-	/**
256
-	 * Flag record for deletion.
257
-	 * @param string $uid user id
258
-	 */
259
-	public function flagRecord($uid) {
260
-		$this->deletedUsersIndex->markUser($uid);
261
-	}
255
+    /**
256
+     * Flag record for deletion.
257
+     * @param string $uid user id
258
+     */
259
+    public function flagRecord($uid) {
260
+        $this->deletedUsersIndex->markUser($uid);
261
+    }
262 262
 
263
-	/**
264
-	 * Unflag record for deletion.
265
-	 * @param string $uid user id
266
-	 */
267
-	public function unflagRecord($uid) {
268
-		//do nothing
269
-	}
263
+    /**
264
+     * Unflag record for deletion.
265
+     * @param string $uid user id
266
+     */
267
+    public function unflagRecord($uid) {
268
+        //do nothing
269
+    }
270 270
 
271
-	/**
272
-	 * Get the LDAP attribute name for the user's display name
273
-	 * @param string $uid user id
274
-	 * @return string the display name field
275
-	 * @throws \Exception if user id was not found in LDAP
276
-	 */
277
-	public function getLDAPDisplayNameField($uid) {
278
-		if (!$this->userBackend->userExists($uid)) {
279
-			throw new \Exception('User id not found in LDAP');
280
-		}
281
-		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_display_name'];
282
-	}
271
+    /**
272
+     * Get the LDAP attribute name for the user's display name
273
+     * @param string $uid user id
274
+     * @return string the display name field
275
+     * @throws \Exception if user id was not found in LDAP
276
+     */
277
+    public function getLDAPDisplayNameField($uid) {
278
+        if (!$this->userBackend->userExists($uid)) {
279
+            throw new \Exception('User id not found in LDAP');
280
+        }
281
+        return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_display_name'];
282
+    }
283 283
 
284
-	/**
285
-	 * Get the LDAP attribute name for the email
286
-	 * @param string $uid user id
287
-	 * @return string the email field
288
-	 * @throws \Exception if user id was not found in LDAP
289
-	 */
290
-	public function getLDAPEmailField($uid) {
291
-		if (!$this->userBackend->userExists($uid)) {
292
-			throw new \Exception('User id not found in LDAP');
293
-		}
294
-		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_email_attr'];
295
-	}
284
+    /**
285
+     * Get the LDAP attribute name for the email
286
+     * @param string $uid user id
287
+     * @return string the email field
288
+     * @throws \Exception if user id was not found in LDAP
289
+     */
290
+    public function getLDAPEmailField($uid) {
291
+        if (!$this->userBackend->userExists($uid)) {
292
+            throw new \Exception('User id not found in LDAP');
293
+        }
294
+        return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_email_attr'];
295
+    }
296 296
 
297
-	/**
298
-	 * Get the LDAP type of association between users and groups
299
-	 * @param string $gid group id
300
-	 * @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber', ''
301
-	 * @throws \Exception if group id was not found in LDAP
302
-	 */
303
-	public function getLDAPGroupMemberAssoc($gid) {
304
-		if (!$this->groupBackend->groupExists($gid)) {
305
-			throw new \Exception('Group id not found in LDAP');
306
-		}
307
-		return $this->groupBackend->getLDAPAccess($gid)->getConnection()->getConfiguration()['ldap_group_member_assoc_attribute'];
308
-	}
297
+    /**
298
+     * Get the LDAP type of association between users and groups
299
+     * @param string $gid group id
300
+     * @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber', ''
301
+     * @throws \Exception if group id was not found in LDAP
302
+     */
303
+    public function getLDAPGroupMemberAssoc($gid) {
304
+        if (!$this->groupBackend->groupExists($gid)) {
305
+            throw new \Exception('Group id not found in LDAP');
306
+        }
307
+        return $this->groupBackend->getLDAPAccess($gid)->getConnection()->getConfiguration()['ldap_group_member_assoc_attribute'];
308
+    }
309 309
 
310
-	/**
311
-	 * Get an LDAP attribute for a nextcloud user
312
-	 * @param string $uid the nextcloud user id to get the attribute for
313
-	 * @param string $attribute the name of the attribute to read
314
-	 * @return string|null
315
-	 * @throws \Exception if user id was not found in LDAP
316
-	 */
317
-	public function getUserAttribute(string $uid, string $attribute): ?string {
318
-		if (!$this->userBackend->userExists($uid)) {
319
-			throw new \Exception('User id not found in LDAP');
320
-		}
321
-		$access = $this->userBackend->getLDAPAccess($uid);
322
-		$connection = $access->getConnection();
323
-		$key = $uid . "::" . $attribute;
324
-		$cached = $connection->getFromCache($key);
310
+    /**
311
+     * Get an LDAP attribute for a nextcloud user
312
+     * @param string $uid the nextcloud user id to get the attribute for
313
+     * @param string $attribute the name of the attribute to read
314
+     * @return string|null
315
+     * @throws \Exception if user id was not found in LDAP
316
+     */
317
+    public function getUserAttribute(string $uid, string $attribute): ?string {
318
+        if (!$this->userBackend->userExists($uid)) {
319
+            throw new \Exception('User id not found in LDAP');
320
+        }
321
+        $access = $this->userBackend->getLDAPAccess($uid);
322
+        $connection = $access->getConnection();
323
+        $key = $uid . "::" . $attribute;
324
+        $cached = $connection->getFromCache($key);
325 325
 
326
-		if ($cached !== null) {
327
-			return $cached;
328
-		}
326
+        if ($cached !== null) {
327
+            return $cached;
328
+        }
329 329
 
330
-		$value = $access->readAttribute($access->username2dn($uid), $attribute);
331
-		if (is_array($value) && count($value) > 0) {
332
-			$value = current($value);
333
-		} else {
334
-			return null;
335
-		}
336
-		$connection->writeToCache($key, $value);
330
+        $value = $access->readAttribute($access->username2dn($uid), $attribute);
331
+        if (is_array($value) && count($value) > 0) {
332
+            $value = current($value);
333
+        } else {
334
+            return null;
335
+        }
336
+        $connection->writeToCache($key, $value);
337 337
 
338
-		return $value;
339
-	}
338
+        return $value;
339
+    }
340 340
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -320,7 +320,7 @@
 block discarded – undo
320 320
 		}
321 321
 		$access = $this->userBackend->getLDAPAccess($uid);
322 322
 		$connection = $access->getConnection();
323
-		$key = $uid . "::" . $attribute;
323
+		$key = $uid."::".$attribute;
324 324
 		$cached = $connection->getFromCache($key);
325 325
 
326 326
 		if ($cached !== null) {
Please login to merge, or discard this patch.