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

Multiple Connections at run-time #712

@SagePacheco

Description

@SagePacheco
  • Laravel Version: 5.8.10
  • Adldap2-Laravel Version: 6.0.2
  • PHP Version: 7.3.3
  • LDAP Type: ActiveDirectory

Description:

Hey There! I'm having an issue that I can't seem to narrow down and would really appreciate some assistance!

I am building a multi-connection AD Login and for some reason I can't get the active connection to swap at run-time as is suggested in issue #230.

Despite successfully changing the ldap_auth connection in the config during run-time, the authentication provider will always stick with the first connection on each authentication attempt. In fact, if the first connection attempt has a valid connection name, all other names on subsequent tries can be completely made-up. Which tells me that the connection is persisted somewhere and not actually read from the config on each authentication attempt.

For example, if credentials for the second domain in the list are used, all three attempts will return as false. As only the first domain connection read from the config is used.

Steps To Reproduce:

Multiple AD connections added to ldap.php file.

	'connections' => [

		'sheriff' => [

			'auto_connect' => true,
			'connection' => Adldap\Connections\Ldap::class,
			'settings' => [
				'schema' => Adldap\Schemas\ActiveDirectory::class,
				'account_prefix' => '',
				'account_suffix' => '',
				'hosts' => ['omitted'],
				'port' => 389,
				'timeout' => 5,
				'base_dn' => 'omitted',
				'username' => env('SHERIFF_ADMIN_USERNAME'),
				'password' => env('SHERIFF_ADMIN_PASSWORD'),
				'follow_referrals' => false,
				'use_ssl' => env('LDAP_USE_SSL', false),
				'use_tls' => env('LDAP_USE_TLS', false),
			],

		],

		'county' => [

			'auto_connect' => true,
			'connection' => Adldap\Connections\Ldap::class,
			'settings' => [
				'schema' => Adldap\Schemas\ActiveDirectory::class,
				'account_prefix' => '',
				'account_suffix' => '',
				'hosts' => ['omitted'],
				'port' => 389,
				'timeout' => 5,
				'base_dn' => 'omitted',
				'username' => env('COUNTY_ADMIN_USERNAME'),
				'password' => env('COUNTY_ADMIN_PASSWORD'),
				'follow_referrals' => false,
				'use_ssl' => env('LDAP_USE_SSL', false),
				'use_tls' => env('LDAP_USE_TLS', false),
			],

		],

		'cdc' => [

			'auto_connect' => true,
			'connection' => Adldap\Connections\Ldap::class,
			'settings' => [
				'schema' => Adldap\Schemas\ActiveDirectory::class,
				'account_prefix' => '',
				'account_suffix' => '',
				'hosts' => ['omitted'],
				'port' => 389,
				'timeout' => 5,
				'base_dn' => 'omitted',
				'username' => env('CDC_ADMIN_USERNAME'),
				'password' => env('CDC_ADMIN_PASSWORD'),
				'follow_referrals' => false,
				'use_ssl' => env('LDAP_USE_SSL', false),
				'use_tls' => env('LDAP_USE_TLS', false),
			],

		],

	],

Login Controller override function:

protected function attemptLogin(Request $request){
     $connections = config('ldap.connections');
     foreach($connections as $connection => $config){
          Config::set('ldap_auth.connection', $connection);
          if($this->guard()->attempt( $this->credentials($request), $request->filled('remember'))){
               return true;
          }
     }
     return false;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions