我正在尝试在我的Symfony 2.8应用程序中使用LdapClient实现FosRestBundle。我想在应用程序启动时自动登录我的LDAP用户并使用此用户凭据我想搜索其他REST api用户的信息。
我的服务和安全基于 Authenticating against an LDAP server from security component和Ldap Component informations from Symfony Blog。
我的ldap服务看起来像这样:
ldap:
class: Symfony\Component\Ldap\LdapClient
arguments:
- ldap.myserver.com # host
- 3268 # port
- 3 # version
- false # SSL
- false # TLS
和我的提供者:
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
我的防火墙:
firewalls:
api:
provider: ldap_users
stateless: true
pattern: ^/api
http_basic_ldap:
service: ldap
dn_string: "{username}@mydaomain.domain.com"
配置非常明确,我希望lsdap服务提供所有/api
个网址,我希望使用ldap提供商凭据。
现在,当我试图访问我的http://localhost:8399/api/v1/users/1
网址时,我从浏览器获取需要身份验证的信息,我必须提供用户名和密码。在dev.log
文件中,我可以看到
[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. [] []
我的问题是,如何使用Symfony LdapClient和来自提供者和服务的凭据启用自动登录应用程序。