@@ -27,235 +27,235 @@ |
||
| 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 | - CapabilitiesManager $capabilitiesManager, |
|
| 34 | - IUserSession $userSession, |
|
| 35 | - IUserManager $userManager, |
|
| 36 | - Manager $keyManager, |
|
| 37 | - ServerVersion $serverVersion, |
|
| 38 | - private Helper $ldapHelper, |
|
| 39 | - private LoggerInterface $logger, |
|
| 40 | - private ConnectionFactory $connectionFactory, |
|
| 41 | - ) { |
|
| 42 | - parent::__construct( |
|
| 43 | - $appName, |
|
| 44 | - $request, |
|
| 45 | - $capabilitiesManager, |
|
| 46 | - $userSession, |
|
| 47 | - $userManager, |
|
| 48 | - $keyManager, |
|
| 49 | - $serverVersion, |
|
| 50 | - ); |
|
| 51 | - } |
|
| 30 | + public function __construct( |
|
| 31 | + string $appName, |
|
| 32 | + IRequest $request, |
|
| 33 | + CapabilitiesManager $capabilitiesManager, |
|
| 34 | + IUserSession $userSession, |
|
| 35 | + IUserManager $userManager, |
|
| 36 | + Manager $keyManager, |
|
| 37 | + ServerVersion $serverVersion, |
|
| 38 | + private Helper $ldapHelper, |
|
| 39 | + private LoggerInterface $logger, |
|
| 40 | + private ConnectionFactory $connectionFactory, |
|
| 41 | + ) { |
|
| 42 | + parent::__construct( |
|
| 43 | + $appName, |
|
| 44 | + $request, |
|
| 45 | + $capabilitiesManager, |
|
| 46 | + $userSession, |
|
| 47 | + $userManager, |
|
| 48 | + $keyManager, |
|
| 49 | + $serverVersion, |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Create a new (empty) configuration and return the resulting prefix |
|
| 55 | - * |
|
| 56 | - * @return DataResponse<Http::STATUS_OK, array{configID: string}, array{}> |
|
| 57 | - * @throws OCSException |
|
| 58 | - * |
|
| 59 | - * 200: Config created successfully |
|
| 60 | - */ |
|
| 61 | - #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 62 | - #[ApiRoute(verb: 'POST', url: '/api/v1/config')] |
|
| 63 | - public function create() { |
|
| 64 | - try { |
|
| 65 | - $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix(); |
|
| 66 | - $configHolder = new Configuration($configPrefix); |
|
| 67 | - $configHolder->ldapConfigurationActive = false; |
|
| 68 | - $configHolder->saveConfiguration(); |
|
| 69 | - } catch (\Exception $e) { |
|
| 70 | - $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
| 71 | - throw new OCSException('An issue occurred when creating the new config.'); |
|
| 72 | - } |
|
| 73 | - return new DataResponse(['configID' => $configPrefix]); |
|
| 74 | - } |
|
| 53 | + /** |
|
| 54 | + * Create a new (empty) configuration and return the resulting prefix |
|
| 55 | + * |
|
| 56 | + * @return DataResponse<Http::STATUS_OK, array{configID: string}, array{}> |
|
| 57 | + * @throws OCSException |
|
| 58 | + * |
|
| 59 | + * 200: Config created successfully |
|
| 60 | + */ |
|
| 61 | + #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 62 | + #[ApiRoute(verb: 'POST', url: '/api/v1/config')] |
|
| 63 | + public function create() { |
|
| 64 | + try { |
|
| 65 | + $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix(); |
|
| 66 | + $configHolder = new Configuration($configPrefix); |
|
| 67 | + $configHolder->ldapConfigurationActive = false; |
|
| 68 | + $configHolder->saveConfiguration(); |
|
| 69 | + } catch (\Exception $e) { |
|
| 70 | + $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
| 71 | + throw new OCSException('An issue occurred when creating the new config.'); |
|
| 72 | + } |
|
| 73 | + return new DataResponse(['configID' => $configPrefix]); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Delete a LDAP configuration |
|
| 78 | - * |
|
| 79 | - * @param string $configID ID of the config |
|
| 80 | - * @return DataResponse<Http::STATUS_OK, list<empty>, array{}> |
|
| 81 | - * @throws OCSException |
|
| 82 | - * @throws OCSNotFoundException Config not found |
|
| 83 | - * |
|
| 84 | - * 200: Config deleted successfully |
|
| 85 | - */ |
|
| 86 | - #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 87 | - #[ApiRoute(verb: 'DELETE', url: '/api/v1/config/{configID}')] |
|
| 88 | - public function delete($configID) { |
|
| 89 | - try { |
|
| 90 | - $this->ensureConfigIDExists($configID); |
|
| 91 | - if (!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
| 92 | - throw new OCSException('Could not delete configuration'); |
|
| 93 | - } |
|
| 94 | - } catch (OCSException $e) { |
|
| 95 | - throw $e; |
|
| 96 | - } catch (\Exception $e) { |
|
| 97 | - $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
| 98 | - throw new OCSException('An issue occurred when deleting the config.'); |
|
| 99 | - } |
|
| 76 | + /** |
|
| 77 | + * Delete a LDAP configuration |
|
| 78 | + * |
|
| 79 | + * @param string $configID ID of the config |
|
| 80 | + * @return DataResponse<Http::STATUS_OK, list<empty>, array{}> |
|
| 81 | + * @throws OCSException |
|
| 82 | + * @throws OCSNotFoundException Config not found |
|
| 83 | + * |
|
| 84 | + * 200: Config deleted successfully |
|
| 85 | + */ |
|
| 86 | + #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 87 | + #[ApiRoute(verb: 'DELETE', url: '/api/v1/config/{configID}')] |
|
| 88 | + public function delete($configID) { |
|
| 89 | + try { |
|
| 90 | + $this->ensureConfigIDExists($configID); |
|
| 91 | + if (!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
| 92 | + throw new OCSException('Could not delete configuration'); |
|
| 93 | + } |
|
| 94 | + } catch (OCSException $e) { |
|
| 95 | + throw $e; |
|
| 96 | + } catch (\Exception $e) { |
|
| 97 | + $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
| 98 | + throw new OCSException('An issue occurred when deleting the config.'); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return new DataResponse(); |
|
| 102 | - } |
|
| 101 | + return new DataResponse(); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Modify a configuration |
|
| 106 | - * |
|
| 107 | - * @param string $configID ID of the config |
|
| 108 | - * @param array<string, mixed> $configData New config |
|
| 109 | - * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}> |
|
| 110 | - * @throws OCSException |
|
| 111 | - * @throws OCSBadRequestException Modifying config is not possible |
|
| 112 | - * @throws OCSNotFoundException Config not found |
|
| 113 | - * |
|
| 114 | - * 200: Config returned |
|
| 115 | - */ |
|
| 116 | - #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 117 | - #[ApiRoute(verb: 'PUT', url: '/api/v1/config/{configID}')] |
|
| 118 | - public function modify($configID, $configData) { |
|
| 119 | - try { |
|
| 120 | - $this->ensureConfigIDExists($configID); |
|
| 104 | + /** |
|
| 105 | + * Modify a configuration |
|
| 106 | + * |
|
| 107 | + * @param string $configID ID of the config |
|
| 108 | + * @param array<string, mixed> $configData New config |
|
| 109 | + * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}> |
|
| 110 | + * @throws OCSException |
|
| 111 | + * @throws OCSBadRequestException Modifying config is not possible |
|
| 112 | + * @throws OCSNotFoundException Config not found |
|
| 113 | + * |
|
| 114 | + * 200: Config returned |
|
| 115 | + */ |
|
| 116 | + #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 117 | + #[ApiRoute(verb: 'PUT', url: '/api/v1/config/{configID}')] |
|
| 118 | + public function modify($configID, $configData) { |
|
| 119 | + try { |
|
| 120 | + $this->ensureConfigIDExists($configID); |
|
| 121 | 121 | |
| 122 | - if (!is_array($configData)) { |
|
| 123 | - throw new OCSBadRequestException('configData is not properly set'); |
|
| 124 | - } |
|
| 122 | + if (!is_array($configData)) { |
|
| 123 | + throw new OCSBadRequestException('configData is not properly set'); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $configuration = new Configuration($configID); |
|
| 127 | - $configKeys = $configuration->getConfigTranslationArray(); |
|
| 126 | + $configuration = new Configuration($configID); |
|
| 127 | + $configKeys = $configuration->getConfigTranslationArray(); |
|
| 128 | 128 | |
| 129 | - foreach ($configKeys as $i => $key) { |
|
| 130 | - if (isset($configData[$key])) { |
|
| 131 | - $configuration->$key = $configData[$key]; |
|
| 132 | - } |
|
| 133 | - } |
|
| 129 | + foreach ($configKeys as $i => $key) { |
|
| 130 | + if (isset($configData[$key])) { |
|
| 131 | + $configuration->$key = $configData[$key]; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - $configuration->saveConfiguration(); |
|
| 136 | - $this->connectionFactory->get($configID)->clearCache(); |
|
| 137 | - } catch (OCSException $e) { |
|
| 138 | - throw $e; |
|
| 139 | - } catch (\Exception $e) { |
|
| 140 | - $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
| 141 | - throw new OCSException('An issue occurred when modifying the config.'); |
|
| 142 | - } |
|
| 135 | + $configuration->saveConfiguration(); |
|
| 136 | + $this->connectionFactory->get($configID)->clearCache(); |
|
| 137 | + } catch (OCSException $e) { |
|
| 138 | + throw $e; |
|
| 139 | + } catch (\Exception $e) { |
|
| 140 | + $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
| 141 | + throw new OCSException('An issue occurred when modifying the config.'); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - return $this->show($configID, false); |
|
| 145 | - } |
|
| 144 | + return $this->show($configID, false); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Get a configuration |
|
| 149 | - * |
|
| 150 | - * Output can look like this: |
|
| 151 | - * <?xml version="1.0"?> |
|
| 152 | - * <ocs> |
|
| 153 | - * <meta> |
|
| 154 | - * <status>ok</status> |
|
| 155 | - * <statuscode>200</statuscode> |
|
| 156 | - * <message>OK</message> |
|
| 157 | - * </meta> |
|
| 158 | - * <data> |
|
| 159 | - * <ldapHost>ldaps://my.ldap.server</ldapHost> |
|
| 160 | - * <ldapPort>7770</ldapPort> |
|
| 161 | - * <ldapBackupHost></ldapBackupHost> |
|
| 162 | - * <ldapBackupPort></ldapBackupPort> |
|
| 163 | - * <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase> |
|
| 164 | - * <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers> |
|
| 165 | - * <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups> |
|
| 166 | - * <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName> |
|
| 167 | - * <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword> |
|
| 168 | - * <ldapTLS>1</ldapTLS> |
|
| 169 | - * <turnOffCertCheck>0</turnOffCertCheck> |
|
| 170 | - * <ldapIgnoreNamingRules/> |
|
| 171 | - * <ldapUserDisplayName>displayname</ldapUserDisplayName> |
|
| 172 | - * <ldapUserDisplayName2>uid</ldapUserDisplayName2> |
|
| 173 | - * <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass> |
|
| 174 | - * <ldapUserFilterGroups></ldapUserFilterGroups> |
|
| 175 | - * <ldapUserFilter>(&(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter> |
|
| 176 | - * <ldapUserFilterMode>1</ldapUserFilterMode> |
|
| 177 | - * <ldapGroupFilter>(&(|(objectclass=nextcloudGroup)))</ldapGroupFilter> |
|
| 178 | - * <ldapGroupFilterMode>0</ldapGroupFilterMode> |
|
| 179 | - * <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass> |
|
| 180 | - * <ldapGroupFilterGroups></ldapGroupFilterGroups> |
|
| 181 | - * <ldapGroupDisplayName>cn</ldapGroupDisplayName> |
|
| 182 | - * <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr> |
|
| 183 | - * <ldapLoginFilter>(&(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter> |
|
| 184 | - * <ldapLoginFilterMode>0</ldapLoginFilterMode> |
|
| 185 | - * <ldapLoginFilterEmail>0</ldapLoginFilterEmail> |
|
| 186 | - * <ldapLoginFilterUsername>1</ldapLoginFilterUsername> |
|
| 187 | - * <ldapLoginFilterAttributes></ldapLoginFilterAttributes> |
|
| 188 | - * <ldapQuotaAttribute></ldapQuotaAttribute> |
|
| 189 | - * <ldapQuotaDefault></ldapQuotaDefault> |
|
| 190 | - * <ldapEmailAttribute>mail</ldapEmailAttribute> |
|
| 191 | - * <ldapCacheTTL>20</ldapCacheTTL> |
|
| 192 | - * <ldapUuidUserAttribute>auto</ldapUuidUserAttribute> |
|
| 193 | - * <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute> |
|
| 194 | - * <ldapOverrideMainServer></ldapOverrideMainServer> |
|
| 195 | - * <ldapConfigurationActive>1</ldapConfigurationActive> |
|
| 196 | - * <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch> |
|
| 197 | - * <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch> |
|
| 198 | - * <ldapExperiencedAdmin>0</ldapExperiencedAdmin> |
|
| 199 | - * <homeFolderNamingRule></homeFolderNamingRule> |
|
| 200 | - * <hasMemberOfFilterSupport></hasMemberOfFilterSupport> |
|
| 201 | - * <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership> |
|
| 202 | - * <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr> |
|
| 203 | - * <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr> |
|
| 204 | - * <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr> |
|
| 205 | - * <lastJpegPhotoLookup>0</lastJpegPhotoLookup> |
|
| 206 | - * <ldapNestedGroups>0</ldapNestedGroups> |
|
| 207 | - * <ldapPagingSize>500</ldapPagingSize> |
|
| 208 | - * <turnOnPasswordChange>1</turnOnPasswordChange> |
|
| 209 | - * <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL> |
|
| 210 | - * </data> |
|
| 211 | - * </ocs> |
|
| 212 | - * |
|
| 213 | - * @param string $configID ID of the config |
|
| 214 | - * @param bool $showPassword Whether to show the password |
|
| 215 | - * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}> |
|
| 216 | - * @throws OCSException |
|
| 217 | - * @throws OCSNotFoundException Config not found |
|
| 218 | - * |
|
| 219 | - * 200: Config returned |
|
| 220 | - */ |
|
| 221 | - #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 222 | - #[ApiRoute(verb: 'GET', url: '/api/v1/config/{configID}')] |
|
| 223 | - public function show($configID, $showPassword = false) { |
|
| 224 | - try { |
|
| 225 | - $this->ensureConfigIDExists($configID); |
|
| 147 | + /** |
|
| 148 | + * Get a configuration |
|
| 149 | + * |
|
| 150 | + * Output can look like this: |
|
| 151 | + * <?xml version="1.0"?> |
|
| 152 | + * <ocs> |
|
| 153 | + * <meta> |
|
| 154 | + * <status>ok</status> |
|
| 155 | + * <statuscode>200</statuscode> |
|
| 156 | + * <message>OK</message> |
|
| 157 | + * </meta> |
|
| 158 | + * <data> |
|
| 159 | + * <ldapHost>ldaps://my.ldap.server</ldapHost> |
|
| 160 | + * <ldapPort>7770</ldapPort> |
|
| 161 | + * <ldapBackupHost></ldapBackupHost> |
|
| 162 | + * <ldapBackupPort></ldapBackupPort> |
|
| 163 | + * <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase> |
|
| 164 | + * <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers> |
|
| 165 | + * <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups> |
|
| 166 | + * <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName> |
|
| 167 | + * <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword> |
|
| 168 | + * <ldapTLS>1</ldapTLS> |
|
| 169 | + * <turnOffCertCheck>0</turnOffCertCheck> |
|
| 170 | + * <ldapIgnoreNamingRules/> |
|
| 171 | + * <ldapUserDisplayName>displayname</ldapUserDisplayName> |
|
| 172 | + * <ldapUserDisplayName2>uid</ldapUserDisplayName2> |
|
| 173 | + * <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass> |
|
| 174 | + * <ldapUserFilterGroups></ldapUserFilterGroups> |
|
| 175 | + * <ldapUserFilter>(&(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter> |
|
| 176 | + * <ldapUserFilterMode>1</ldapUserFilterMode> |
|
| 177 | + * <ldapGroupFilter>(&(|(objectclass=nextcloudGroup)))</ldapGroupFilter> |
|
| 178 | + * <ldapGroupFilterMode>0</ldapGroupFilterMode> |
|
| 179 | + * <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass> |
|
| 180 | + * <ldapGroupFilterGroups></ldapGroupFilterGroups> |
|
| 181 | + * <ldapGroupDisplayName>cn</ldapGroupDisplayName> |
|
| 182 | + * <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr> |
|
| 183 | + * <ldapLoginFilter>(&(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter> |
|
| 184 | + * <ldapLoginFilterMode>0</ldapLoginFilterMode> |
|
| 185 | + * <ldapLoginFilterEmail>0</ldapLoginFilterEmail> |
|
| 186 | + * <ldapLoginFilterUsername>1</ldapLoginFilterUsername> |
|
| 187 | + * <ldapLoginFilterAttributes></ldapLoginFilterAttributes> |
|
| 188 | + * <ldapQuotaAttribute></ldapQuotaAttribute> |
|
| 189 | + * <ldapQuotaDefault></ldapQuotaDefault> |
|
| 190 | + * <ldapEmailAttribute>mail</ldapEmailAttribute> |
|
| 191 | + * <ldapCacheTTL>20</ldapCacheTTL> |
|
| 192 | + * <ldapUuidUserAttribute>auto</ldapUuidUserAttribute> |
|
| 193 | + * <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute> |
|
| 194 | + * <ldapOverrideMainServer></ldapOverrideMainServer> |
|
| 195 | + * <ldapConfigurationActive>1</ldapConfigurationActive> |
|
| 196 | + * <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch> |
|
| 197 | + * <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch> |
|
| 198 | + * <ldapExperiencedAdmin>0</ldapExperiencedAdmin> |
|
| 199 | + * <homeFolderNamingRule></homeFolderNamingRule> |
|
| 200 | + * <hasMemberOfFilterSupport></hasMemberOfFilterSupport> |
|
| 201 | + * <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership> |
|
| 202 | + * <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr> |
|
| 203 | + * <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr> |
|
| 204 | + * <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr> |
|
| 205 | + * <lastJpegPhotoLookup>0</lastJpegPhotoLookup> |
|
| 206 | + * <ldapNestedGroups>0</ldapNestedGroups> |
|
| 207 | + * <ldapPagingSize>500</ldapPagingSize> |
|
| 208 | + * <turnOnPasswordChange>1</turnOnPasswordChange> |
|
| 209 | + * <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL> |
|
| 210 | + * </data> |
|
| 211 | + * </ocs> |
|
| 212 | + * |
|
| 213 | + * @param string $configID ID of the config |
|
| 214 | + * @param bool $showPassword Whether to show the password |
|
| 215 | + * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}> |
|
| 216 | + * @throws OCSException |
|
| 217 | + * @throws OCSNotFoundException Config not found |
|
| 218 | + * |
|
| 219 | + * 200: Config returned |
|
| 220 | + */ |
|
| 221 | + #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 222 | + #[ApiRoute(verb: 'GET', url: '/api/v1/config/{configID}')] |
|
| 223 | + public function show($configID, $showPassword = false) { |
|
| 224 | + try { |
|
| 225 | + $this->ensureConfigIDExists($configID); |
|
| 226 | 226 | |
| 227 | - $config = new Configuration($configID); |
|
| 228 | - $data = $config->getConfiguration(); |
|
| 229 | - if (!$showPassword) { |
|
| 230 | - $data['ldapAgentPassword'] = '***'; |
|
| 231 | - } |
|
| 232 | - foreach ($data as $key => $value) { |
|
| 233 | - if (is_array($value)) { |
|
| 234 | - $value = implode(';', $value); |
|
| 235 | - $data[$key] = $value; |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - } catch (OCSException $e) { |
|
| 239 | - throw $e; |
|
| 240 | - } catch (\Exception $e) { |
|
| 241 | - $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
| 242 | - throw new OCSException('An issue occurred when modifying the config.'); |
|
| 243 | - } |
|
| 227 | + $config = new Configuration($configID); |
|
| 228 | + $data = $config->getConfiguration(); |
|
| 229 | + if (!$showPassword) { |
|
| 230 | + $data['ldapAgentPassword'] = '***'; |
|
| 231 | + } |
|
| 232 | + foreach ($data as $key => $value) { |
|
| 233 | + if (is_array($value)) { |
|
| 234 | + $value = implode(';', $value); |
|
| 235 | + $data[$key] = $value; |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + } catch (OCSException $e) { |
|
| 239 | + throw $e; |
|
| 240 | + } catch (\Exception $e) { |
|
| 241 | + $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
| 242 | + throw new OCSException('An issue occurred when modifying the config.'); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return new DataResponse($data); |
|
| 246 | - } |
|
| 245 | + return new DataResponse($data); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * If the given config ID is not available, an exception is thrown |
|
| 250 | - * |
|
| 251 | - * @param string $configID |
|
| 252 | - * @throws OCSNotFoundException |
|
| 253 | - */ |
|
| 254 | - #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 255 | - private function ensureConfigIDExists($configID): void { |
|
| 256 | - $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); |
|
| 257 | - if (!in_array($configID, $prefixes, true)) { |
|
| 258 | - throw new OCSNotFoundException('Config ID not found'); |
|
| 259 | - } |
|
| 260 | - } |
|
| 248 | + /** |
|
| 249 | + * If the given config ID is not available, an exception is thrown |
|
| 250 | + * |
|
| 251 | + * @param string $configID |
|
| 252 | + * @throws OCSNotFoundException |
|
| 253 | + */ |
|
| 254 | + #[AuthorizedAdminSetting(settings: Admin::class)] |
|
| 255 | + private function ensureConfigIDExists($configID): void { |
|
| 256 | + $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); |
|
| 257 | + if (!in_array($configID, $prefixes, true)) { |
|
| 258 | + throw new OCSNotFoundException('Config ID not found'); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | } |
@@ -16,72 +16,72 @@ |
||
| 16 | 16 | use OCP\Template\ITemplateManager; |
| 17 | 17 | |
| 18 | 18 | class Admin implements IDelegatedSettings { |
| 19 | - public function __construct( |
|
| 20 | - private IL10N $l, |
|
| 21 | - private ITemplateManager $templateManager, |
|
| 22 | - private IInitialState $initialState, |
|
| 23 | - ) { |
|
| 24 | - } |
|
| 19 | + public function __construct( |
|
| 20 | + private IL10N $l, |
|
| 21 | + private ITemplateManager $templateManager, |
|
| 22 | + private IInitialState $initialState, |
|
| 23 | + ) { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function getForm(): TemplateResponse { |
|
| 27 | - $helper = Server::get(Helper::class); |
|
| 28 | - $prefixes = $helper->getServerConfigurationPrefixes(); |
|
| 29 | - if (count($prefixes) === 0) { |
|
| 30 | - $newPrefix = $helper->getNextServerConfigurationPrefix(); |
|
| 31 | - $config = new Configuration($newPrefix, false); |
|
| 32 | - $config->setConfiguration($config->getDefaults()); |
|
| 33 | - $config->saveConfiguration(); |
|
| 34 | - $prefixes[] = $newPrefix; |
|
| 35 | - } |
|
| 26 | + public function getForm(): TemplateResponse { |
|
| 27 | + $helper = Server::get(Helper::class); |
|
| 28 | + $prefixes = $helper->getServerConfigurationPrefixes(); |
|
| 29 | + if (count($prefixes) === 0) { |
|
| 30 | + $newPrefix = $helper->getNextServerConfigurationPrefix(); |
|
| 31 | + $config = new Configuration($newPrefix, false); |
|
| 32 | + $config->setConfiguration($config->getDefaults()); |
|
| 33 | + $config->saveConfiguration(); |
|
| 34 | + $prefixes[] = $newPrefix; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // assign default values |
|
| 38 | - if (!isset($config)) { |
|
| 39 | - $config = new Configuration('', false); |
|
| 40 | - } |
|
| 41 | - $defaults = $config->getDefaults(); |
|
| 42 | - foreach ($defaults as $key => $default) { |
|
| 43 | - $parameters[$key . '_default'] = $default; |
|
| 44 | - } |
|
| 37 | + // assign default values |
|
| 38 | + if (!isset($config)) { |
|
| 39 | + $config = new Configuration('', false); |
|
| 40 | + } |
|
| 41 | + $defaults = $config->getDefaults(); |
|
| 42 | + foreach ($defaults as $key => $default) { |
|
| 43 | + $parameters[$key . '_default'] = $default; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - $ldapConfigs = []; |
|
| 47 | - foreach ($prefixes as $prefix) { |
|
| 48 | - $ldapConfig = new Configuration($prefix); |
|
| 49 | - $rawLdapConfig = $ldapConfig->getConfiguration(); |
|
| 50 | - foreach ($rawLdapConfig as $key => $value) { |
|
| 51 | - if (is_array($value)) { |
|
| 52 | - $rawLdapConfig[$key] = implode(';', $value); |
|
| 53 | - } |
|
| 54 | - } |
|
| 46 | + $ldapConfigs = []; |
|
| 47 | + foreach ($prefixes as $prefix) { |
|
| 48 | + $ldapConfig = new Configuration($prefix); |
|
| 49 | + $rawLdapConfig = $ldapConfig->getConfiguration(); |
|
| 50 | + foreach ($rawLdapConfig as $key => $value) { |
|
| 51 | + if (is_array($value)) { |
|
| 52 | + $rawLdapConfig[$key] = implode(';', $value); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $ldapConfigs[$prefix] = $rawLdapConfig; |
|
| 57 | - } |
|
| 56 | + $ldapConfigs[$prefix] = $rawLdapConfig; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $this->initialState->provideInitialState('ldapConfigs', $ldapConfigs); |
|
| 60 | - $this->initialState->provideInitialState('ldapModuleInstalled', function_exists('ldap_connect')); |
|
| 59 | + $this->initialState->provideInitialState('ldapConfigs', $ldapConfigs); |
|
| 60 | + $this->initialState->provideInitialState('ldapModuleInstalled', function_exists('ldap_connect')); |
|
| 61 | 61 | |
| 62 | - return new TemplateResponse('user_ldap', 'settings', $parameters); |
|
| 63 | - } |
|
| 62 | + return new TemplateResponse('user_ldap', 'settings', $parameters); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function getSection(): string { |
|
| 66 | - return 'ldap'; |
|
| 67 | - } |
|
| 65 | + public function getSection(): string { |
|
| 66 | + return 'ldap'; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @return int whether the form should be rather on the top or bottom of |
|
| 71 | - * the admin section. The forms are arranged in ascending order of the |
|
| 72 | - * priority values. It is required to return a value between 0 and 100. |
|
| 73 | - * |
|
| 74 | - * E.g.: 70 |
|
| 75 | - */ |
|
| 76 | - public function getPriority(): int { |
|
| 77 | - return 5; |
|
| 78 | - } |
|
| 69 | + /** |
|
| 70 | + * @return int whether the form should be rather on the top or bottom of |
|
| 71 | + * the admin section. The forms are arranged in ascending order of the |
|
| 72 | + * priority values. It is required to return a value between 0 and 100. |
|
| 73 | + * |
|
| 74 | + * E.g.: 70 |
|
| 75 | + */ |
|
| 76 | + public function getPriority(): int { |
|
| 77 | + return 5; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - public function getName(): ?string { |
|
| 81 | - return null; // Only one setting in this section |
|
| 82 | - } |
|
| 80 | + public function getName(): ?string { |
|
| 81 | + return null; // Only one setting in this section |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public function getAuthorizedAppConfig(): array { |
|
| 85 | - return []; // Custom controller |
|
| 86 | - } |
|
| 84 | + public function getAuthorizedAppConfig(): array { |
|
| 85 | + return []; // Custom controller |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | } |
| 41 | 41 | $defaults = $config->getDefaults(); |
| 42 | 42 | foreach ($defaults as $key => $default) { |
| 43 | - $parameters[$key . '_default'] = $default; |
|
| 43 | + $parameters[$key.'_default'] = $default; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $ldapConfigs = []; |
@@ -8,25 +8,25 @@ |
||
| 8 | 8 | * SPDX-License-Identifier: AGPL-3.0-only |
| 9 | 9 | */ |
| 10 | 10 | $this->create('user_ldap_ajax_clearMappings', 'apps/user_ldap/ajax/clearMappings.php') |
| 11 | - ->actionInclude('user_ldap/ajax/clearMappings.php'); |
|
| 11 | + ->actionInclude('user_ldap/ajax/clearMappings.php'); |
|
| 12 | 12 | $this->create('user_ldap_ajax_deleteConfiguration', 'apps/user_ldap/ajax/deleteConfiguration.php') |
| 13 | - ->actionInclude('user_ldap/ajax/deleteConfiguration.php'); |
|
| 13 | + ->actionInclude('user_ldap/ajax/deleteConfiguration.php'); |
|
| 14 | 14 | $this->create('user_ldap_ajax_getConfiguration', 'apps/user_ldap/ajax/getConfiguration.php') |
| 15 | - ->actionInclude('user_ldap/ajax/getConfiguration.php'); |
|
| 15 | + ->actionInclude('user_ldap/ajax/getConfiguration.php'); |
|
| 16 | 16 | $this->create('user_ldap_ajax_getNewServerConfigPrefix', 'apps/user_ldap/ajax/getNewServerConfigPrefix.php') |
| 17 | - ->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php'); |
|
| 17 | + ->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php'); |
|
| 18 | 18 | $this->create('user_ldap_ajax_setConfiguration', 'apps/user_ldap/ajax/setConfiguration.php') |
| 19 | - ->actionInclude('user_ldap/ajax/setConfiguration.php'); |
|
| 19 | + ->actionInclude('user_ldap/ajax/setConfiguration.php'); |
|
| 20 | 20 | $this->create('user_ldap_ajax_testConfiguration', 'apps/user_ldap/ajax/testConfiguration.php') |
| 21 | - ->actionInclude('user_ldap/ajax/testConfiguration.php'); |
|
| 21 | + ->actionInclude('user_ldap/ajax/testConfiguration.php'); |
|
| 22 | 22 | $this->create('user_ldap_ajax_wizard', 'apps/user_ldap/ajax/wizard.php') |
| 23 | - ->actionInclude('user_ldap/ajax/wizard.php'); |
|
| 23 | + ->actionInclude('user_ldap/ajax/wizard.php'); |
|
| 24 | 24 | |
| 25 | 25 | return [ |
| 26 | - 'routes' => [ |
|
| 27 | - ['name' => 'renewPassword#tryRenewPassword', 'url' => '/renewpassword', 'verb' => 'POST'], |
|
| 28 | - ['name' => 'renewPassword#showRenewPasswordForm', 'url' => '/renewpassword/{user}', 'verb' => 'GET'], |
|
| 29 | - ['name' => 'renewPassword#cancel', 'url' => '/renewpassword/cancel', 'verb' => 'GET'], |
|
| 30 | - ['name' => 'renewPassword#showLoginFormInvalidPassword', 'url' => '/renewpassword/invalidlogin/{user}', 'verb' => 'GET'], |
|
| 31 | - ], |
|
| 26 | + 'routes' => [ |
|
| 27 | + ['name' => 'renewPassword#tryRenewPassword', 'url' => '/renewpassword', 'verb' => 'POST'], |
|
| 28 | + ['name' => 'renewPassword#showRenewPasswordForm', 'url' => '/renewpassword/{user}', 'verb' => 'GET'], |
|
| 29 | + ['name' => 'renewPassword#cancel', 'url' => '/renewpassword/cancel', 'verb' => 'GET'], |
|
| 30 | + ['name' => 'renewPassword#showLoginFormInvalidPassword', 'url' => '/renewpassword/invalidlogin/{user}', 'verb' => 'GET'], |
|
| 31 | + ], |
|
| 32 | 32 | ]; |
@@ -22,51 +22,51 @@ |
||
| 22 | 22 | * @package OCA\User_LDAP\Tests\Settings |
| 23 | 23 | */ |
| 24 | 24 | class AdminTest extends TestCase { |
| 25 | - private IL10N&MockObject $l10n; |
|
| 26 | - private ITemplateManager $templateManager; |
|
| 27 | - private IInitialState&MockObject $initialState; |
|
| 28 | - private Admin $admin; |
|
| 25 | + private IL10N&MockObject $l10n; |
|
| 26 | + private ITemplateManager $templateManager; |
|
| 27 | + private IInitialState&MockObject $initialState; |
|
| 28 | + private Admin $admin; |
|
| 29 | 29 | |
| 30 | - protected function setUp(): void { |
|
| 31 | - parent::setUp(); |
|
| 32 | - $this->l10n = $this->createMock(IL10N::class); |
|
| 33 | - $this->templateManager = Server::get(ITemplateManager::class); |
|
| 34 | - $this->initialState = $this->createMock(IInitialState::class); |
|
| 30 | + protected function setUp(): void { |
|
| 31 | + parent::setUp(); |
|
| 32 | + $this->l10n = $this->createMock(IL10N::class); |
|
| 33 | + $this->templateManager = Server::get(ITemplateManager::class); |
|
| 34 | + $this->initialState = $this->createMock(IInitialState::class); |
|
| 35 | 35 | |
| 36 | - $this->admin = new Admin( |
|
| 37 | - $this->l10n, |
|
| 38 | - $this->templateManager, |
|
| 39 | - $this->initialState, |
|
| 40 | - ); |
|
| 41 | - } |
|
| 36 | + $this->admin = new Admin( |
|
| 37 | + $this->l10n, |
|
| 38 | + $this->templateManager, |
|
| 39 | + $this->initialState, |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function testGetForm(): void { |
|
| 44 | - $prefixes = ['s01']; |
|
| 45 | - $hosts = ['s01' => '']; |
|
| 43 | + public function testGetForm(): void { |
|
| 44 | + $prefixes = ['s01']; |
|
| 45 | + $hosts = ['s01' => '']; |
|
| 46 | 46 | |
| 47 | - $wControls = $this->templateManager->getTemplate('user_ldap', 'part.wizardcontrols'); |
|
| 48 | - $wControls = $wControls->fetchPage(); |
|
| 49 | - $sControls = $this->templateManager->getTemplate('user_ldap', 'part.settingcontrols'); |
|
| 50 | - $sControls = $sControls->fetchPage(); |
|
| 47 | + $wControls = $this->templateManager->getTemplate('user_ldap', 'part.wizardcontrols'); |
|
| 48 | + $wControls = $wControls->fetchPage(); |
|
| 49 | + $sControls = $this->templateManager->getTemplate('user_ldap', 'part.settingcontrols'); |
|
| 50 | + $sControls = $sControls->fetchPage(); |
|
| 51 | 51 | |
| 52 | - $parameters = []; |
|
| 52 | + $parameters = []; |
|
| 53 | 53 | |
| 54 | - // assign default values |
|
| 55 | - $config = new Configuration('', false); |
|
| 56 | - $defaults = $config->getDefaults(); |
|
| 57 | - foreach ($defaults as $key => $default) { |
|
| 58 | - $parameters[$key . '_default'] = $default; |
|
| 59 | - } |
|
| 54 | + // assign default values |
|
| 55 | + $config = new Configuration('', false); |
|
| 56 | + $defaults = $config->getDefaults(); |
|
| 57 | + foreach ($defaults as $key => $default) { |
|
| 58 | + $parameters[$key . '_default'] = $default; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $expected = new TemplateResponse('user_ldap', 'settings', $parameters); |
|
| 62 | - $this->assertEquals($expected, $this->admin->getForm()); |
|
| 63 | - } |
|
| 61 | + $expected = new TemplateResponse('user_ldap', 'settings', $parameters); |
|
| 62 | + $this->assertEquals($expected, $this->admin->getForm()); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function testGetSection(): void { |
|
| 66 | - $this->assertSame('ldap', $this->admin->getSection()); |
|
| 67 | - } |
|
| 65 | + public function testGetSection(): void { |
|
| 66 | + $this->assertSame('ldap', $this->admin->getSection()); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public function testGetPriority(): void { |
|
| 70 | - $this->assertSame(5, $this->admin->getPriority()); |
|
| 71 | - } |
|
| 69 | + public function testGetPriority(): void { |
|
| 70 | + $this->assertSame(5, $this->admin->getPriority()); |
|
| 71 | + } |
|
| 72 | 72 | } |