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

Issue with creating user in specific OU #880

Open
vlad198407 opened this issue Jul 12, 2020 · 0 comments
Open

Issue with creating user in specific OU #880

vlad198407 opened this issue Jul 12, 2020 · 0 comments

Comments

@vlad198407
Copy link

vlad198407 commented Jul 12, 2020

Adldap2 Version: Master
LDAP Type: ActiveDirectory
PHP Version: 7.3
Laravel version: 5.8

Hi there,

I have an issue with creating user in specific OU.

I'm not sure, but I think it should be done using distinguished names.

so what I have tried is

$userData = [
    'cn' => 'common name Test',
    'sAMAccountName' => 'sAMAccountName test',
    'company' => 'Company Name',
    'UserPrincipalName' => 'principal@company.local',
    'givenname' => 'test',
    'sn' => 'sn test'
];

$user->objectclass = [
	'top',
	'person',
	'inetOrgPerson',
];

$user->setPassword('some initial pass');
$user->setAttribute('UserAccountControl', 512);
$user->setAttribute('pwdLastSet',  0);

So if leave this as this is, it will work. But I will need to create in specific OU depending on some conditions.

So what I've tried is adding to above code this

$dn  = "cn=common name Test,ou=sub section,ou=section,ou=sub unit,ou=Unit,ou=Department,ou=companyName,dc=companyName,dc=local"

$user->setDn($dn);

$result = $user->save();

As a result got error message

ErrorException : ldap_add(): Add: Insufficient access at project_root\vendor\adldap2\adldap2\src\Connections\Ldap.php:354

tried also with this way

$dn = $user->getDnBuilder();

$dn->addCn($user->getCommonName());

$dn->removeOu('companyName');
$dn->removeOu('Department');
$dn->removeOu('Unit');
$dn->removeOu('sub unit');
$dn->removeOu('section');


$dn->addOu('sub section');
$dn->addOu('section');
$dn->addOu('sub unit');
$dn->addOu('Unit');
$dn->addOu('Department');
$dn->addOu('companyName');

echo $dn->get(); // it's the same string as I've tried above

$user->setDn($dn);

$result = $user->save();

And again same error. I thought that it can be because of user permissions, that I'm using, but with the same credentials using Softera Ldap Administrator it works, I can create entry in my selected OU, so probably something wrong with my code.

BTW, I'm able to move user to my selected OU with the methods that your package provides. $user->move($ou);

Any help will be appreciated!
Thanks

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