Skip to content

Resolve #3107815 "Argument 1 passed to Drupal\ldap_servers\LdapBaseManager::sanitizeUserDataResponse() must be an instance of Symfony\Component\Ldap\Entry, null given"

yas requested to merge issue/ldap-3107815:3107815-argument-1-passed into 8.x-4.x

We encountered exactly the same issue while logging into a server using LDAP module 4.x-dev.

Warning: Invalid argument supplied for foreach() in Drupal\ldap_servers\LdapBaseManager->sanitizeUserDataResponse() (line 416 of modules/contrib/ldap/ldap_servers/src/LdapBaseManager.php).
Drupal\ldap_servers\LdapBaseManager->sanitizeUserDataResponse(Object, 'xxx.xxxx') (Line: 124)
Drupal\ldap_authentication\Controller\LoginValidatorLoginForm->testCredentials() (Line: 50)
Drupal\ldap_authentication\Controller\LoginValidatorLoginForm->processLogin() (Line: 33)
Drupal\ldap_authentication\Controller\LoginValidatorLoginForm->validateLogin(Object) (Line: 214)
ldap_authentication_user_login_authenticate_validate(Array, Object)
call_user_func_array('ldap_authentication_user_login_authenticate_validate', Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 273)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'user_login_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('user_login_form', Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('user_login_form', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 706)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

When we want to fix this issue, return NULL at the end of LdapBaseManager::sanitizeUserDataResponse() however it is not enough due to the following error:

Warning: Invalid argument supplied for foreach() in Drupal\ldap_servers\LdapBaseManager->sanitizeUserDataResponse() (line 416 of modules/contrib/ldap/ldap_servers/src/LdapBaseManager.php).
Drupal\ldap_servers\LdapBaseManager->sanitizeUserDataResponse(Object, 'xxx.xxxx') (Line: 124)
Drupal\ldap_authentication\Controller\LoginValidatorLoginForm->testCredentials() (Line: 50)
Drupal\ldap_authentication\Controller\LoginValidatorLoginForm->processLogin() (Line: 33)
Drupal\ldap_authentication\Controller\LoginValidatorLoginForm->validateLogin(Object) (Line: 214)
ldap_authentication_user_login_authenticate_validate(Array, Object)
call_user_func_array('ldap_authentication_user_login_authenticate_validate', Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 273)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'user_login_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('user_login_form', Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('user_login_form', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 706)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Therefore I added ?: [] in the foreach() loop.

Merge request reports