[BUG] connection with environment configuration doesn't work, with custom Provider instance it does
- Laravel Version: 5.7.*
- Adldap2-Laravel Version: ^4.0
- PHP Version: 7.2
- LDAP Type: OpenLDAP
Description:
When creating a custom instance of \Adldap\Connections\Provider I'm able to connect to the OpenLDAP server. Using the environment variables with the same configuration doesn't work and I receive Invalid DN syntax for all attempts. openldap within the controllers is a docker container with the same hostname which can be accessed from my laravel docker container.
Not working example
.env
ADLDAP_ACCOUNT_PREFIX=""
ADLDAP_ACCOUNT_SUFFIX=""
ADLDAP_CONTROLLERS="openldap"
ADLDAP_PORT=389
ADLDAP_TIMEOUT=5
ADLDAP_BASEDN="dc=company,dc=com"
ADLDAP_ADMIN_ACCOUNT_PREFIX=""
ADLDAP_ADMIN_ACCOUNT_SUFFIX=""
ADLDAP_ADMIN_USERNAME="cn=admin,dc=company,dc=com"
ADLDAP_ADMIN_PASSWORD="secret"
ADLDAP_USE_SSL=false
ADLDAP_USE_TLS=false
ADLDAP_FOLLOW_REFERRALS=false
ADLDAP_ELOQUENT_USERNAME=username
ADLDAP_PASSWORD_SYNC=true
ADLDAP_LOGIN_FALLBACK=true
AuthController.php
public function login(Request $request, AdldapInterface $ldap)
{
// does not work - "Invalid DN syntax" error appears
dd($ldap->search()->all());
}
Creating a custom instance of the Provider - working example
AuthController.php
public function login(Request $request)
{
$config = [
// Mandatory Configuration Options
'domain_controllers' => ['openldap'],
'base_dn' => 'dc=company,dc=com',
'admin_username' => 'cn=admin,dc=company,dc=com',
'admin_password' => 'secret',
// Optional Configuration Options
'account_prefix' => '',
'account_suffix' => '',
'admin_account_suffix' => '',
'port' => 389,
'follow_referrals' => false,
'use_ssl' => false,
'use_tls' => false,
];
$schema = new OpenLDAP();
// this works
$provider = new \Adldap\Connections\Provider($config, null, $schema);
// this also works
$provider->auth()->attempt('cn=mySecondUserIveCreated,dc=company,dc=com', 'secret');
// and yes, this also works
dd($provider->search()->all());
}
I figured out that the default provider always contains the admin username "admin". Prefixes/Postfixes are also not set at all.
public function login(Request $request, AdldapInterface $ldap)
{
// does not work - "Invalid DN syntax" error appears:
var_dump($ldap->search()->all());
// does work:
var_dump($ldap->connect('default','cn=admin,dc=company,dc=com', 'secret')->search()->all());
}
Hi @renepardon,
In your adldap.php config, do you have auto_connect set to true or false?
Judging by your second comment, it looks like you may have set it to false and connecting manually works because the configured instance isn't actually bound.
Hi @stevebauman
auto_connect is set to true.
I'm not sure right now but it may be a caching issues with my docker container. After removing and re-building it, it seems to work. So maybe the bound volume has had a problem. But I will double check this.