DirectoryTree / LdapRecord-Laravel

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

[Bug] Unable to run `ldap:import` command programatically #605

Closed zillion42 closed 1 year ago

zillion42 commented 1 year ago

Environment:

Describe the bug: Hi,

I'm having trouble to import users programmatically with ldaprecord 2.7 https://ldaprecord.com/docs/laravel/v2/auth/database/importing/#programmatically-executing

It works perfectly if run the commands in the console

C:\laragon\www\jobticket(master -> origin)
λ php artisan ldap:import users reichert
Found user [CN=xxxx Reichert].

 Would you like to display the user(s) to be imported / synchronized? (yes/no) [no]:
 > yes

+---------------------------------------------------------------------------------------+--------------------+
| Name                                                                                  | Distinguished Name |
+---------------------------------------------------------------------------------------+--------------------+
| CN=xxxx Reichert,OU=benutzer,OU=FBIT,OU=Verwaltung,DC=verwaltung,DC=xxxx,DC=intern | CN=xxxx Reichert |
+---------------------------------------------------------------------------------------+--------------------+

 Would you like these users to be imported / synchronized? (yes/no) [yes]:
 > yes

 1/1 [============================] 100%
 Successfully imported / synchronized [1] user(s).

The user is then added to my user table, all is fine. Logs show:

[2023-11-07 18:04:26] local.INFO: Starting import of [1] LDAP objects.  
[2023-11-07 18:04:26] local.INFO: Object with name [xxxx Reichert] is being imported.  
[2023-11-07 18:04:26] local.INFO: Object with name [xxxx Reichert] is being synchronized.  
[2023-11-07 18:04:26] local.INFO: Object with name [xxxx Reichert] has been successfully synchronized.  
[2023-11-07 18:04:26] local.INFO: Object with name [xxxx Reichert] has been successfully imported.  

If I however try to import programmatically like so:

Artisan::call('ldap:import', [
                        'provider' => 'ldap',
                        'user' => 'xxxx.reichert',
                        '--no-interaction',
                        //'--restore' => true,
                        //'--delete' => true,
                        //'--delete-missing' => true,
                        '--filter' => '(objectclass=user)',
                        //'--scopes' => 'App\Ldap\Scopes\OnlyAdmins',
                        '--attributes' => 'cn,mail,samaccountname',
                    ]);

No errors are thrown, but nothing is imported either

EDIT: I tried with and without all the options provided. Unfortunately nothing happens, no errors are thrown. EDIT2: Everthing else works bind search etc. Checking the logs also looks like import is not executed

EDIT3: This is my config/auth.php providers section:

    'providers' => [
        'users' => [
            'driver' => 'ldap',
            'model' => LdapRecord\Models\ActiveDirectory\User::class,
            'rules' => [],
            'database' => [
                'model' => App\Models\User::class,
                'sync_passwords' => false,
                'sync_attributes' => [
                    'name' => 'cn',
                    'username' => 'samaccountname',
                    'email' => 'mail',
                ],
            ],
        ],
    ],
stevebauman commented 1 year ago

Hi @zillion42,

Looking at your successful command run, the ‘provider’ that you've passed into the programmatic call should be "users" instead of "ldap"'. Can you give that a shot?

zillion42 commented 1 year ago

Hi @stevebauman ,

yes I tried that, thought might fix it, but unfortunately it gave me this, now it gets weird:

image

EDIT: Full trace:

[2023-11-07 18:56:04] local.ERROR: Undefined constant "STDIN" {"userId":6,"exception":"[object] (Error(code: 0): Undefined constant \"STDIN\" at C:\\laragon\\www\\jobticket\\vendor\\symfony\\console\\Helper\\QuestionHelper.php:109)
[stacktrace]
#0 C:\\laragon\\www\\jobticket\\vendor\\symfony\\console\\Helper\\QuestionHelper.php(68): Symfony\\Component\\Console\\Helper\\QuestionHelper->doAsk(Object(Illuminate\\Console\\OutputStyle), Object(Symfony\\Component\\Console\\Question\\ConfirmationQuestion))
#1 C:\\laragon\\www\\jobticket\\vendor\\symfony\\console\\Style\\SymfonyStyle.php(346): Symfony\\Component\\Console\\Helper\\QuestionHelper->ask(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Illuminate\\Console\\OutputStyle), Object(Symfony\\Component\\Console\\Question\\ConfirmationQuestion))
#2 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\OutputStyle.php(58): Symfony\\Component\\Console\\Style\\SymfonyStyle->askQuestion(Object(Symfony\\Component\\Console\\Question\\ConfirmationQuestion))
#3 C:\\laragon\\www\\jobticket\\vendor\\symfony\\console\\Style\\SymfonyStyle.php(272): Illuminate\\Console\\OutputStyle->askQuestion(Object(Symfony\\Component\\Console\\Question\\ConfirmationQuestion))
#4 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Concerns\\InteractsWithIO.php(142): Symfony\\Component\\Console\\Style\\SymfonyStyle->confirm('Would you like ...', false)
#5 C:\\laragon\\www\\jobticket\\vendor\\directorytree\\ldaprecord-laravel\\src\\Commands\\ImportLdapUsers.php(218): Illuminate\\Console\\Command->confirm('Would you like ...', false)
#6 C:\\laragon\\www\\jobticket\\vendor\\directorytree\\ldaprecord-laravel\\src\\Commands\\ImportLdapUsers.php(115): LdapRecord\\Laravel\\Commands\\ImportLdapUsers->confirmAndDisplayObjects(Object(LdapRecord\\Models\\Collection))
#7 C:\\laragon\\www\\jobticket\\vendor\\directorytree\\ldaprecord-laravel\\src\\Commands\\ImportLdapUsers.php(95): LdapRecord\\Laravel\\Commands\\ImportLdapUsers->beginImport()
#8 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(36): LdapRecord\\Laravel\\Commands\\ImportLdapUsers->handle(Object(LdapRecord\\Laravel\\Commands\\LdapUserImporter), Object(Illuminate\\Config\\Repository))
#9 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#10 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#11 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#12 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(662): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#13 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(211): Illuminate\\Container\\Container->call(Array)
#14 C:\\laragon\\www\\jobticket\\vendor\\symfony\\console\\Command\\Command.php(326): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Illuminate\\Console\\OutputStyle))
#15 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(181): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Illuminate\\Console\\OutputStyle))
#16 C:\\laragon\\www\\jobticket\\vendor\\symfony\\console\\Application.php(1081): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#17 C:\\laragon\\www\\jobticket\\vendor\\symfony\\console\\Application.php(320): Symfony\\Component\\Console\\Application->doRunCommand(Object(LdapRecord\\Laravel\\Commands\\ImportLdapUsers), Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#18 C:\\laragon\\www\\jobticket\\vendor\\symfony\\console\\Application.php(174): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#19 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Application.php(163): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#20 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(400): Illuminate\\Console\\Application->call('ldap:import', Array, NULL)
#21 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Facades\\Facade.php(353): Illuminate\\Foundation\\Console\\Kernel->call('ldap:import', Array)
#22 C:\\laragon\\www\\jobticket\\app\\Http\\Controllers\\FilesController.php(75): Illuminate\\Support\\Facades\\Facade::__callStatic('call', Array)
#23 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php(54): App\\Http\\Controllers\\FilesController->store(Object(Illuminate\\Http\\Request))
#24 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(43): Illuminate\\Routing\\Controller->callAction('store', Array)
#25 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(260): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\FilesController), 'store')
#26 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(205): Illuminate\\Routing\\Route->runController()
#27 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(799): Illuminate\\Routing\\Route->run()
#28 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(142): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#29 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#31 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Auth\\Middleware\\Authenticate.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#32 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Auth\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#33 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#34 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#35 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#36 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#37 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#38 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(64): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest(Object(Illuminate\\Http\\Request), Object(Illuminate\\Session\\Store), Object(Closure))
#39 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#40 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#41 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#42 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#43 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#44 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(117): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#45 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(800): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#46 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(777): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#47 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(741): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#48 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(730): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#49 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(200): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#50 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(142): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#51 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#52 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#53 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#54 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#55 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#56 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#57 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#58 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#59 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance.php(99): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#60 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#61 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Middleware\\HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#62 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Http\\Middleware\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#63 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Middleware\\TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#64 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(181): Illuminate\\Http\\Middleware\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#65 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(117): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#66 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#67 C:\\laragon\\www\\jobticket\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#68 C:\\laragon\\www\\jobticket\\public\\index.php(52): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
stevebauman commented 1 year ago

You're also missing the --no-interaction flag 👍

zillion42 commented 1 year ago

🤦 Works now! Thx a lot for your fast and precise help, guess my concentration dropped. I had the no-interaction flag in there before.

stevebauman commented 1 year ago

No worries at all @zillion42! Always happy to help! Glad you're up and running 🙏