metadata = $metadata; $this->service = $service; $this->user = $user; $this->config = $config; } public function getActionRead(): stdClass { return $this->getConfigData(); } /** * @throws BadRequest * @throws Forbidden * @throws Error */ public function putActionUpdate(Request $request): stdClass { if (!$this->user->isAdmin()) { throw new Forbidden(); } $data = $request->getParsedBody(); $this->service->setConfigData($data); return $this->getConfigData(); } /** * @throws Forbidden * @throws LdapException */ public function postActionTestLdapConnection(Request $request): bool { if (!$this->user->isAdmin()) { throw new Forbidden(); } $data = $request->getParsedBody(); if (!isset($data->password)) { $data->password = $this->config->get('ldapPassword'); } $ldapUtils = new LDAPUtils(); $options = $ldapUtils->normalizeOptions( get_object_vars($data) ); $ldapClient = new LDAPClient($options); // An exception thrown if no connection. $ldapClient->bind(); return true; } private function getConfigData(): stdClass { $data = $this->service->getConfigData(); $metadataData = $this->service->getMetadataConfigData(); foreach (get_object_vars($metadataData) as $key => $value) { $data->$key = $value; } return $data; } }