Skip to content

Commit

Permalink
Merge pull request #1064 from remche/custom-ldap-user
Browse files Browse the repository at this point in the history
add a way to override LdapUser. fix  #1062
  • Loading branch information
dbarzin authored Jan 17, 2025
2 parents 37dc527 + 2c591a8 commit d88de87
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
20 changes: 19 additions & 1 deletion INSTALL.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ ajouter cette ligne dans le crontab
Si vous souhaitez connecter Mercator avec un Active Diretory ou un serveur LDAP,
dans le fichier .env, mettez les paramètres de connexion en décommentant les lignes :

# Plusieurs types possibles : AD, OpenLDAP, FreeIPA, DirectoryServer
# Plusieurs types possibles : AD, OpenLDAP, FreeIPA, DirectoryServer, Custom
LDAP_TYPE="AD"
# If true, LDAP actions will be written to the application's default log file
LDAP_LOGGING=true
Expand All @@ -198,6 +198,24 @@ dans le fichier .env, mettez les paramètres de connexion en décommentant les l

Retrouvez une documentation plus complète sur la configuration de [LdapRecord](https://ldaprecord.com/docs/laravel/v2/configuration/#using-an-environment-file-env).

Si vous choisissez le type Custom, vous devez fournir une classe LdapUserCustom dans le fichier `app/Ldap/LdapUserCustom.php`, par exemple :

```php
<?php

namespace App\Ldap;

use LdapRecord\Models\OpenLDAP\User as OpenLdapUser;
use LdapRecord\Models as Models;

class LdapUserCustom extends OpenLdapUser
{
public function groups(): Models\Relations\HasMany {
return $this->hasMany(Models\OpenLDAP\Group::class, 'memberUid', 'uid');
}
}
```

## Configuration de Keycloak (optionel)

Pour configurer Keycloak, suivez ces étapes :
Expand Down
21 changes: 20 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ add this line in the crontab

Modify .env file, and uncomment LDAP configuration :

# Several possible types: AD, OpenLDAP, FreeIPA, DirectoryServer
# Several possible types: AD, OpenLDAP, FreeIPA, DirectoryServer, Custom
LDAP_TYPE="AD"
# If true, LDAP's actions will be log into
LDAP_LOGGING=true
Expand All @@ -198,6 +198,25 @@ Modify .env file, and uncomment LDAP configuration :

Find more complete documentation on LDAP configuration [here](https://ldaprecord.com/docs/laravel/v2/configuration/#using-an-environment-file-env).

If you choose Custom, you have to provide a LdapUserCustom class in `app/Ldap/LdapUserCustom.php` file, ie :

```php
<?php

namespace App\Ldap;

use LdapRecord\Models\OpenLDAP\User as OpenLdapUser;
use LdapRecord\Models as Models;

class LdapUserCustom extends OpenLdapUser
{
public function groups(): Models\Relations\HasMany {
return $this->hasMany(Models\OpenLDAP\Group::class, 'memberUid', 'uid');
}
}
```


## KeyCloak Configuration (optional)

To configure Keycloak, follow these steps:
Expand Down
6 changes: 6 additions & 0 deletions app/Ldap/LdapUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
use LdapRecord\Models\OpenLDAP\User as OpenLdapUser;

switch (strtolower(config('app.ldap_type', 'AD'))) {
case 'custom':
class LdapUser extends LdapUserCustom
{
}
break;
// no break
case 'openldap':
class LdapUser extends OpenLdapUser
{
Expand Down

0 comments on commit d88de87

Please sign in to comment.