Completed
Push — master ( 842df4...8ec73e )
by
unknown
29:13
created
apps/user_ldap/lib/Controller/ConfigAPIController.php 1 patch
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -27,249 +27,249 @@  discard block
 block discarded – undo
27 27
 use Psr\Log\LoggerInterface;
28 28
 
29 29
 class ConfigAPIController extends OCSController {
30
-	public function __construct(
31
-		string $appName,
32
-		IRequest $request,
33
-		private Helper $ldapHelper,
34
-		private LoggerInterface $logger,
35
-		private ConnectionFactory $connectionFactory,
36
-		private IL10N $l,
37
-	) {
38
-		parent::__construct($appName, $request);
39
-	}
30
+    public function __construct(
31
+        string $appName,
32
+        IRequest $request,
33
+        private Helper $ldapHelper,
34
+        private LoggerInterface $logger,
35
+        private ConnectionFactory $connectionFactory,
36
+        private IL10N $l,
37
+    ) {
38
+        parent::__construct($appName, $request);
39
+    }
40 40
 
41
-	/**
42
-	 * Create a new (empty) configuration and return the resulting prefix
43
-	 *
44
-	 * @return DataResponse<Http::STATUS_OK, array{configID: string}, array{}>
45
-	 * @throws OCSException
46
-	 *
47
-	 * 200: Config created successfully
48
-	 */
49
-	#[AuthorizedAdminSetting(settings: Admin::class)]
50
-	#[ApiRoute(verb: 'POST', url: '/api/v1/config')]
51
-	public function create() {
52
-		try {
53
-			$configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
54
-			$configHolder = new Configuration($configPrefix);
55
-			$configHolder->ldapConfigurationActive = false;
56
-			$configHolder->saveConfiguration();
57
-		} catch (\Exception $e) {
58
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
59
-			throw new OCSException('An issue occurred when creating the new config.');
60
-		}
61
-		return new DataResponse(['configID' => $configPrefix]);
62
-	}
41
+    /**
42
+     * Create a new (empty) configuration and return the resulting prefix
43
+     *
44
+     * @return DataResponse<Http::STATUS_OK, array{configID: string}, array{}>
45
+     * @throws OCSException
46
+     *
47
+     * 200: Config created successfully
48
+     */
49
+    #[AuthorizedAdminSetting(settings: Admin::class)]
50
+    #[ApiRoute(verb: 'POST', url: '/api/v1/config')]
51
+    public function create() {
52
+        try {
53
+            $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
54
+            $configHolder = new Configuration($configPrefix);
55
+            $configHolder->ldapConfigurationActive = false;
56
+            $configHolder->saveConfiguration();
57
+        } catch (\Exception $e) {
58
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
59
+            throw new OCSException('An issue occurred when creating the new config.');
60
+        }
61
+        return new DataResponse(['configID' => $configPrefix]);
62
+    }
63 63
 
64
-	/**
65
-	 * Delete a LDAP configuration
66
-	 *
67
-	 * @param string $configID ID of the config
68
-	 * @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
69
-	 * @throws OCSException
70
-	 * @throws OCSNotFoundException Config not found
71
-	 *
72
-	 * 200: Config deleted successfully
73
-	 */
74
-	#[AuthorizedAdminSetting(settings: Admin::class)]
75
-	#[ApiRoute(verb: 'DELETE', url: '/api/v1/config/{configID}')]
76
-	public function delete($configID) {
77
-		try {
78
-			$this->ensureConfigIDExists($configID);
79
-			if (!$this->ldapHelper->deleteServerConfiguration($configID)) {
80
-				throw new OCSException('Could not delete configuration');
81
-			}
82
-		} catch (OCSException $e) {
83
-			throw $e;
84
-		} catch (\Exception $e) {
85
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
86
-			throw new OCSException('An issue occurred when deleting the config.');
87
-		}
64
+    /**
65
+     * Delete a LDAP configuration
66
+     *
67
+     * @param string $configID ID of the config
68
+     * @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
69
+     * @throws OCSException
70
+     * @throws OCSNotFoundException Config not found
71
+     *
72
+     * 200: Config deleted successfully
73
+     */
74
+    #[AuthorizedAdminSetting(settings: Admin::class)]
75
+    #[ApiRoute(verb: 'DELETE', url: '/api/v1/config/{configID}')]
76
+    public function delete($configID) {
77
+        try {
78
+            $this->ensureConfigIDExists($configID);
79
+            if (!$this->ldapHelper->deleteServerConfiguration($configID)) {
80
+                throw new OCSException('Could not delete configuration');
81
+            }
82
+        } catch (OCSException $e) {
83
+            throw $e;
84
+        } catch (\Exception $e) {
85
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
86
+            throw new OCSException('An issue occurred when deleting the config.');
87
+        }
88 88
 
89
-		return new DataResponse();
90
-	}
89
+        return new DataResponse();
90
+    }
91 91
 
92
-	/**
93
-	 * Modify a configuration
94
-	 *
95
-	 * @param string $configID ID of the config
96
-	 * @param array<string, mixed> $configData New config
97
-	 * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>
98
-	 * @throws OCSException
99
-	 * @throws OCSBadRequestException Modifying config is not possible
100
-	 * @throws OCSNotFoundException Config not found
101
-	 *
102
-	 * 200: Config returned
103
-	 */
104
-	#[AuthorizedAdminSetting(settings: Admin::class)]
105
-	#[ApiRoute(verb: 'PUT', url: '/api/v1/config/{configID}')]
106
-	public function modify($configID, $configData) {
107
-		try {
108
-			$this->ensureConfigIDExists($configID);
92
+    /**
93
+     * Modify a configuration
94
+     *
95
+     * @param string $configID ID of the config
96
+     * @param array<string, mixed> $configData New config
97
+     * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>
98
+     * @throws OCSException
99
+     * @throws OCSBadRequestException Modifying config is not possible
100
+     * @throws OCSNotFoundException Config not found
101
+     *
102
+     * 200: Config returned
103
+     */
104
+    #[AuthorizedAdminSetting(settings: Admin::class)]
105
+    #[ApiRoute(verb: 'PUT', url: '/api/v1/config/{configID}')]
106
+    public function modify($configID, $configData) {
107
+        try {
108
+            $this->ensureConfigIDExists($configID);
109 109
 
110
-			if (!is_array($configData)) {
111
-				throw new OCSBadRequestException('configData is not properly set');
112
-			}
110
+            if (!is_array($configData)) {
111
+                throw new OCSBadRequestException('configData is not properly set');
112
+            }
113 113
 
114
-			$configuration = new Configuration($configID);
115
-			$configKeys = $configuration->getConfigTranslationArray();
114
+            $configuration = new Configuration($configID);
115
+            $configKeys = $configuration->getConfigTranslationArray();
116 116
 
117
-			foreach ($configKeys as $i => $key) {
118
-				if (isset($configData[$key])) {
119
-					$configuration->$key = $configData[$key];
120
-				}
121
-			}
117
+            foreach ($configKeys as $i => $key) {
118
+                if (isset($configData[$key])) {
119
+                    $configuration->$key = $configData[$key];
120
+                }
121
+            }
122 122
 
123
-			$configuration->saveConfiguration();
124
-			$this->connectionFactory->get($configID)->clearCache();
125
-		} catch (OCSException $e) {
126
-			throw $e;
127
-		} catch (\Exception $e) {
128
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
129
-			throw new OCSException('An issue occurred when modifying the config.');
130
-		}
123
+            $configuration->saveConfiguration();
124
+            $this->connectionFactory->get($configID)->clearCache();
125
+        } catch (OCSException $e) {
126
+            throw $e;
127
+        } catch (\Exception $e) {
128
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
129
+            throw new OCSException('An issue occurred when modifying the config.');
130
+        }
131 131
 
132
-		return $this->show($configID, false);
133
-	}
132
+        return $this->show($configID, false);
133
+    }
134 134
 
135
-	/**
136
-	 * Get a configuration
137
-	 *
138
-	 * Output can look like this:
139
-	 * <?xml version="1.0"?>
140
-	 * <ocs>
141
-	 *   <meta>
142
-	 *     <status>ok</status>
143
-	 *     <statuscode>200</statuscode>
144
-	 *     <message>OK</message>
145
-	 *   </meta>
146
-	 *   <data>
147
-	 *     <ldapHost>ldaps://my.ldap.server</ldapHost>
148
-	 *     <ldapPort>7770</ldapPort>
149
-	 *     <ldapBackupHost></ldapBackupHost>
150
-	 *     <ldapBackupPort></ldapBackupPort>
151
-	 *     <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase>
152
-	 *     <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers>
153
-	 *     <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups>
154
-	 *     <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName>
155
-	 *     <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword>
156
-	 *     <ldapTLS>1</ldapTLS>
157
-	 *     <turnOffCertCheck>0</turnOffCertCheck>
158
-	 *     <ldapIgnoreNamingRules/>
159
-	 *     <ldapUserDisplayName>displayname</ldapUserDisplayName>
160
-	 *     <ldapUserDisplayName2>uid</ldapUserDisplayName2>
161
-	 *     <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass>
162
-	 *     <ldapUserFilterGroups></ldapUserFilterGroups>
163
-	 *     <ldapUserFilter>(&amp;(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter>
164
-	 *     <ldapUserFilterMode>1</ldapUserFilterMode>
165
-	 *     <ldapGroupFilter>(&amp;(|(objectclass=nextcloudGroup)))</ldapGroupFilter>
166
-	 *     <ldapGroupFilterMode>0</ldapGroupFilterMode>
167
-	 *     <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass>
168
-	 *     <ldapGroupFilterGroups></ldapGroupFilterGroups>
169
-	 *     <ldapGroupDisplayName>cn</ldapGroupDisplayName>
170
-	 *     <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr>
171
-	 *     <ldapLoginFilter>(&amp;(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter>
172
-	 *     <ldapLoginFilterMode>0</ldapLoginFilterMode>
173
-	 *     <ldapLoginFilterEmail>0</ldapLoginFilterEmail>
174
-	 *     <ldapLoginFilterUsername>1</ldapLoginFilterUsername>
175
-	 *     <ldapLoginFilterAttributes></ldapLoginFilterAttributes>
176
-	 *     <ldapQuotaAttribute></ldapQuotaAttribute>
177
-	 *     <ldapQuotaDefault></ldapQuotaDefault>
178
-	 *     <ldapEmailAttribute>mail</ldapEmailAttribute>
179
-	 *     <ldapCacheTTL>20</ldapCacheTTL>
180
-	 *     <ldapUuidUserAttribute>auto</ldapUuidUserAttribute>
181
-	 *     <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute>
182
-	 *     <ldapOverrideMainServer></ldapOverrideMainServer>
183
-	 *     <ldapConfigurationActive>1</ldapConfigurationActive>
184
-	 *     <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch>
185
-	 *     <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch>
186
-	 *     <ldapExperiencedAdmin>0</ldapExperiencedAdmin>
187
-	 *     <homeFolderNamingRule></homeFolderNamingRule>
188
-	 *     <hasMemberOfFilterSupport></hasMemberOfFilterSupport>
189
-	 *     <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership>
190
-	 *     <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr>
191
-	 *     <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr>
192
-	 *     <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr>
193
-	 *     <lastJpegPhotoLookup>0</lastJpegPhotoLookup>
194
-	 *     <ldapNestedGroups>0</ldapNestedGroups>
195
-	 *     <ldapPagingSize>500</ldapPagingSize>
196
-	 *     <turnOnPasswordChange>1</turnOnPasswordChange>
197
-	 *     <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL>
198
-	 *   </data>
199
-	 * </ocs>
200
-	 *
201
-	 * @param string $configID ID of the config
202
-	 * @param bool $showPassword Whether to show the password
203
-	 * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>
204
-	 * @throws OCSException
205
-	 * @throws OCSNotFoundException Config not found
206
-	 *
207
-	 * 200: Config returned
208
-	 */
209
-	#[AuthorizedAdminSetting(settings: Admin::class)]
210
-	#[ApiRoute(verb: 'GET', url: '/api/v1/config/{configID}')]
211
-	public function show($configID, $showPassword = false) {
212
-		try {
213
-			$this->ensureConfigIDExists($configID);
135
+    /**
136
+     * Get a configuration
137
+     *
138
+     * Output can look like this:
139
+     * <?xml version="1.0"?>
140
+     * <ocs>
141
+     *   <meta>
142
+     *     <status>ok</status>
143
+     *     <statuscode>200</statuscode>
144
+     *     <message>OK</message>
145
+     *   </meta>
146
+     *   <data>
147
+     *     <ldapHost>ldaps://my.ldap.server</ldapHost>
148
+     *     <ldapPort>7770</ldapPort>
149
+     *     <ldapBackupHost></ldapBackupHost>
150
+     *     <ldapBackupPort></ldapBackupPort>
151
+     *     <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase>
152
+     *     <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers>
153
+     *     <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups>
154
+     *     <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName>
155
+     *     <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword>
156
+     *     <ldapTLS>1</ldapTLS>
157
+     *     <turnOffCertCheck>0</turnOffCertCheck>
158
+     *     <ldapIgnoreNamingRules/>
159
+     *     <ldapUserDisplayName>displayname</ldapUserDisplayName>
160
+     *     <ldapUserDisplayName2>uid</ldapUserDisplayName2>
161
+     *     <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass>
162
+     *     <ldapUserFilterGroups></ldapUserFilterGroups>
163
+     *     <ldapUserFilter>(&amp;(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter>
164
+     *     <ldapUserFilterMode>1</ldapUserFilterMode>
165
+     *     <ldapGroupFilter>(&amp;(|(objectclass=nextcloudGroup)))</ldapGroupFilter>
166
+     *     <ldapGroupFilterMode>0</ldapGroupFilterMode>
167
+     *     <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass>
168
+     *     <ldapGroupFilterGroups></ldapGroupFilterGroups>
169
+     *     <ldapGroupDisplayName>cn</ldapGroupDisplayName>
170
+     *     <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr>
171
+     *     <ldapLoginFilter>(&amp;(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter>
172
+     *     <ldapLoginFilterMode>0</ldapLoginFilterMode>
173
+     *     <ldapLoginFilterEmail>0</ldapLoginFilterEmail>
174
+     *     <ldapLoginFilterUsername>1</ldapLoginFilterUsername>
175
+     *     <ldapLoginFilterAttributes></ldapLoginFilterAttributes>
176
+     *     <ldapQuotaAttribute></ldapQuotaAttribute>
177
+     *     <ldapQuotaDefault></ldapQuotaDefault>
178
+     *     <ldapEmailAttribute>mail</ldapEmailAttribute>
179
+     *     <ldapCacheTTL>20</ldapCacheTTL>
180
+     *     <ldapUuidUserAttribute>auto</ldapUuidUserAttribute>
181
+     *     <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute>
182
+     *     <ldapOverrideMainServer></ldapOverrideMainServer>
183
+     *     <ldapConfigurationActive>1</ldapConfigurationActive>
184
+     *     <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch>
185
+     *     <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch>
186
+     *     <ldapExperiencedAdmin>0</ldapExperiencedAdmin>
187
+     *     <homeFolderNamingRule></homeFolderNamingRule>
188
+     *     <hasMemberOfFilterSupport></hasMemberOfFilterSupport>
189
+     *     <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership>
190
+     *     <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr>
191
+     *     <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr>
192
+     *     <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr>
193
+     *     <lastJpegPhotoLookup>0</lastJpegPhotoLookup>
194
+     *     <ldapNestedGroups>0</ldapNestedGroups>
195
+     *     <ldapPagingSize>500</ldapPagingSize>
196
+     *     <turnOnPasswordChange>1</turnOnPasswordChange>
197
+     *     <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL>
198
+     *   </data>
199
+     * </ocs>
200
+     *
201
+     * @param string $configID ID of the config
202
+     * @param bool $showPassword Whether to show the password
203
+     * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>
204
+     * @throws OCSException
205
+     * @throws OCSNotFoundException Config not found
206
+     *
207
+     * 200: Config returned
208
+     */
209
+    #[AuthorizedAdminSetting(settings: Admin::class)]
210
+    #[ApiRoute(verb: 'GET', url: '/api/v1/config/{configID}')]
211
+    public function show($configID, $showPassword = false) {
212
+        try {
213
+            $this->ensureConfigIDExists($configID);
214 214
 
215
-			$config = new Configuration($configID);
216
-			$data = $config->getConfiguration();
217
-			if (!$showPassword) {
218
-				$data['ldapAgentPassword'] = '***';
219
-			}
220
-			foreach ($data as $key => $value) {
221
-				if (is_array($value)) {
222
-					$value = implode(';', $value);
223
-					$data[$key] = $value;
224
-				}
225
-			}
226
-		} catch (OCSException $e) {
227
-			throw $e;
228
-		} catch (\Exception $e) {
229
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
230
-			throw new OCSException('An issue occurred when modifying the config.');
231
-		}
215
+            $config = new Configuration($configID);
216
+            $data = $config->getConfiguration();
217
+            if (!$showPassword) {
218
+                $data['ldapAgentPassword'] = '***';
219
+            }
220
+            foreach ($data as $key => $value) {
221
+                if (is_array($value)) {
222
+                    $value = implode(';', $value);
223
+                    $data[$key] = $value;
224
+                }
225
+            }
226
+        } catch (OCSException $e) {
227
+            throw $e;
228
+        } catch (\Exception $e) {
229
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
230
+            throw new OCSException('An issue occurred when modifying the config.');
231
+        }
232 232
 
233
-		return new DataResponse($data);
234
-	}
233
+        return new DataResponse($data);
234
+    }
235 235
 
236
-	/**
237
-	 * Test a configuration
238
-	 *
239
-	 * @param string $configID ID of the LDAP config
240
-	 * @return DataResponse<Http::STATUS_OK, array{success:bool,message:string}, array{}>
241
-	 * @throws OCSException An unexpected error happened
242
-	 * @throws OCSNotFoundException Config not found
243
-	 *
244
-	 * 200: Test was run and results are returned
245
-	 */
246
-	#[AuthorizedAdminSetting(settings: Admin::class)]
247
-	#[ApiRoute(verb: 'POST', url: '/api/v1/config/{configID}/test')]
248
-	public function testConfiguration(string $configID) {
249
-		try {
250
-			$this->ensureConfigIDExists($configID);
251
-			$connection = $this->connectionFactory->get($configID);
252
-			$conf = $connection->getConfiguration();
253
-			if ($conf['ldap_configuration_active'] !== '1') {
254
-				//needs to be true, otherwise it will also fail with an irritating message
255
-				$conf['ldap_configuration_active'] = '1';
256
-			}
257
-			try {
258
-				$connection->setConfiguration($conf, throw: true);
259
-			} catch (ConfigurationIssueException $e) {
260
-				return new DataResponse([
261
-					'success' => false,
262
-					'message' => $this->l->t('Invalid configuration: %s', $e->getHint()),
263
-				]);
264
-			}
265
-			// Configuration is okay
266
-			if (!$connection->bind()) {
267
-				return new DataResponse([
268
-					'success' => false,
269
-					'message' => $this->l->t('Valid configuration, but binding failed. Please check the server settings and credentials.'),
270
-				]);
271
-			}
272
-			/*
236
+    /**
237
+     * Test a configuration
238
+     *
239
+     * @param string $configID ID of the LDAP config
240
+     * @return DataResponse<Http::STATUS_OK, array{success:bool,message:string}, array{}>
241
+     * @throws OCSException An unexpected error happened
242
+     * @throws OCSNotFoundException Config not found
243
+     *
244
+     * 200: Test was run and results are returned
245
+     */
246
+    #[AuthorizedAdminSetting(settings: Admin::class)]
247
+    #[ApiRoute(verb: 'POST', url: '/api/v1/config/{configID}/test')]
248
+    public function testConfiguration(string $configID) {
249
+        try {
250
+            $this->ensureConfigIDExists($configID);
251
+            $connection = $this->connectionFactory->get($configID);
252
+            $conf = $connection->getConfiguration();
253
+            if ($conf['ldap_configuration_active'] !== '1') {
254
+                //needs to be true, otherwise it will also fail with an irritating message
255
+                $conf['ldap_configuration_active'] = '1';
256
+            }
257
+            try {
258
+                $connection->setConfiguration($conf, throw: true);
259
+            } catch (ConfigurationIssueException $e) {
260
+                return new DataResponse([
261
+                    'success' => false,
262
+                    'message' => $this->l->t('Invalid configuration: %s', $e->getHint()),
263
+                ]);
264
+            }
265
+            // Configuration is okay
266
+            if (!$connection->bind()) {
267
+                return new DataResponse([
268
+                    'success' => false,
269
+                    'message' => $this->l->t('Valid configuration, but binding failed. Please check the server settings and credentials.'),
270
+                ]);
271
+            }
272
+            /*
273 273
 			* This shiny if block is an ugly hack to find out whether anonymous
274 274
 			* bind is possible on AD or not. Because AD happily and constantly
275 275
 			* replies with success to any anonymous bind request, we need to
@@ -278,69 +278,69 @@  discard block
 block discarded – undo
278 278
 			* exception by the LDAP wrapper. We catch this. Other cases may
279 279
 			* pass (like e.g. expected syntax error).
280 280
 			*/
281
-			try {
282
-				$ldapWrapper = Server::get(ILDAPWrapper::class);
283
-				$ldapWrapper->read($connection->getConnectionResource(), '', 'objectClass=*', ['dn']);
284
-			} catch (\Exception $e) {
285
-				if ($e->getCode() === 1) {
286
-					return new DataResponse([
287
-						'success' => false,
288
-						'message' => $this->l->t('Invalid configuration: Anonymous binding is not allowed.'),
289
-					]);
290
-				}
291
-			}
292
-			return new DataResponse([
293
-				'success' => true,
294
-				'message' => $this->l->t('Valid configuration, connection established!'),
295
-			]);
296
-		} catch (OCSException $e) {
297
-			throw $e;
298
-		} catch (\Exception $e) {
299
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
300
-			throw new OCSException('An issue occurred when testing the config.');
301
-		}
302
-	}
281
+            try {
282
+                $ldapWrapper = Server::get(ILDAPWrapper::class);
283
+                $ldapWrapper->read($connection->getConnectionResource(), '', 'objectClass=*', ['dn']);
284
+            } catch (\Exception $e) {
285
+                if ($e->getCode() === 1) {
286
+                    return new DataResponse([
287
+                        'success' => false,
288
+                        'message' => $this->l->t('Invalid configuration: Anonymous binding is not allowed.'),
289
+                    ]);
290
+                }
291
+            }
292
+            return new DataResponse([
293
+                'success' => true,
294
+                'message' => $this->l->t('Valid configuration, connection established!'),
295
+            ]);
296
+        } catch (OCSException $e) {
297
+            throw $e;
298
+        } catch (\Exception $e) {
299
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
300
+            throw new OCSException('An issue occurred when testing the config.');
301
+        }
302
+    }
303 303
 
304
-	/**
305
-	 * Copy a configuration
306
-	 *
307
-	 * @param string $configID ID of the LDAP config
308
-	 * @return DataResponse<Http::STATUS_OK, array{configID:string}, array{}>
309
-	 * @throws OCSException An unexpected error happened
310
-	 * @throws OCSNotFoundException Config not found
311
-	 *
312
-	 * 200: Config was copied, new configID was returned
313
-	 */
314
-	#[AuthorizedAdminSetting(settings: Admin::class)]
315
-	#[ApiRoute(verb: 'POST', url: '/api/v1/config/{configID}/copy')]
316
-	public function copyConfiguration(string $configID) {
317
-		try {
318
-			$this->ensureConfigIDExists($configID);
319
-			$configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
320
-			$newConfig = new Configuration($configPrefix, false);
321
-			$originalConfig = new Configuration($configID);
322
-			$newConfig->setConfiguration($originalConfig->getConfiguration());
323
-			$newConfig->saveConfiguration();
324
-			return new DataResponse(['configID' => $configPrefix]);
325
-		} catch (OCSException $e) {
326
-			throw $e;
327
-		} catch (\Exception $e) {
328
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
329
-			throw new OCSException('An issue occurred when creating the new config.');
330
-		}
331
-	}
304
+    /**
305
+     * Copy a configuration
306
+     *
307
+     * @param string $configID ID of the LDAP config
308
+     * @return DataResponse<Http::STATUS_OK, array{configID:string}, array{}>
309
+     * @throws OCSException An unexpected error happened
310
+     * @throws OCSNotFoundException Config not found
311
+     *
312
+     * 200: Config was copied, new configID was returned
313
+     */
314
+    #[AuthorizedAdminSetting(settings: Admin::class)]
315
+    #[ApiRoute(verb: 'POST', url: '/api/v1/config/{configID}/copy')]
316
+    public function copyConfiguration(string $configID) {
317
+        try {
318
+            $this->ensureConfigIDExists($configID);
319
+            $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
320
+            $newConfig = new Configuration($configPrefix, false);
321
+            $originalConfig = new Configuration($configID);
322
+            $newConfig->setConfiguration($originalConfig->getConfiguration());
323
+            $newConfig->saveConfiguration();
324
+            return new DataResponse(['configID' => $configPrefix]);
325
+        } catch (OCSException $e) {
326
+            throw $e;
327
+        } catch (\Exception $e) {
328
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
329
+            throw new OCSException('An issue occurred when creating the new config.');
330
+        }
331
+    }
332 332
 
333
-	/**
334
-	 * If the given config ID is not available, an exception is thrown
335
-	 *
336
-	 * @param string $configID
337
-	 * @throws OCSNotFoundException
338
-	 */
339
-	#[AuthorizedAdminSetting(settings: Admin::class)]
340
-	private function ensureConfigIDExists($configID): void {
341
-		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
342
-		if (!in_array($configID, $prefixes, true)) {
343
-			throw new OCSNotFoundException('Config ID not found');
344
-		}
345
-	}
333
+    /**
334
+     * If the given config ID is not available, an exception is thrown
335
+     *
336
+     * @param string $configID
337
+     * @throws OCSNotFoundException
338
+     */
339
+    #[AuthorizedAdminSetting(settings: Admin::class)]
340
+    private function ensureConfigIDExists($configID): void {
341
+        $prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
342
+        if (!in_array($configID, $prefixes, true)) {
343
+            throw new OCSNotFoundException('Config ID not found');
344
+        }
345
+    }
346 346
 }
Please login to merge, or discard this patch.