@@ -147,12 +147,12 @@ discard block |
||
147 | 147 | public function delete($configID) { |
148 | 148 | try { |
149 | 149 | $this->ensureConfigIDExists($configID); |
150 | - if(!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
150 | + if (!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
151 | 151 | throw new OCSException('Could not delete configuration'); |
152 | 152 | } |
153 | - } catch(OCSException $e) { |
|
153 | + } catch (OCSException $e) { |
|
154 | 154 | throw $e; |
155 | - } catch(\Exception $e) { |
|
155 | + } catch (\Exception $e) { |
|
156 | 156 | $this->logger->logException($e); |
157 | 157 | throw new OCSException('An issue occurred when deleting the config.'); |
158 | 158 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | try { |
188 | 188 | $this->ensureConfigIDExists($configID); |
189 | 189 | |
190 | - if(!is_array($configData)) { |
|
190 | + if (!is_array($configData)) { |
|
191 | 191 | throw new OCSBadRequestException('configData is not properly set'); |
192 | 192 | } |
193 | 193 | |
@@ -195,13 +195,13 @@ discard block |
||
195 | 195 | $configKeys = $configuration->getConfigTranslationArray(); |
196 | 196 | |
197 | 197 | foreach ($configKeys as $i => $key) { |
198 | - if(isset($configData[$key])) { |
|
198 | + if (isset($configData[$key])) { |
|
199 | 199 | $configuration->$key = $configData[$key]; |
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | 203 | $configuration->saveConfiguration(); |
204 | - } catch(OCSException $e) { |
|
204 | + } catch (OCSException $e) { |
|
205 | 205 | throw $e; |
206 | 206 | } catch (\Exception $e) { |
207 | 207 | $this->logger->logException($e); |
@@ -288,16 +288,16 @@ discard block |
||
288 | 288 | |
289 | 289 | $config = new Configuration($configID); |
290 | 290 | $data = $config->getConfiguration(); |
291 | - if(!boolval(intval($showPassword))) { |
|
291 | + if (!boolval(intval($showPassword))) { |
|
292 | 292 | $data['ldapAgentPassword'] = '***'; |
293 | 293 | } |
294 | 294 | foreach ($data as $key => $value) { |
295 | - if(is_array($value)) { |
|
295 | + if (is_array($value)) { |
|
296 | 296 | $value = implode(';', $value); |
297 | 297 | $data[$key] = $value; |
298 | 298 | } |
299 | 299 | } |
300 | - } catch(OCSException $e) { |
|
300 | + } catch (OCSException $e) { |
|
301 | 301 | throw $e; |
302 | 302 | } catch (\Exception $e) { |
303 | 303 | $this->logger->logException($e); |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | */ |
316 | 316 | private function ensureConfigIDExists($configID) { |
317 | 317 | $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); |
318 | - if(!in_array($configID, $prefixes, true)) { |
|
318 | + if (!in_array($configID, $prefixes, true)) { |
|
319 | 319 | throw new OCSNotFoundException('Config ID not found'); |
320 | 320 | } |
321 | 321 | } |
@@ -39,281 +39,281 @@ |
||
39 | 39 | |
40 | 40 | class ConfigAPIController extends OCSController { |
41 | 41 | |
42 | - /** @var Helper */ |
|
43 | - private $ldapHelper; |
|
42 | + /** @var Helper */ |
|
43 | + private $ldapHelper; |
|
44 | 44 | |
45 | - /** @var ILogger */ |
|
46 | - private $logger; |
|
45 | + /** @var ILogger */ |
|
46 | + private $logger; |
|
47 | 47 | |
48 | - public function __construct( |
|
49 | - $appName, |
|
50 | - IRequest $request, |
|
51 | - CapabilitiesManager $capabilitiesManager, |
|
52 | - IUserSession $userSession, |
|
53 | - IUserManager $userManager, |
|
54 | - Manager $keyManager, |
|
55 | - Helper $ldapHelper, |
|
56 | - ILogger $logger |
|
57 | - ) { |
|
58 | - parent::__construct( |
|
59 | - $appName, |
|
60 | - $request, |
|
61 | - $capabilitiesManager, |
|
62 | - $userSession, |
|
63 | - $userManager, |
|
64 | - $keyManager |
|
65 | - ); |
|
48 | + public function __construct( |
|
49 | + $appName, |
|
50 | + IRequest $request, |
|
51 | + CapabilitiesManager $capabilitiesManager, |
|
52 | + IUserSession $userSession, |
|
53 | + IUserManager $userManager, |
|
54 | + Manager $keyManager, |
|
55 | + Helper $ldapHelper, |
|
56 | + ILogger $logger |
|
57 | + ) { |
|
58 | + parent::__construct( |
|
59 | + $appName, |
|
60 | + $request, |
|
61 | + $capabilitiesManager, |
|
62 | + $userSession, |
|
63 | + $userManager, |
|
64 | + $keyManager |
|
65 | + ); |
|
66 | 66 | |
67 | 67 | |
68 | - $this->ldapHelper = $ldapHelper; |
|
69 | - $this->logger = $logger; |
|
70 | - } |
|
68 | + $this->ldapHelper = $ldapHelper; |
|
69 | + $this->logger = $logger; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * creates a new (empty) configuration and returns the resulting prefix |
|
74 | - * |
|
75 | - * Example: curl -X POST -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
76 | - * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config |
|
77 | - * |
|
78 | - * results in: |
|
79 | - * |
|
80 | - * <?xml version="1.0"?> |
|
81 | - * <ocs> |
|
82 | - * <meta> |
|
83 | - * <status>ok</status> |
|
84 | - * <statuscode>200</statuscode> |
|
85 | - * <message>OK</message> |
|
86 | - * </meta> |
|
87 | - * <data> |
|
88 | - * <configID>s40</configID> |
|
89 | - * </data> |
|
90 | - * </ocs> |
|
91 | - * |
|
92 | - * Failing example: if an exception is thrown (e.g. Database connection lost) |
|
93 | - * the detailed error will be logged. The output will then look like: |
|
94 | - * |
|
95 | - * <?xml version="1.0"?> |
|
96 | - * <ocs> |
|
97 | - * <meta> |
|
98 | - * <status>failure</status> |
|
99 | - * <statuscode>999</statuscode> |
|
100 | - * <message>An issue occurred when creating the new config.</message> |
|
101 | - * </meta> |
|
102 | - * <data/> |
|
103 | - * </ocs> |
|
104 | - * |
|
105 | - * For JSON output provide the format=json parameter |
|
106 | - * |
|
107 | - * @return DataResponse |
|
108 | - * @throws OCSException |
|
109 | - */ |
|
110 | - public function create() { |
|
111 | - try { |
|
112 | - $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix(); |
|
113 | - $configHolder = new Configuration($configPrefix); |
|
114 | - $configHolder->saveConfiguration(); |
|
115 | - } catch (\Exception $e) { |
|
116 | - $this->logger->logException($e); |
|
117 | - throw new OCSException('An issue occurred when creating the new config.'); |
|
118 | - } |
|
119 | - return new DataResponse(['configID' => $configPrefix]); |
|
120 | - } |
|
72 | + /** |
|
73 | + * creates a new (empty) configuration and returns the resulting prefix |
|
74 | + * |
|
75 | + * Example: curl -X POST -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
76 | + * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config |
|
77 | + * |
|
78 | + * results in: |
|
79 | + * |
|
80 | + * <?xml version="1.0"?> |
|
81 | + * <ocs> |
|
82 | + * <meta> |
|
83 | + * <status>ok</status> |
|
84 | + * <statuscode>200</statuscode> |
|
85 | + * <message>OK</message> |
|
86 | + * </meta> |
|
87 | + * <data> |
|
88 | + * <configID>s40</configID> |
|
89 | + * </data> |
|
90 | + * </ocs> |
|
91 | + * |
|
92 | + * Failing example: if an exception is thrown (e.g. Database connection lost) |
|
93 | + * the detailed error will be logged. The output will then look like: |
|
94 | + * |
|
95 | + * <?xml version="1.0"?> |
|
96 | + * <ocs> |
|
97 | + * <meta> |
|
98 | + * <status>failure</status> |
|
99 | + * <statuscode>999</statuscode> |
|
100 | + * <message>An issue occurred when creating the new config.</message> |
|
101 | + * </meta> |
|
102 | + * <data/> |
|
103 | + * </ocs> |
|
104 | + * |
|
105 | + * For JSON output provide the format=json parameter |
|
106 | + * |
|
107 | + * @return DataResponse |
|
108 | + * @throws OCSException |
|
109 | + */ |
|
110 | + public function create() { |
|
111 | + try { |
|
112 | + $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix(); |
|
113 | + $configHolder = new Configuration($configPrefix); |
|
114 | + $configHolder->saveConfiguration(); |
|
115 | + } catch (\Exception $e) { |
|
116 | + $this->logger->logException($e); |
|
117 | + throw new OCSException('An issue occurred when creating the new config.'); |
|
118 | + } |
|
119 | + return new DataResponse(['configID' => $configPrefix]); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Deletes a LDAP configuration, if present. |
|
124 | - * |
|
125 | - * Example: |
|
126 | - * curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
127 | - * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 |
|
128 | - * |
|
129 | - * <?xml version="1.0"?> |
|
130 | - * <ocs> |
|
131 | - * <meta> |
|
132 | - * <status>ok</status> |
|
133 | - * <statuscode>200</statuscode> |
|
134 | - * <message>OK</message> |
|
135 | - * </meta> |
|
136 | - * <data/> |
|
137 | - * </ocs> |
|
138 | - * |
|
139 | - * @param string $configID |
|
140 | - * @return DataResponse |
|
141 | - * @throws OCSBadRequestException |
|
142 | - * @throws OCSException |
|
143 | - */ |
|
144 | - public function delete($configID) { |
|
145 | - try { |
|
146 | - $this->ensureConfigIDExists($configID); |
|
147 | - if(!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
148 | - throw new OCSException('Could not delete configuration'); |
|
149 | - } |
|
150 | - } catch(OCSException $e) { |
|
151 | - throw $e; |
|
152 | - } catch(\Exception $e) { |
|
153 | - $this->logger->logException($e); |
|
154 | - throw new OCSException('An issue occurred when deleting the config.'); |
|
155 | - } |
|
122 | + /** |
|
123 | + * Deletes a LDAP configuration, if present. |
|
124 | + * |
|
125 | + * Example: |
|
126 | + * curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
127 | + * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 |
|
128 | + * |
|
129 | + * <?xml version="1.0"?> |
|
130 | + * <ocs> |
|
131 | + * <meta> |
|
132 | + * <status>ok</status> |
|
133 | + * <statuscode>200</statuscode> |
|
134 | + * <message>OK</message> |
|
135 | + * </meta> |
|
136 | + * <data/> |
|
137 | + * </ocs> |
|
138 | + * |
|
139 | + * @param string $configID |
|
140 | + * @return DataResponse |
|
141 | + * @throws OCSBadRequestException |
|
142 | + * @throws OCSException |
|
143 | + */ |
|
144 | + public function delete($configID) { |
|
145 | + try { |
|
146 | + $this->ensureConfigIDExists($configID); |
|
147 | + if(!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
148 | + throw new OCSException('Could not delete configuration'); |
|
149 | + } |
|
150 | + } catch(OCSException $e) { |
|
151 | + throw $e; |
|
152 | + } catch(\Exception $e) { |
|
153 | + $this->logger->logException($e); |
|
154 | + throw new OCSException('An issue occurred when deleting the config.'); |
|
155 | + } |
|
156 | 156 | |
157 | - return new DataResponse(); |
|
158 | - } |
|
157 | + return new DataResponse(); |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * modifies a configuration |
|
162 | - * |
|
163 | - * Example: |
|
164 | - * curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \ |
|
165 | - * -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
166 | - * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 |
|
167 | - * |
|
168 | - * <?xml version="1.0"?> |
|
169 | - * <ocs> |
|
170 | - * <meta> |
|
171 | - * <status>ok</status> |
|
172 | - * <statuscode>200</statuscode> |
|
173 | - * <message>OK</message> |
|
174 | - * </meta> |
|
175 | - * <data/> |
|
176 | - * </ocs> |
|
177 | - * |
|
178 | - * @param string $configID |
|
179 | - * @param array $configData |
|
180 | - * @return DataResponse |
|
181 | - * @throws OCSException |
|
182 | - */ |
|
183 | - public function modify($configID, $configData) { |
|
184 | - try { |
|
185 | - $this->ensureConfigIDExists($configID); |
|
160 | + /** |
|
161 | + * modifies a configuration |
|
162 | + * |
|
163 | + * Example: |
|
164 | + * curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \ |
|
165 | + * -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
166 | + * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 |
|
167 | + * |
|
168 | + * <?xml version="1.0"?> |
|
169 | + * <ocs> |
|
170 | + * <meta> |
|
171 | + * <status>ok</status> |
|
172 | + * <statuscode>200</statuscode> |
|
173 | + * <message>OK</message> |
|
174 | + * </meta> |
|
175 | + * <data/> |
|
176 | + * </ocs> |
|
177 | + * |
|
178 | + * @param string $configID |
|
179 | + * @param array $configData |
|
180 | + * @return DataResponse |
|
181 | + * @throws OCSException |
|
182 | + */ |
|
183 | + public function modify($configID, $configData) { |
|
184 | + try { |
|
185 | + $this->ensureConfigIDExists($configID); |
|
186 | 186 | |
187 | - if(!is_array($configData)) { |
|
188 | - throw new OCSBadRequestException('configData is not properly set'); |
|
189 | - } |
|
187 | + if(!is_array($configData)) { |
|
188 | + throw new OCSBadRequestException('configData is not properly set'); |
|
189 | + } |
|
190 | 190 | |
191 | - $configuration = new Configuration($configID); |
|
192 | - $configKeys = $configuration->getConfigTranslationArray(); |
|
191 | + $configuration = new Configuration($configID); |
|
192 | + $configKeys = $configuration->getConfigTranslationArray(); |
|
193 | 193 | |
194 | - foreach ($configKeys as $i => $key) { |
|
195 | - if(isset($configData[$key])) { |
|
196 | - $configuration->$key = $configData[$key]; |
|
197 | - } |
|
198 | - } |
|
194 | + foreach ($configKeys as $i => $key) { |
|
195 | + if(isset($configData[$key])) { |
|
196 | + $configuration->$key = $configData[$key]; |
|
197 | + } |
|
198 | + } |
|
199 | 199 | |
200 | - $configuration->saveConfiguration(); |
|
201 | - } catch(OCSException $e) { |
|
202 | - throw $e; |
|
203 | - } catch (\Exception $e) { |
|
204 | - $this->logger->logException($e); |
|
205 | - throw new OCSException('An issue occurred when modifying the config.'); |
|
206 | - } |
|
200 | + $configuration->saveConfiguration(); |
|
201 | + } catch(OCSException $e) { |
|
202 | + throw $e; |
|
203 | + } catch (\Exception $e) { |
|
204 | + $this->logger->logException($e); |
|
205 | + throw new OCSException('An issue occurred when modifying the config.'); |
|
206 | + } |
|
207 | 207 | |
208 | - return new DataResponse(); |
|
209 | - } |
|
208 | + return new DataResponse(); |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * retrieves a configuration |
|
213 | - * |
|
214 | - * <?xml version="1.0"?> |
|
215 | - * <ocs> |
|
216 | - * <meta> |
|
217 | - * <status>ok</status> |
|
218 | - * <statuscode>200</statuscode> |
|
219 | - * <message>OK</message> |
|
220 | - * </meta> |
|
221 | - * <data> |
|
222 | - * <ldapHost>ldaps://my.ldap.server</ldapHost> |
|
223 | - * <ldapPort>7770</ldapPort> |
|
224 | - * <ldapBackupHost></ldapBackupHost> |
|
225 | - * <ldapBackupPort></ldapBackupPort> |
|
226 | - * <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase> |
|
227 | - * <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers> |
|
228 | - * <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups> |
|
229 | - * <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName> |
|
230 | - * <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword> |
|
231 | - * <ldapTLS>1</ldapTLS> |
|
232 | - * <turnOffCertCheck>0</turnOffCertCheck> |
|
233 | - * <ldapIgnoreNamingRules/> |
|
234 | - * <ldapUserDisplayName>displayname</ldapUserDisplayName> |
|
235 | - * <ldapUserDisplayName2>uid</ldapUserDisplayName2> |
|
236 | - * <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass> |
|
237 | - * <ldapUserFilterGroups></ldapUserFilterGroups> |
|
238 | - * <ldapUserFilter>(&(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter> |
|
239 | - * <ldapUserFilterMode>1</ldapUserFilterMode> |
|
240 | - * <ldapGroupFilter>(&(|(objectclass=nextcloudGroup)))</ldapGroupFilter> |
|
241 | - * <ldapGroupFilterMode>0</ldapGroupFilterMode> |
|
242 | - * <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass> |
|
243 | - * <ldapGroupFilterGroups></ldapGroupFilterGroups> |
|
244 | - * <ldapGroupDisplayName>cn</ldapGroupDisplayName> |
|
245 | - * <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr> |
|
246 | - * <ldapLoginFilter>(&(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter> |
|
247 | - * <ldapLoginFilterMode>0</ldapLoginFilterMode> |
|
248 | - * <ldapLoginFilterEmail>0</ldapLoginFilterEmail> |
|
249 | - * <ldapLoginFilterUsername>1</ldapLoginFilterUsername> |
|
250 | - * <ldapLoginFilterAttributes></ldapLoginFilterAttributes> |
|
251 | - * <ldapQuotaAttribute></ldapQuotaAttribute> |
|
252 | - * <ldapQuotaDefault></ldapQuotaDefault> |
|
253 | - * <ldapEmailAttribute>mail</ldapEmailAttribute> |
|
254 | - * <ldapCacheTTL>20</ldapCacheTTL> |
|
255 | - * <ldapUuidUserAttribute>auto</ldapUuidUserAttribute> |
|
256 | - * <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute> |
|
257 | - * <ldapOverrideMainServer></ldapOverrideMainServer> |
|
258 | - * <ldapConfigurationActive>1</ldapConfigurationActive> |
|
259 | - * <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch> |
|
260 | - * <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch> |
|
261 | - * <ldapExperiencedAdmin>0</ldapExperiencedAdmin> |
|
262 | - * <homeFolderNamingRule></homeFolderNamingRule> |
|
263 | - * <hasPagedResultSupport></hasPagedResultSupport> |
|
264 | - * <hasMemberOfFilterSupport></hasMemberOfFilterSupport> |
|
265 | - * <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership> |
|
266 | - * <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr> |
|
267 | - * <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr> |
|
268 | - * <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr> |
|
269 | - * <lastJpegPhotoLookup>0</lastJpegPhotoLookup> |
|
270 | - * <ldapNestedGroups>0</ldapNestedGroups> |
|
271 | - * <ldapPagingSize>500</ldapPagingSize> |
|
272 | - * <turnOnPasswordChange>1</turnOnPasswordChange> |
|
273 | - * <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL> |
|
274 | - * </data> |
|
275 | - * </ocs> |
|
276 | - * |
|
277 | - * @param string $configID |
|
278 | - * @param bool|string $showPassword |
|
279 | - * @return DataResponse |
|
280 | - * @throws OCSException |
|
281 | - */ |
|
282 | - public function show($configID, $showPassword = false) { |
|
283 | - try { |
|
284 | - $this->ensureConfigIDExists($configID); |
|
211 | + /** |
|
212 | + * retrieves a configuration |
|
213 | + * |
|
214 | + * <?xml version="1.0"?> |
|
215 | + * <ocs> |
|
216 | + * <meta> |
|
217 | + * <status>ok</status> |
|
218 | + * <statuscode>200</statuscode> |
|
219 | + * <message>OK</message> |
|
220 | + * </meta> |
|
221 | + * <data> |
|
222 | + * <ldapHost>ldaps://my.ldap.server</ldapHost> |
|
223 | + * <ldapPort>7770</ldapPort> |
|
224 | + * <ldapBackupHost></ldapBackupHost> |
|
225 | + * <ldapBackupPort></ldapBackupPort> |
|
226 | + * <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase> |
|
227 | + * <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers> |
|
228 | + * <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups> |
|
229 | + * <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName> |
|
230 | + * <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword> |
|
231 | + * <ldapTLS>1</ldapTLS> |
|
232 | + * <turnOffCertCheck>0</turnOffCertCheck> |
|
233 | + * <ldapIgnoreNamingRules/> |
|
234 | + * <ldapUserDisplayName>displayname</ldapUserDisplayName> |
|
235 | + * <ldapUserDisplayName2>uid</ldapUserDisplayName2> |
|
236 | + * <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass> |
|
237 | + * <ldapUserFilterGroups></ldapUserFilterGroups> |
|
238 | + * <ldapUserFilter>(&(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter> |
|
239 | + * <ldapUserFilterMode>1</ldapUserFilterMode> |
|
240 | + * <ldapGroupFilter>(&(|(objectclass=nextcloudGroup)))</ldapGroupFilter> |
|
241 | + * <ldapGroupFilterMode>0</ldapGroupFilterMode> |
|
242 | + * <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass> |
|
243 | + * <ldapGroupFilterGroups></ldapGroupFilterGroups> |
|
244 | + * <ldapGroupDisplayName>cn</ldapGroupDisplayName> |
|
245 | + * <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr> |
|
246 | + * <ldapLoginFilter>(&(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter> |
|
247 | + * <ldapLoginFilterMode>0</ldapLoginFilterMode> |
|
248 | + * <ldapLoginFilterEmail>0</ldapLoginFilterEmail> |
|
249 | + * <ldapLoginFilterUsername>1</ldapLoginFilterUsername> |
|
250 | + * <ldapLoginFilterAttributes></ldapLoginFilterAttributes> |
|
251 | + * <ldapQuotaAttribute></ldapQuotaAttribute> |
|
252 | + * <ldapQuotaDefault></ldapQuotaDefault> |
|
253 | + * <ldapEmailAttribute>mail</ldapEmailAttribute> |
|
254 | + * <ldapCacheTTL>20</ldapCacheTTL> |
|
255 | + * <ldapUuidUserAttribute>auto</ldapUuidUserAttribute> |
|
256 | + * <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute> |
|
257 | + * <ldapOverrideMainServer></ldapOverrideMainServer> |
|
258 | + * <ldapConfigurationActive>1</ldapConfigurationActive> |
|
259 | + * <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch> |
|
260 | + * <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch> |
|
261 | + * <ldapExperiencedAdmin>0</ldapExperiencedAdmin> |
|
262 | + * <homeFolderNamingRule></homeFolderNamingRule> |
|
263 | + * <hasPagedResultSupport></hasPagedResultSupport> |
|
264 | + * <hasMemberOfFilterSupport></hasMemberOfFilterSupport> |
|
265 | + * <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership> |
|
266 | + * <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr> |
|
267 | + * <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr> |
|
268 | + * <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr> |
|
269 | + * <lastJpegPhotoLookup>0</lastJpegPhotoLookup> |
|
270 | + * <ldapNestedGroups>0</ldapNestedGroups> |
|
271 | + * <ldapPagingSize>500</ldapPagingSize> |
|
272 | + * <turnOnPasswordChange>1</turnOnPasswordChange> |
|
273 | + * <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL> |
|
274 | + * </data> |
|
275 | + * </ocs> |
|
276 | + * |
|
277 | + * @param string $configID |
|
278 | + * @param bool|string $showPassword |
|
279 | + * @return DataResponse |
|
280 | + * @throws OCSException |
|
281 | + */ |
|
282 | + public function show($configID, $showPassword = false) { |
|
283 | + try { |
|
284 | + $this->ensureConfigIDExists($configID); |
|
285 | 285 | |
286 | - $config = new Configuration($configID); |
|
287 | - $data = $config->getConfiguration(); |
|
288 | - if(!boolval(intval($showPassword))) { |
|
289 | - $data['ldapAgentPassword'] = '***'; |
|
290 | - } |
|
291 | - foreach ($data as $key => $value) { |
|
292 | - if(is_array($value)) { |
|
293 | - $value = implode(';', $value); |
|
294 | - $data[$key] = $value; |
|
295 | - } |
|
296 | - } |
|
297 | - } catch(OCSException $e) { |
|
298 | - throw $e; |
|
299 | - } catch (\Exception $e) { |
|
300 | - $this->logger->logException($e); |
|
301 | - throw new OCSException('An issue occurred when modifying the config.'); |
|
302 | - } |
|
286 | + $config = new Configuration($configID); |
|
287 | + $data = $config->getConfiguration(); |
|
288 | + if(!boolval(intval($showPassword))) { |
|
289 | + $data['ldapAgentPassword'] = '***'; |
|
290 | + } |
|
291 | + foreach ($data as $key => $value) { |
|
292 | + if(is_array($value)) { |
|
293 | + $value = implode(';', $value); |
|
294 | + $data[$key] = $value; |
|
295 | + } |
|
296 | + } |
|
297 | + } catch(OCSException $e) { |
|
298 | + throw $e; |
|
299 | + } catch (\Exception $e) { |
|
300 | + $this->logger->logException($e); |
|
301 | + throw new OCSException('An issue occurred when modifying the config.'); |
|
302 | + } |
|
303 | 303 | |
304 | - return new DataResponse($data); |
|
305 | - } |
|
304 | + return new DataResponse($data); |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * if the given config ID is not available, an exception is thrown |
|
309 | - * |
|
310 | - * @param string $configID |
|
311 | - * @throws OCSNotFoundException |
|
312 | - */ |
|
313 | - private function ensureConfigIDExists($configID) { |
|
314 | - $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); |
|
315 | - if(!in_array($configID, $prefixes, true)) { |
|
316 | - throw new OCSNotFoundException('Config ID not found'); |
|
317 | - } |
|
318 | - } |
|
307 | + /** |
|
308 | + * if the given config ID is not available, an exception is thrown |
|
309 | + * |
|
310 | + * @param string $configID |
|
311 | + * @throws OCSNotFoundException |
|
312 | + */ |
|
313 | + private function ensureConfigIDExists($configID) { |
|
314 | + $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); |
|
315 | + if(!in_array($configID, $prefixes, true)) { |
|
316 | + throw new OCSNotFoundException('Config ID not found'); |
|
317 | + } |
|
318 | + } |
|
319 | 319 | } |
@@ -27,13 +27,13 @@ |
||
27 | 27 | |
28 | 28 | |
29 | 29 | abstract class BackendUtility { |
30 | - protected $access; |
|
30 | + protected $access; |
|
31 | 31 | |
32 | - /** |
|
33 | - * constructor, make sure the subclasses call this one! |
|
34 | - * @param Access $access an instance of Access for LDAP interaction |
|
35 | - */ |
|
36 | - public function __construct(Access $access) { |
|
37 | - $this->access = $access; |
|
38 | - } |
|
32 | + /** |
|
33 | + * constructor, make sure the subclasses call this one! |
|
34 | + * @param Access $access an instance of Access for LDAP interaction |
|
35 | + */ |
|
36 | + public function __construct(Access $access) { |
|
37 | + $this->access = $access; |
|
38 | + } |
|
39 | 39 | } |
@@ -28,52 +28,52 @@ |
||
28 | 28 | namespace OCA\User_LDAP; |
29 | 29 | |
30 | 30 | class WizardResult { |
31 | - protected $changes = array(); |
|
32 | - protected $options = array(); |
|
33 | - protected $markedChange = false; |
|
31 | + protected $changes = array(); |
|
32 | + protected $options = array(); |
|
33 | + protected $markedChange = false; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string $key |
|
37 | - * @param mixed $value |
|
38 | - */ |
|
39 | - public function addChange($key, $value) { |
|
40 | - $this->changes[$key] = $value; |
|
41 | - } |
|
35 | + /** |
|
36 | + * @param string $key |
|
37 | + * @param mixed $value |
|
38 | + */ |
|
39 | + public function addChange($key, $value) { |
|
40 | + $this->changes[$key] = $value; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * |
|
45 | - */ |
|
46 | - public function markChange() { |
|
47 | - $this->markedChange = true; |
|
48 | - } |
|
43 | + /** |
|
44 | + * |
|
45 | + */ |
|
46 | + public function markChange() { |
|
47 | + $this->markedChange = true; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $key |
|
52 | - * @param array|string $values |
|
53 | - */ |
|
54 | - public function addOptions($key, $values) { |
|
55 | - if(!is_array($values)) { |
|
56 | - $values = array($values); |
|
57 | - } |
|
58 | - $this->options[$key] = $values; |
|
59 | - } |
|
50 | + /** |
|
51 | + * @param string $key |
|
52 | + * @param array|string $values |
|
53 | + */ |
|
54 | + public function addOptions($key, $values) { |
|
55 | + if(!is_array($values)) { |
|
56 | + $values = array($values); |
|
57 | + } |
|
58 | + $this->options[$key] = $values; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function hasChanges() { |
|
65 | - return (count($this->changes) > 0 || $this->markedChange); |
|
66 | - } |
|
61 | + /** |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function hasChanges() { |
|
65 | + return (count($this->changes) > 0 || $this->markedChange); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function getResultArray() { |
|
72 | - $result = array(); |
|
73 | - $result['changes'] = $this->changes; |
|
74 | - if(count($this->options) > 0) { |
|
75 | - $result['options'] = $this->options; |
|
76 | - } |
|
77 | - return $result; |
|
78 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function getResultArray() { |
|
72 | + $result = array(); |
|
73 | + $result['changes'] = $this->changes; |
|
74 | + if(count($this->options) > 0) { |
|
75 | + $result['options'] = $this->options; |
|
76 | + } |
|
77 | + return $result; |
|
78 | + } |
|
79 | 79 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param array|string $values |
53 | 53 | */ |
54 | 54 | public function addOptions($key, $values) { |
55 | - if(!is_array($values)) { |
|
55 | + if (!is_array($values)) { |
|
56 | 56 | $values = array($values); |
57 | 57 | } |
58 | 58 | $this->options[$key] = $values; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | public function getResultArray() { |
72 | 72 | $result = array(); |
73 | 73 | $result['changes'] = $this->changes; |
74 | - if(count($this->options) > 0) { |
|
74 | + if (count($this->options) > 0) { |
|
75 | 75 | $result['options'] = $this->options; |
76 | 76 | } |
77 | 77 | return $result; |
@@ -32,70 +32,70 @@ |
||
32 | 32 | |
33 | 33 | class UUIDFixInsert implements IRepairStep { |
34 | 34 | |
35 | - /** @var IConfig */ |
|
36 | - protected $config; |
|
35 | + /** @var IConfig */ |
|
36 | + protected $config; |
|
37 | 37 | |
38 | - /** @var UserMapping */ |
|
39 | - protected $userMapper; |
|
38 | + /** @var UserMapping */ |
|
39 | + protected $userMapper; |
|
40 | 40 | |
41 | - /** @var GroupMapping */ |
|
42 | - protected $groupMapper; |
|
41 | + /** @var GroupMapping */ |
|
42 | + protected $groupMapper; |
|
43 | 43 | |
44 | - /** @var IJobList */ |
|
45 | - protected $jobList; |
|
44 | + /** @var IJobList */ |
|
45 | + protected $jobList; |
|
46 | 46 | |
47 | - public function __construct(IConfig $config, UserMapping $userMapper, GroupMapping $groupMapper, IJobList $jobList) { |
|
48 | - $this->config = $config; |
|
49 | - $this->userMapper = $userMapper; |
|
50 | - $this->groupMapper = $groupMapper; |
|
51 | - $this->jobList = $jobList; |
|
52 | - } |
|
47 | + public function __construct(IConfig $config, UserMapping $userMapper, GroupMapping $groupMapper, IJobList $jobList) { |
|
48 | + $this->config = $config; |
|
49 | + $this->userMapper = $userMapper; |
|
50 | + $this->groupMapper = $groupMapper; |
|
51 | + $this->jobList = $jobList; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns the step's name |
|
56 | - * |
|
57 | - * @return string |
|
58 | - * @since 9.1.0 |
|
59 | - */ |
|
60 | - public function getName() { |
|
61 | - return 'Insert UUIDFix background job for user and group in batches'; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Returns the step's name |
|
56 | + * |
|
57 | + * @return string |
|
58 | + * @since 9.1.0 |
|
59 | + */ |
|
60 | + public function getName() { |
|
61 | + return 'Insert UUIDFix background job for user and group in batches'; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Run repair step. |
|
66 | - * Must throw exception on error. |
|
67 | - * |
|
68 | - * @param IOutput $output |
|
69 | - * @throws \Exception in case of failure |
|
70 | - * @since 9.1.0 |
|
71 | - */ |
|
72 | - public function run(IOutput $output) { |
|
73 | - $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1'); |
|
74 | - if(version_compare($installedVersion, '1.2.1') !== -1) { |
|
75 | - return; |
|
76 | - } |
|
64 | + /** |
|
65 | + * Run repair step. |
|
66 | + * Must throw exception on error. |
|
67 | + * |
|
68 | + * @param IOutput $output |
|
69 | + * @throws \Exception in case of failure |
|
70 | + * @since 9.1.0 |
|
71 | + */ |
|
72 | + public function run(IOutput $output) { |
|
73 | + $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1'); |
|
74 | + if(version_compare($installedVersion, '1.2.1') !== -1) { |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - foreach ([$this->userMapper, $this->groupMapper] as $mapper) { |
|
79 | - $offset = 0; |
|
80 | - $batchSize = 50; |
|
81 | - $jobClass = $mapper instanceof UserMapping ? UUIDFixUser::class : UUIDFixGroup::class; |
|
82 | - do { |
|
83 | - $retry = false; |
|
84 | - $records = $mapper->getList($offset, $batchSize); |
|
85 | - if(count($records) === 0){ |
|
86 | - continue; |
|
87 | - } |
|
88 | - try { |
|
89 | - $this->jobList->add($jobClass, ['records' => $records]); |
|
90 | - $offset += $batchSize; |
|
91 | - } catch (\InvalidArgumentException $e) { |
|
92 | - if(strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
93 | - $batchSize = intval(floor(count($records) * 0.8)); |
|
94 | - $retry = true; |
|
95 | - } |
|
96 | - } |
|
97 | - } while (count($records) === $batchSize || $retry); |
|
98 | - } |
|
78 | + foreach ([$this->userMapper, $this->groupMapper] as $mapper) { |
|
79 | + $offset = 0; |
|
80 | + $batchSize = 50; |
|
81 | + $jobClass = $mapper instanceof UserMapping ? UUIDFixUser::class : UUIDFixGroup::class; |
|
82 | + do { |
|
83 | + $retry = false; |
|
84 | + $records = $mapper->getList($offset, $batchSize); |
|
85 | + if(count($records) === 0){ |
|
86 | + continue; |
|
87 | + } |
|
88 | + try { |
|
89 | + $this->jobList->add($jobClass, ['records' => $records]); |
|
90 | + $offset += $batchSize; |
|
91 | + } catch (\InvalidArgumentException $e) { |
|
92 | + if(strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
93 | + $batchSize = intval(floor(count($records) * 0.8)); |
|
94 | + $retry = true; |
|
95 | + } |
|
96 | + } |
|
97 | + } while (count($records) === $batchSize || $retry); |
|
98 | + } |
|
99 | 99 | |
100 | - } |
|
100 | + } |
|
101 | 101 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function run(IOutput $output) { |
73 | 73 | $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1'); |
74 | - if(version_compare($installedVersion, '1.2.1') !== -1) { |
|
74 | + if (version_compare($installedVersion, '1.2.1') !== -1) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
@@ -82,14 +82,14 @@ discard block |
||
82 | 82 | do { |
83 | 83 | $retry = false; |
84 | 84 | $records = $mapper->getList($offset, $batchSize); |
85 | - if(count($records) === 0){ |
|
85 | + if (count($records) === 0) { |
|
86 | 86 | continue; |
87 | 87 | } |
88 | 88 | try { |
89 | 89 | $this->jobList->add($jobClass, ['records' => $records]); |
90 | 90 | $offset += $batchSize; |
91 | 91 | } catch (\InvalidArgumentException $e) { |
92 | - if(strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
92 | + if (strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
93 | 93 | $batchSize = intval(floor(count($records) * 0.8)); |
94 | 94 | $retry = true; |
95 | 95 | } |
@@ -30,8 +30,8 @@ |
||
30 | 30 | use OCP\IConfig; |
31 | 31 | |
32 | 32 | class UUIDFixUser extends UUIDFix { |
33 | - public function __construct(UserMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) { |
|
34 | - $this->mapper = $mapper; |
|
35 | - $this->proxy = new Group_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config); |
|
36 | - } |
|
33 | + public function __construct(UserMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) { |
|
34 | + $this->mapper = $mapper; |
|
35 | + $this->proxy = new Group_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config); |
|
36 | + } |
|
37 | 37 | } |
@@ -30,31 +30,31 @@ |
||
30 | 30 | use OCA\User_LDAP\User_Proxy; |
31 | 31 | |
32 | 32 | abstract class UUIDFix extends QueuedJob { |
33 | - /** @var AbstractMapping */ |
|
34 | - protected $mapper; |
|
33 | + /** @var AbstractMapping */ |
|
34 | + protected $mapper; |
|
35 | 35 | |
36 | - /** @var Proxy */ |
|
37 | - protected $proxy; |
|
36 | + /** @var Proxy */ |
|
37 | + protected $proxy; |
|
38 | 38 | |
39 | - public function run($argument) { |
|
40 | - $isUser = $this->proxy instanceof User_Proxy; |
|
41 | - foreach($argument['records'] as $record) { |
|
42 | - $access = $this->proxy->getLDAPAccess($record['name']); |
|
43 | - $uuid = $access->getUUID($record['dn'], $isUser); |
|
44 | - if($uuid === false) { |
|
45 | - // record not found, no prob, continue with the next |
|
46 | - continue; |
|
47 | - } |
|
48 | - if($uuid !== $record['uuid']) { |
|
49 | - $this->mapper->setUUIDbyDN($uuid, $record['dn']); |
|
50 | - } |
|
51 | - } |
|
52 | - } |
|
39 | + public function run($argument) { |
|
40 | + $isUser = $this->proxy instanceof User_Proxy; |
|
41 | + foreach($argument['records'] as $record) { |
|
42 | + $access = $this->proxy->getLDAPAccess($record['name']); |
|
43 | + $uuid = $access->getUUID($record['dn'], $isUser); |
|
44 | + if($uuid === false) { |
|
45 | + // record not found, no prob, continue with the next |
|
46 | + continue; |
|
47 | + } |
|
48 | + if($uuid !== $record['uuid']) { |
|
49 | + $this->mapper->setUUIDbyDN($uuid, $record['dn']); |
|
50 | + } |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param Proxy $proxy |
|
56 | - */ |
|
57 | - public function overrideProxy(Proxy $proxy) { |
|
58 | - $this->proxy = $proxy; |
|
59 | - } |
|
54 | + /** |
|
55 | + * @param Proxy $proxy |
|
56 | + */ |
|
57 | + public function overrideProxy(Proxy $proxy) { |
|
58 | + $this->proxy = $proxy; |
|
59 | + } |
|
60 | 60 | } |
@@ -38,14 +38,14 @@ |
||
38 | 38 | |
39 | 39 | public function run($argument) { |
40 | 40 | $isUser = $this->proxy instanceof User_Proxy; |
41 | - foreach($argument['records'] as $record) { |
|
41 | + foreach ($argument['records'] as $record) { |
|
42 | 42 | $access = $this->proxy->getLDAPAccess($record['name']); |
43 | 43 | $uuid = $access->getUUID($record['dn'], $isUser); |
44 | - if($uuid === false) { |
|
44 | + if ($uuid === false) { |
|
45 | 45 | // record not found, no prob, continue with the next |
46 | 46 | continue; |
47 | 47 | } |
48 | - if($uuid !== $record['uuid']) { |
|
48 | + if ($uuid !== $record['uuid']) { |
|
49 | 49 | $this->mapper->setUUIDbyDN($uuid, $record['dn']); |
50 | 50 | } |
51 | 51 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $this->isAllowed($input->getOption('force')); |
87 | 87 | $this->confirmUserIsMapped($uid); |
88 | 88 | $exists = $this->backend->userExistsOnLDAP($uid); |
89 | - if($exists === true) { |
|
89 | + if ($exists === true) { |
|
90 | 90 | $output->writeln('The user is still available on LDAP.'); |
91 | 91 | return; |
92 | 92 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | $this->dui->markUser($uid); |
95 | 95 | $output->writeln('The user does not exists on LDAP anymore.'); |
96 | 96 | $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
97 | - . $uid . '"'); |
|
97 | + . $uid.'"'); |
|
98 | 98 | } catch (\Exception $e) { |
99 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
99 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @return true |
122 | 122 | */ |
123 | 123 | protected function isAllowed($force) { |
124 | - if($this->helper->haveDisabledConfigurations() && !$force) { |
|
124 | + if ($this->helper->haveDisabledConfigurations() && !$force) { |
|
125 | 125 | throw new \Exception('Cannot check user existence, because ' |
126 | 126 | . 'disabled LDAP configurations are present.'); |
127 | 127 | } |
@@ -36,101 +36,101 @@ |
||
36 | 36 | use OCA\User_LDAP\User_Proxy; |
37 | 37 | |
38 | 38 | class CheckUser extends Command { |
39 | - /** @var \OCA\User_LDAP\User_Proxy */ |
|
40 | - protected $backend; |
|
41 | - |
|
42 | - /** @var \OCA\User_LDAP\Helper */ |
|
43 | - protected $helper; |
|
44 | - |
|
45 | - /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
46 | - protected $dui; |
|
47 | - |
|
48 | - /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
49 | - protected $mapping; |
|
50 | - |
|
51 | - /** |
|
52 | - * @param User_Proxy $uBackend |
|
53 | - * @param LDAPHelper $helper |
|
54 | - * @param DeletedUsersIndex $dui |
|
55 | - * @param UserMapping $mapping |
|
56 | - */ |
|
57 | - public function __construct(User_Proxy $uBackend, LDAPHelper $helper, DeletedUsersIndex $dui, UserMapping $mapping) { |
|
58 | - $this->backend = $uBackend; |
|
59 | - $this->helper = $helper; |
|
60 | - $this->dui = $dui; |
|
61 | - $this->mapping = $mapping; |
|
62 | - parent::__construct(); |
|
63 | - } |
|
64 | - |
|
65 | - protected function configure() { |
|
66 | - $this |
|
67 | - ->setName('ldap:check-user') |
|
68 | - ->setDescription('checks whether a user exists on LDAP.') |
|
69 | - ->addArgument( |
|
70 | - 'ocName', |
|
71 | - InputArgument::REQUIRED, |
|
72 | - 'the user name as used in Nextcloud' |
|
73 | - ) |
|
74 | - ->addOption( |
|
75 | - 'force', |
|
76 | - null, |
|
77 | - InputOption::VALUE_NONE, |
|
78 | - 'ignores disabled LDAP configuration' |
|
79 | - ) |
|
80 | - ; |
|
81 | - } |
|
82 | - |
|
83 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
84 | - try { |
|
85 | - $uid = $input->getArgument('ocName'); |
|
86 | - $this->isAllowed($input->getOption('force')); |
|
87 | - $this->confirmUserIsMapped($uid); |
|
88 | - $exists = $this->backend->userExistsOnLDAP($uid); |
|
89 | - if($exists === true) { |
|
90 | - $output->writeln('The user is still available on LDAP.'); |
|
91 | - return; |
|
92 | - } |
|
93 | - |
|
94 | - $this->dui->markUser($uid); |
|
95 | - $output->writeln('The user does not exists on LDAP anymore.'); |
|
96 | - $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
|
97 | - . $uid . '"'); |
|
98 | - } catch (\Exception $e) { |
|
99 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * checks whether a user is actually mapped |
|
105 | - * @param string $ocName the username as used in Nextcloud |
|
106 | - * @throws \Exception |
|
107 | - * @return true |
|
108 | - */ |
|
109 | - protected function confirmUserIsMapped($ocName) { |
|
110 | - $dn = $this->mapping->getDNByName($ocName); |
|
111 | - if ($dn === false) { |
|
112 | - throw new \Exception('The given user is not a recognized LDAP user.'); |
|
113 | - } |
|
114 | - |
|
115 | - return true; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * checks whether the setup allows reliable checking of LDAP user existence |
|
120 | - * @throws \Exception |
|
121 | - * @return true |
|
122 | - */ |
|
123 | - protected function isAllowed($force) { |
|
124 | - if($this->helper->haveDisabledConfigurations() && !$force) { |
|
125 | - throw new \Exception('Cannot check user existence, because ' |
|
126 | - . 'disabled LDAP configurations are present.'); |
|
127 | - } |
|
128 | - |
|
129 | - // we don't check ldapUserCleanupInterval from config.php because this |
|
130 | - // action is triggered manually, while the setting only controls the |
|
131 | - // background job. |
|
132 | - |
|
133 | - return true; |
|
134 | - } |
|
39 | + /** @var \OCA\User_LDAP\User_Proxy */ |
|
40 | + protected $backend; |
|
41 | + |
|
42 | + /** @var \OCA\User_LDAP\Helper */ |
|
43 | + protected $helper; |
|
44 | + |
|
45 | + /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
46 | + protected $dui; |
|
47 | + |
|
48 | + /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
49 | + protected $mapping; |
|
50 | + |
|
51 | + /** |
|
52 | + * @param User_Proxy $uBackend |
|
53 | + * @param LDAPHelper $helper |
|
54 | + * @param DeletedUsersIndex $dui |
|
55 | + * @param UserMapping $mapping |
|
56 | + */ |
|
57 | + public function __construct(User_Proxy $uBackend, LDAPHelper $helper, DeletedUsersIndex $dui, UserMapping $mapping) { |
|
58 | + $this->backend = $uBackend; |
|
59 | + $this->helper = $helper; |
|
60 | + $this->dui = $dui; |
|
61 | + $this->mapping = $mapping; |
|
62 | + parent::__construct(); |
|
63 | + } |
|
64 | + |
|
65 | + protected function configure() { |
|
66 | + $this |
|
67 | + ->setName('ldap:check-user') |
|
68 | + ->setDescription('checks whether a user exists on LDAP.') |
|
69 | + ->addArgument( |
|
70 | + 'ocName', |
|
71 | + InputArgument::REQUIRED, |
|
72 | + 'the user name as used in Nextcloud' |
|
73 | + ) |
|
74 | + ->addOption( |
|
75 | + 'force', |
|
76 | + null, |
|
77 | + InputOption::VALUE_NONE, |
|
78 | + 'ignores disabled LDAP configuration' |
|
79 | + ) |
|
80 | + ; |
|
81 | + } |
|
82 | + |
|
83 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
84 | + try { |
|
85 | + $uid = $input->getArgument('ocName'); |
|
86 | + $this->isAllowed($input->getOption('force')); |
|
87 | + $this->confirmUserIsMapped($uid); |
|
88 | + $exists = $this->backend->userExistsOnLDAP($uid); |
|
89 | + if($exists === true) { |
|
90 | + $output->writeln('The user is still available on LDAP.'); |
|
91 | + return; |
|
92 | + } |
|
93 | + |
|
94 | + $this->dui->markUser($uid); |
|
95 | + $output->writeln('The user does not exists on LDAP anymore.'); |
|
96 | + $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
|
97 | + . $uid . '"'); |
|
98 | + } catch (\Exception $e) { |
|
99 | + $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * checks whether a user is actually mapped |
|
105 | + * @param string $ocName the username as used in Nextcloud |
|
106 | + * @throws \Exception |
|
107 | + * @return true |
|
108 | + */ |
|
109 | + protected function confirmUserIsMapped($ocName) { |
|
110 | + $dn = $this->mapping->getDNByName($ocName); |
|
111 | + if ($dn === false) { |
|
112 | + throw new \Exception('The given user is not a recognized LDAP user.'); |
|
113 | + } |
|
114 | + |
|
115 | + return true; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * checks whether the setup allows reliable checking of LDAP user existence |
|
120 | + * @throws \Exception |
|
121 | + * @return true |
|
122 | + */ |
|
123 | + protected function isAllowed($force) { |
|
124 | + if($this->helper->haveDisabledConfigurations() && !$force) { |
|
125 | + throw new \Exception('Cannot check user existence, because ' |
|
126 | + . 'disabled LDAP configurations are present.'); |
|
127 | + } |
|
128 | + |
|
129 | + // we don't check ldapUserCleanupInterval from config.php because this |
|
130 | + // action is triggered manually, while the setting only controls the |
|
131 | + // background job. |
|
132 | + |
|
133 | + return true; |
|
134 | + } |
|
135 | 135 | |
136 | 136 | } |
@@ -87,16 +87,16 @@ discard block |
||
87 | 87 | * @throws \InvalidArgumentException |
88 | 88 | */ |
89 | 89 | protected function validateOffsetAndLimit($offset, $limit) { |
90 | - if($limit < 0) { |
|
90 | + if ($limit < 0) { |
|
91 | 91 | throw new \InvalidArgumentException('limit must be 0 or greater'); |
92 | 92 | } |
93 | - if($offset < 0) { |
|
93 | + if ($offset < 0) { |
|
94 | 94 | throw new \InvalidArgumentException('offset must be 0 or greater'); |
95 | 95 | } |
96 | - if($limit === 0 && $offset !== 0) { |
|
96 | + if ($limit === 0 && $offset !== 0) { |
|
97 | 97 | throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
98 | 98 | } |
99 | - if($offset > 0 && ($offset % $limit !== 0)) { |
|
99 | + if ($offset > 0 && ($offset % $limit !== 0)) { |
|
100 | 100 | throw new \InvalidArgumentException('offset must be a multiple of limit'); |
101 | 101 | } |
102 | 102 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $limit = intval($input->getOption('limit')); |
111 | 111 | $this->validateOffsetAndLimit($offset, $limit); |
112 | 112 | |
113 | - if($input->getOption('group')) { |
|
113 | + if ($input->getOption('group')) { |
|
114 | 114 | $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
115 | 115 | $getMethod = 'getGroups'; |
116 | 116 | $printID = false; |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
124 | - foreach($result as $id => $name) { |
|
125 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
124 | + foreach ($result as $id => $name) { |
|
125 | + $line = $name.($printID ? ' ('.$id.')' : ''); |
|
126 | 126 | $output->writeln($line); |
127 | 127 | } |
128 | 128 | } |
@@ -37,98 +37,98 @@ |
||
37 | 37 | use OCP\IConfig; |
38 | 38 | |
39 | 39 | class Search extends Command { |
40 | - /** @var \OCP\IConfig */ |
|
41 | - protected $ocConfig; |
|
40 | + /** @var \OCP\IConfig */ |
|
41 | + protected $ocConfig; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param \OCP\IConfig $ocConfig |
|
45 | - */ |
|
46 | - public function __construct(IConfig $ocConfig) { |
|
47 | - $this->ocConfig = $ocConfig; |
|
48 | - parent::__construct(); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @param \OCP\IConfig $ocConfig |
|
45 | + */ |
|
46 | + public function __construct(IConfig $ocConfig) { |
|
47 | + $this->ocConfig = $ocConfig; |
|
48 | + parent::__construct(); |
|
49 | + } |
|
50 | 50 | |
51 | - protected function configure() { |
|
52 | - $this |
|
53 | - ->setName('ldap:search') |
|
54 | - ->setDescription('executes a user or group search') |
|
55 | - ->addArgument( |
|
56 | - 'search', |
|
57 | - InputArgument::REQUIRED, |
|
58 | - 'the search string (can be empty)' |
|
59 | - ) |
|
60 | - ->addOption( |
|
61 | - 'group', |
|
62 | - null, |
|
63 | - InputOption::VALUE_NONE, |
|
64 | - 'searches groups instead of users' |
|
65 | - ) |
|
66 | - ->addOption( |
|
67 | - 'offset', |
|
68 | - null, |
|
69 | - InputOption::VALUE_REQUIRED, |
|
70 | - 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
71 | - 0 |
|
72 | - ) |
|
73 | - ->addOption( |
|
74 | - 'limit', |
|
75 | - null, |
|
76 | - InputOption::VALUE_REQUIRED, |
|
77 | - 'limit the results. 0 means no limit, defaults to 15', |
|
78 | - 15 |
|
79 | - ) |
|
80 | - ; |
|
81 | - } |
|
51 | + protected function configure() { |
|
52 | + $this |
|
53 | + ->setName('ldap:search') |
|
54 | + ->setDescription('executes a user or group search') |
|
55 | + ->addArgument( |
|
56 | + 'search', |
|
57 | + InputArgument::REQUIRED, |
|
58 | + 'the search string (can be empty)' |
|
59 | + ) |
|
60 | + ->addOption( |
|
61 | + 'group', |
|
62 | + null, |
|
63 | + InputOption::VALUE_NONE, |
|
64 | + 'searches groups instead of users' |
|
65 | + ) |
|
66 | + ->addOption( |
|
67 | + 'offset', |
|
68 | + null, |
|
69 | + InputOption::VALUE_REQUIRED, |
|
70 | + 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
71 | + 0 |
|
72 | + ) |
|
73 | + ->addOption( |
|
74 | + 'limit', |
|
75 | + null, |
|
76 | + InputOption::VALUE_REQUIRED, |
|
77 | + 'limit the results. 0 means no limit, defaults to 15', |
|
78 | + 15 |
|
79 | + ) |
|
80 | + ; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Tests whether the offset and limit options are valid |
|
85 | - * @param int $offset |
|
86 | - * @param int $limit |
|
87 | - * @throws \InvalidArgumentException |
|
88 | - */ |
|
89 | - protected function validateOffsetAndLimit($offset, $limit) { |
|
90 | - if($limit < 0) { |
|
91 | - throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
92 | - } |
|
93 | - if($offset < 0) { |
|
94 | - throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
95 | - } |
|
96 | - if($limit === 0 && $offset !== 0) { |
|
97 | - throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
98 | - } |
|
99 | - if($offset > 0 && ($offset % $limit !== 0)) { |
|
100 | - throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
101 | - } |
|
102 | - } |
|
83 | + /** |
|
84 | + * Tests whether the offset and limit options are valid |
|
85 | + * @param int $offset |
|
86 | + * @param int $limit |
|
87 | + * @throws \InvalidArgumentException |
|
88 | + */ |
|
89 | + protected function validateOffsetAndLimit($offset, $limit) { |
|
90 | + if($limit < 0) { |
|
91 | + throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
92 | + } |
|
93 | + if($offset < 0) { |
|
94 | + throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
95 | + } |
|
96 | + if($limit === 0 && $offset !== 0) { |
|
97 | + throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
98 | + } |
|
99 | + if($offset > 0 && ($offset % $limit !== 0)) { |
|
100 | + throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
105 | - $helper = new Helper($this->ocConfig); |
|
106 | - $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
107 | - $ldapWrapper = new LDAP(); |
|
104 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
105 | + $helper = new Helper($this->ocConfig); |
|
106 | + $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
107 | + $ldapWrapper = new LDAP(); |
|
108 | 108 | |
109 | - $offset = intval($input->getOption('offset')); |
|
110 | - $limit = intval($input->getOption('limit')); |
|
111 | - $this->validateOffsetAndLimit($offset, $limit); |
|
109 | + $offset = intval($input->getOption('offset')); |
|
110 | + $limit = intval($input->getOption('limit')); |
|
111 | + $this->validateOffsetAndLimit($offset, $limit); |
|
112 | 112 | |
113 | - if($input->getOption('group')) { |
|
114 | - $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
115 | - $getMethod = 'getGroups'; |
|
116 | - $printID = false; |
|
117 | - // convert the limit of groups to null. This will show all the groups available instead of |
|
118 | - // nothing, and will match the same behaviour the search for users has. |
|
119 | - if ($limit === 0) { |
|
120 | - $limit = null; |
|
121 | - } |
|
122 | - } else { |
|
123 | - $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig, \OC::$server->getNotificationManager()); |
|
124 | - $getMethod = 'getDisplayNames'; |
|
125 | - $printID = true; |
|
126 | - } |
|
113 | + if($input->getOption('group')) { |
|
114 | + $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
115 | + $getMethod = 'getGroups'; |
|
116 | + $printID = false; |
|
117 | + // convert the limit of groups to null. This will show all the groups available instead of |
|
118 | + // nothing, and will match the same behaviour the search for users has. |
|
119 | + if ($limit === 0) { |
|
120 | + $limit = null; |
|
121 | + } |
|
122 | + } else { |
|
123 | + $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig, \OC::$server->getNotificationManager()); |
|
124 | + $getMethod = 'getDisplayNames'; |
|
125 | + $printID = true; |
|
126 | + } |
|
127 | 127 | |
128 | - $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
129 | - foreach($result as $id => $name) { |
|
130 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
131 | - $output->writeln($line); |
|
132 | - } |
|
133 | - } |
|
128 | + $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
129 | + foreach($result as $id => $name) { |
|
130 | + $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
131 | + $output->writeln($line); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | } |
@@ -33,39 +33,39 @@ |
||
33 | 33 | use Symfony\Component\Console\Output\OutputInterface; |
34 | 34 | |
35 | 35 | class DeleteConfig extends Command { |
36 | - /** @var \OCA\User_LDAP\Helper */ |
|
37 | - protected $helper; |
|
36 | + /** @var \OCA\User_LDAP\Helper */ |
|
37 | + protected $helper; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param Helper $helper |
|
41 | - */ |
|
42 | - public function __construct(Helper $helper) { |
|
43 | - $this->helper = $helper; |
|
44 | - parent::__construct(); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @param Helper $helper |
|
41 | + */ |
|
42 | + public function __construct(Helper $helper) { |
|
43 | + $this->helper = $helper; |
|
44 | + parent::__construct(); |
|
45 | + } |
|
46 | 46 | |
47 | - protected function configure() { |
|
48 | - $this |
|
49 | - ->setName('ldap:delete-config') |
|
50 | - ->setDescription('deletes an existing LDAP configuration') |
|
51 | - ->addArgument( |
|
52 | - 'configID', |
|
53 | - InputArgument::REQUIRED, |
|
54 | - 'the configuration ID' |
|
55 | - ) |
|
56 | - ; |
|
57 | - } |
|
47 | + protected function configure() { |
|
48 | + $this |
|
49 | + ->setName('ldap:delete-config') |
|
50 | + ->setDescription('deletes an existing LDAP configuration') |
|
51 | + ->addArgument( |
|
52 | + 'configID', |
|
53 | + InputArgument::REQUIRED, |
|
54 | + 'the configuration ID' |
|
55 | + ) |
|
56 | + ; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
61 | - $configPrefix = $input->getArgument('configID'); |
|
60 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
61 | + $configPrefix = $input->getArgument('configID'); |
|
62 | 62 | |
63 | - $success = $this->helper->deleteServerConfiguration($configPrefix); |
|
63 | + $success = $this->helper->deleteServerConfiguration($configPrefix); |
|
64 | 64 | |
65 | - if($success) { |
|
66 | - $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
|
67 | - } else { |
|
68 | - $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
|
69 | - } |
|
70 | - } |
|
65 | + if($success) { |
|
66 | + $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
|
67 | + } else { |
|
68 | + $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | } |
@@ -62,7 +62,7 @@ |
||
62 | 62 | |
63 | 63 | $success = $this->helper->deleteServerConfiguration($configPrefix); |
64 | 64 | |
65 | - if($success) { |
|
65 | + if ($success) { |
|
66 | 66 | $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
67 | 67 | } else { |
68 | 68 | $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |