Switching to different Connections to perform ->attach() and ->detach() #351
-
My situation is as follows: We have an AD forest with multiple child domains. We have AD Groups sprinkled in a variety of these domains, and I have a need to search for various users spread across domains and place them into various groups. An example would be like this: 10 users in Historically, I have done this with raw PHP, and somehow it works, but a major drawback is that I am using an account with far too many privileges, and I would also like to start using LdapRecord-Laravel for this. So, is it possible to have a Laravel Command that starts by identifying the users using a bind account that has limited permissions, connecting on port 3269 (so that it can search the entire Global Catalog), and then once I find the relevant users, then switch to using a different Connection in the users' domains for doing the I understand how to create new Connections and add them to the Container and give them different names. I guess I'm just curious how to perform the attach method while specifying a Connection for the operation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @nspaul, this is a great question. I'll do my best to help you get this working.
Unfortunately I've never worked with the global catalog before. I've only worked with a domain that had two child domains (a pretty simplistic setup), so I don't have much knowledge on this.
You can certainly do this now using the For example: $group = Group::on('ChildDomainC')->find('cn=group,dc=local,dc=com');
User::on('ChildDomainA')->each(function (User $user) use ($group) {
// Using "ChildDomainA" connection to attach the user.
$group->setConnection('ChildDomainA')->members()->attach($user);
});
User::on('ChildDomainB')->each(function (User $user) use ($group) {
// Using "ChildDomainB" connection to attach the user.
$group->setConnection('ChildDomainB')->members()->attach($user);
}); You'll have to configure connections for each of your domains of course, along with their own credentials. Does this help you / answer some of your questions? |
Beta Was this translation helpful? Give feedback.
Hi @nspaul, this is a great question. I'll do my best to help you get this working.
Unfortunately I've never worked with the global catalog before. I've only worked with a domain that had two child domains (a pretty simplistic setup), so I don't have much knowledge on this.
You can certainly do this now using the
Model::on($connection)
…