Configuring LDAP authentication with Silex and Symfony 3
Silex security configuration works otherwise.
User providers are defined as $app['security.user_provider.%firewall_name%']
, not as provider
key in firewall config.
Try to change your config to:
$app['ldap'] = $app->share(function() { return new Symfony\Component\Ldap\LdapClient('ldap.example.com');});$app['security.user_provider.stats'] = $app->share(function($app) { return new \Symfony\Component\Security\Core\User\LdapUserProvider( $app['ldap'], 'dc=example,dc=com', null, null, ['ROLE_USER'], 'CN' );});$app['security.authentication_provider.stats.dao'] = function () use ($app) { return new \Symfony\Component\Security\Core\Authentication\Provider\LdapBindAuthenticationProvider( $app['security.user_provider.stats'], $app['security.user_checker'], 'stats', $app['ldap'], 'CN={username},OU=DEV,DC=example,DC=com', $app['security.hide_user_not_found'] );};$app->register(new Silex\Provider\SecurityServiceProvider(), [ 'security.firewalls' => [ 'stats' => [ 'pattern' => '^/', 'http' => true, 'stateless' => true, ], ],]);
UPDATE: Or better use this decision Symfony LDAP auth bind with username and password. I think that it is better.