Skip to content
Snippets Groups Projects
Commit 2ff89571 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Add a health check for the LDAP attributes

We check that at least one person in LDAP has the specified attribute,
or we error out.
parent 036faee9
No related branches found
No related tags found
No related merge requests found
Pipeline #92945 passed
......@@ -41,6 +41,7 @@ class HealthCheck implements CheckInterface
{
$results = [];
$results[] = $this->checkMethod('Check if we can connect to the LDAP server', [$this->ldap, 'checkConnection']);
$results[] = $this->checkMethod('Check if all attributes are available', [$this->ldap, 'checkAttributes']);
return $results;
}
......
......@@ -111,6 +111,42 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
$builder->first();
}
public function checkAttributeExists(string $attribute): bool
{
$provider = $this->getProvider();
$builder = $this->getCachedBuilder($provider);
/** @var User $user */
$user = $builder
->where('objectClass', '=', $provider->getSchema()->person())
->whereHas($attribute)
->first();
return $user !== null;
}
public function checkAttributes()
{
$attributes = [
$this->identifierAttributeName,
$this->givenNameAttributeName,
$this->familyNameAttributeName,
$this->emailAttributeName,
$this->birthdayAttributeName,
];
$missing = [];
foreach ($attributes as $attr) {
if ($attr !== '' && !$this->checkAttributeExists($attr)) {
$missing[] = $attr;
}
}
if (count($missing) > 0) {
throw new \RuntimeException('The following LDAP attributes were not found: '.join(', ', $missing));
}
}
public function setDeploymentEnvironment(string $env)
{
$this->deploymentEnv = $env;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment