DirectoryTree / LdapRecord-Laravel

Multi-domain LDAP Authentication & Management for Laravel.
https://ldaprecord.com/docs/laravel/v3
MIT License
492 stars 51 forks source link

Emulate `memberof` virtual attribute in Directory Emulator #584

Closed stevebauman closed 10 months ago

stevebauman commented 10 months ago

Closes https://github.com/DirectoryTree/LdapRecord-Laravel/issues/561 Closes https://github.com/DirectoryTree/LdapRecord-Laravel/pull/565

This PR implements emulating virtual attributes (memberof only right now) in the Directory Emulator. More attributes can be added if necessary by developers using the public attribute arrays inside of each observer.

This fixes the issue namely with attaching/detaching user groups and having the changes automatically reflected in the related models virtual attribute. This now works as it would with a real LDAP server. For example:

use LdapRecord\Models\ActiveDirectory\User;
use LdapRecord\Models\ActiveDirectory\Group;

$user = User::create(['cn' => 'John']);
$group = Group::create(['cn' => 'Accounting']);

$user->groups()->attach($group);

$user->refresh();

dd($user->memberof); // ["cn=Accounting,dc=local,dc=com"]

This also fixes an issue where a model is renamed in the Directory Emulator, but the rename didn't update in relationships it's apart of.

Huge kudos and credit goes to @cheesegrits for this, as this is all inspired from his original PR https://github.com/DirectoryTree/LdapRecord-Laravel/pull/565.

cheesegrits commented 10 months ago

Just FYI I ran this branch through my LDAP torture-test suite, and it passes.

stevebauman commented 10 months ago

@cheesegrits This has been released, thanks again for your help on this! 🙏

https://github.com/DirectoryTree/LdapRecord-Laravel/releases/v3.0.8