Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make name LDAP properties configurable #5423

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions docs/authentication_and_users.md
Expand Up @@ -43,11 +43,13 @@ sudo -u apache bin/console --env=prod ilios:maintenance:set-config-value ldap_di
sudo -u apache bin/console --env=prod ilios:maintenance:set-config-value ldap_directory_username_property <your campus value>
```

| Property Name| Description| Example Value|
|---|---|---|
| ldap_directory_url | URL to connect to your LDAP server including protocol | ldaps://directory.campus.edu |
| ldap_directory_user | The user we will use to authenticate | uid=Ilios,ou=applications,dc=campus,dc=edu |
| ldap_directory_password | The bind password for your user | 123GoLdap! |
| ldap_directory_search_base | What scope in the directory we should user for users | ou=people,dc=campus,dc=edu |
| ldap_directory_campus_id_property | In the returned data for a user what property is unique and can be used to populate the campusId field in Ilios | eduIDNumber |
| ldap_directory_username_property | In the returned data for a user what property contains the username that links to the **cas**, **ldap**, or **shibboleth** authentication service | eduPersonPrincipalName |
| Property Name | Description | Example Value |
|------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| ldap_directory_url | URL to connect to your LDAP server including protocol | ldaps://directory.campus.edu |
| ldap_directory_user | The user we will use to authenticate | uid=Ilios,ou=applications,dc=campus,dc=edu |
| ldap_directory_password | The bind password for your user | 123GoLdap! |
| ldap_directory_search_base | What scope in the directory we should user for users | ou=people,dc=campus,dc=edu |
| ldap_directory_campus_id_property | In the returned data for a user what property is unique and can be used to populate the campusId field in Ilios | eduIDNumber |
| ldap_directory_username_property | In the returned data for a user what property contains the username that links to the **cas**, **ldap**, or **shibboleth** authentication service | eduPersonPrincipalName |
| ldap_directory_first_name_property | In the returned data for a user what property contains the first name. If this isn't provided it will default to **givenName** | givenName |
| ldap_directory_last_name_property | In the returned data for a user what property contains the last name. If this isn't provided it will default to **sn** | sn |
16 changes: 12 additions & 4 deletions src/Service/LdapManager.php
Expand Up @@ -7,9 +7,15 @@
use Exception;
use Symfony\Component\Ldap\Ldap;

/**
* Manages the LDAP connection. Because the Symfony ldap class is marked as final,
* we need to wrap it here so that we can mock it in tests. This class is the lowest
* level in the test tree, it can't be tested itself because of the issue with mocking
* the final class.
*/
class LdapManager
{
protected ?Ldap $ldap = null;
protected Ldap $ldap;

/**
* Constructor
Expand All @@ -28,6 +34,8 @@ public function search(string $filter): array
$ldapUsernameProperty = $this->config->get('ldap_directory_username_property');
$ldapDisplayNameProperty = $this->config->get('ldap_directory_display_name_property');
$ldapPronounsProperty = $this->config->get('ldap_directory_pronouns_property');
$ldapFirstNameProperty = $this->config->get('ldap_directory_first_name_property') ?? 'givenName';
$ldapLastNameProperty = $this->config->get('ldap_directory_last_name_property') ?? 'sn';

$rhett = [];
try {
Expand All @@ -36,8 +44,8 @@ public function search(string $filter): array
$results = $query->execute();
$attributes = [
'mail' => 'email',
'sn' => 'lastName',
'givenName' => 'firstName',
$ldapLastNameProperty => 'lastName',
$ldapFirstNameProperty => 'firstName',
'telephoneNumber' => 'telephoneNumber',
$ldapCampusIdProperty => 'campusId',
$ldapUsernameProperty => 'username',
Expand Down Expand Up @@ -73,7 +81,7 @@ public function search(string $filter): array

protected function getConnection(): Ldap
{
if (! $this->ldap) {
if (!isset($this->ldap)) {
$ldapUrl = $this->config->get('ldap_directory_url');
$ldapBindUser = $this->config->get('ldap_directory_user');
$ldapBindPassword = $this->config->get('ldap_directory_password');
Expand Down