I'm trying to implement FosRestBundle with LdapClient in my Symfony 2.8 application. I want to auto login my LDAP user when application starts and using this user credentials i want to search other REST api user's informations.
I've creadet service and security based on Authenticating against an LDAP server from security component and Ldap Component informations from Symfony Blog.
My ldap service looks like this:
ldap:
class: Symfony\Component\Ldap\LdapClient
arguments:
- ldap.myserver.com # host
- 3268 # port
- 3 # version
- false # SSL
- false # TLS
and my providers:
providers:
ldap_users:
ldap:
service: ldap
base_dn: dc=myportal,dc=url,dc=com
search_dn: mysuperuser
search_password: mysuperpassword
filter: (sAMAccountName={username})
default_roles: ROLE_USER
And my firewall:
firewalls:
api:
provider: ldap_users
stateless: true
pattern: ^/api
http_basic_ldap:
service: ldap
dn_string: "{username}@mydaomain.domain.com"
Configuration is preety staightforward, I want all /api
url's to be provided by lsdap service and I want use ldap provider credentials.
Now when I'm trying to get on my http://localhost:8399/api/v1/users/1
url I'm getting information from browser that Authentication is required and I have to provide username and password . In dev.log
file I can see
[2016-12-21 14:23:53] request.INFO: Matched route "application_app_v1_user_getuser". {"route_parameters":{"_controller":"Application\\AppBundle\\Controller\\V1\\UserController::getUserAction","id":"1","_route":"application_app_v1_user_getuser"},"request_uri":"http://localhost:8399/api/v1/users/1"} []
[2016-12-21 14:23:53] security.INFO: An AuthenticationException was thrown; redirecting to authentication entry point. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationCredentialsNotFoundException(code: 0): A Token was not found in the TokenStorage. at /var/www/symfony/backend/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php:53)"} []
[2016-12-21 14:23:53] security.DEBUG: Calling Authentication entry point. [] []
My question is , how to enable autologin to application using Symfony LdapClient and with credentials from provider and service.