Env set default" connection persists over app specific one #828
Description
- Laravel Version: 6.0
- Adldap2-Laravel Version: 6.0
- PHP Version: 7.3.5
- LDAP Type: ActiveDirectory / OpenLDAP / FreeIPA
Description:
I have two different LDAP connections that I would like to use simultaneously but I know this is not supported yet.
I can set either using .env values and new users are created and persisted to the database. That means both are valid connections.
If I set one in .env and then replace the default with the other one in AppServiceProvider, then neither one will authenticate new users.
The data for the replacement connection is coming from a DB record and I can see it is correctly replacing all the required values (hosts, baseDn, username, password) by using:
ddd(Adldap::addProvider($this->toArray()));
By turning logging on, I can see that when I submit the login request there are binding requests to the original default provider provided from the .env file but the lookup of the new user is attempted with the new connection. It doesn't work though as it then seems to attempt to authenticate against the original connection.
local.INFO: LDAP (ldap://env.set.connection:389) - Connection: default - Operation: Binding - Username: CN=LDAP USER,CN=Users,DC=env,DC=connection local.INFO: LDAP (ldap://env.set.connection:389) - Connection: default - Operation: Bound - Username: CN=LDAP USER,CN=Users,DC=env,DC=connection local.INFO: LDAP (ldap://appserviceprovider.set.connection.from.db:389) - Connection: default - Operation: Search - Base DN: OU=Staff,OU=Users,OU=Network,DC=appserviceprovider,DC=set,DC=connection - Filter: (&(objectclass=user)(objectcategory=person)(!(objectclass=contact))([email protected])) - Selected: (*,objectguid) - Time Elapsed: 35.75 local.INFO: LDAP (ldap://env.set.connection:389) - Connection: default - Operation: Binding - Username: CN=LDAP USER,CN=Users,DC=env,DC=connection local.INFO: LDAP (ldap://env.set.connection:389) - Connection: default - Operation: Bound - Username: CN=LDAP USER,CN=Users,DC=env,DC=connection local.INFO: LDAP (ldap://env.set.connection:389) - Connection: default - Operation: Binding - Username: CN=LDAP USER,CN=Users,DC=env,DC=connection local.INFO: LDAP (ldap://env.set.connection:389) - Connection: default - Operation: Bound - Username: CN=LDAP USER,CN=Users,DC=env,DC=connection
I've looked through the various issues and comments on multiple providers as well as all the docs but cant work out what mistake I'm making. Given the provider does seem to be properly replaced I think it's a bug.
The workaround is of course to only configure the connection in .env (or presumably as the default in the config file with no env values set). This isn't very helpful as ideally the user of app would be able to configure and change the connection themselves without having to access .env variables.
Apart from that everything works flawlessly!!