/**
  * Register the service provider.
  */
 public function register()
 {
     // Bind the Adldap instance to the IoC
     $this->app->singleton('adldap', function (Application $app) {
         $config = $app->make('config')->get('adldap');
         // Verify configuration exists.
         if (is_null($config)) {
             $message = 'Adldap configuration could not be found. Try re-publishing using `php artisan vendor:publish --tag="adldap"`.';
             throw new ConfigurationMissingException($message);
         }
         // Create a new connection Manager.
         $manager = new Manager();
         // Retrieve the LDAP connections.
         $connections = $config['connections'];
         // Go through each connection and construct a Provider.
         foreach ($connections as $name => $settings) {
             $configuration = new Configuration($settings['connection_settings']);
             $connection = new $settings['connection']();
             $schema = new $settings['schema']();
             // Construct a new connection Provider with its settings.
             $provider = new Provider($configuration, $connection, $schema);
             if ($settings['auto_connect'] === true) {
                 // Try connecting to the provider if `auto_connect` is true.
                 $provider->connect();
             }
             // Add the Provider to the Manager.
             $manager->add($name, $provider);
         }
         return new Adldap($manager);
     });
     // Bind the Adldap contract to the Adldap object
     // in the IoC for dependency injection.
     $this->app->singleton(AdldapInterface::class, 'adldap');
 }
Example #2
0
 public function test_config_login_fallback_no_connection()
 {
     $this->app['config']->set('adldap_auth.login_fallback', true);
     $mockedProvider = $this->mock(Provider::class);
     $mockedSearch = $this->mock(Factory::class);
     $mockedConnection = $this->mock(ConnectionInterface::class);
     $mockedConnection->shouldReceive('isBound')->once()->andReturn(false);
     $mockedSearch->shouldReceive('select')->once()->andReturn($mockedSearch);
     $mockedSearch->shouldReceive('users')->once()->andReturn($mockedSearch);
     $mockedSearch->shouldReceive('getConnection')->once()->andReturn($mockedConnection);
     $manager = new Manager();
     $manager->add('default', $mockedProvider);
     $mockedProvider->shouldReceive('search')->once()->andReturn($mockedSearch);
     Adldap::shouldReceive('getManager')->andReturn($manager);
     EloquentUser::create(['email' => '*****@*****.**', 'name' => 'John Doe', 'password' => bcrypt('Password123')]);
     $credentials = ['email' => '*****@*****.**', 'password' => 'Password123'];
     $outcome = Auth::attempt($credentials);
     $user = \Auth::user();
     $this->assertTrue($outcome);
     $this->assertInstanceOf('Adldap\\Laravel\\Tests\\Models\\User', $user);
     $this->assertEquals('*****@*****.**', $user->email);
 }