Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Recursive Group names from AD (memberOf) #909

Open
JustJeremy opened this issue Apr 15, 2021 · 0 comments
Open

Recursive Group names from AD (memberOf) #909

JustJeremy opened this issue Apr 15, 2021 · 0 comments

Comments

@JustJeremy
Copy link

  • Laravel Version: 7.x
  • Adldap2-Laravel Version: latest
  • PHP Version: 7.4
  • LDAP Type: ActiveDirectory

I recently did a huge upgrade going from Laravel 5 to the last branch before going to 8. I was using adldap in version 5 branch and upgraded that to the latest stable you have. I got it all working like it should but wanted to point this out for any other folks having problems.
If you are trying to get groups (memberOf) at log in to do a sync that is broken the way you used to do this in earlier versions. I'm not sure when this broke as I went from very old to latest and skipped over doing all the upgrades in between.
In the older version you could put in the hook at the 'sync_attributes' property with \App\Handlers\LdapAttributeHandler::class.
This worked perfect to hook in and do the logic needed to do a recursive grab of all user groups on the AD. In the newest version you are not able to do this. Even if you make it more json like and give it the attribute of 'groups' => 'App\Handlers\LdapAttributeHandler@groups', This will always return null.
The fix for me was to move this out of the handler and put the logic in the LoginController at the authenticated function.
Then it was just a simple matter to check if $user has a objectguid and if they do we know they are an AD user. Then you can use the adldap Facades...

$ldapuser = Adldap::search()->users()->find($user->username);
$group = $ldapuser->getGroupNames($recursive = true);
$comma_group = implode(",", $group);
$lower_group = strtolower($comma_group);
$user->groups = $lower_group;
$user->save();

It's probably not the nicest way of doing this but it works 100%. Obviously you are going to do some checking before this so you don't throw null errors...etc. Anyway, hope this helps someone out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant