Symfony4-AD / LDAP-身份验证:无效的凭据

时间:2019-06-17 08:42:30

标签: symfony authentication active-directory ldap symfony4

我正在尝试在AD / LDAP上进行身份验证,但响应始终是我具有无效的凭据。有什么问题吗?

这是我的代码: services.yaml

    Symfony\Component\Ldap\Ldap:
    arguments: ['@Symfony\Component\Ldap\Adapter\ExtLdap\Adapter']

Symfony\Component\Ldap\Adapter\ExtLdap\Adapter:
    arguments:
        -   host: samba4-ip
            port: 389
            options:
                protocol_version: 3
                referrals: false

security.yaml

    providers:
    m-ad:
        ldap:
            service: Symfony\Component\Ldap\Ldap
            base_dn: 'DC=my_domain,DC=fr'
            search_dn:  'CN=adminad,CN=Users,DC=my_domain,DC=fr'
            search_password: 'my_password'
            uid_key: 'sAMAccountName'
            filter: '({uid_key}={username})'
            default_roles: 'ROLE_USER'

....

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        anonymous: true

        form_login_ldap:
            provider: m-ad
            login_path: login
            check_path: login
            service: Symfony\Component\Ldap\Ldap
            dn_string: 'DC=my_domain,DC=fr'
            query_string: '(&(sAMAccountName={username})(memberOf=CN=informatique,CN=Users,DC=my_domain,DC=fr))'

login.twig

{% extends 'base.html.twig' %}
{% block body %}
<form action="{{ path('login') }}" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />
</br>
<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
</br>
<button type="submit">login</button>
</br>
{% if error %}
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
</form>
{% endblock %}
{% block stylesheets %}
{% endblock %}

如果有人有主意...

1 个答案:

答案 0 :(得分:0)

答案是,我的search_dn不好,应该看起来像:adminad@my_domain.fr