user = $user; $this->config = $config; } /** * @throws Forbidden * @throws LdapException */ public function postActionTestConnection(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; } }