Symfony-针对LDAPserver进行身份验证

时间:2018-09-12 10:23:01

标签: symfony openldap

我正在尝试根据LDAP伺服器对用户进行身份验证。

security:
    providers:
        my_ldap:
            ldap:
                service: Symfony\Component\Ldap\Ldap
                base_dn: 'DC=maxcrc,DC=com'
                search_dn: 'CN=manager,DC=maxcrc,DC=com'
                search_password: 'secret'
                default_roles: ROLE_USER
...
    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            anonymous: ~

            form_login_ldap:
                #http_basic_ldap:
                login_path: login
                check_path: login
                service: Symfony\Component\Ldap\Ldap
                dn_string: 'maxcrc\{username}'

my services.yml:

...

    Symfony\Component\Ldap\Ldap:
        arguments: ['@Symfony\Component\Ldap\Adapter\ExtLdap\Adapter']
    Symfony\Component\Ldap\Adapter\ExtLdap\Adapter:
        arguments:
        -   host: localhost
            port: 389
            #encryption: tls
            options:
                protocol_version: 3
                referrals: false`

似乎完全遵循了symfony的指示。我可以绑定到服务器,但是每当我提交表单时都会收到无效的凭证错误! 请提供相应的帮助!

1 个答案:

答案 0 :(得分:0)

您在ldap定义中缺少uid_key

security:
    providers:
        my_ldap:
            ldap:
                service: Symfony\Component\Ldap\Ldap
                base_dn: 'DC=maxcrc,DC=com'
                search_dn: 'CN=manager,DC=maxcrc,DC=com'
                search_password: 'secret'
                default_roles: ROLE_USER
                uid_key: 'samaccountname'

除此之外,我还有以下设置:

    firewalls:
      dev:
          pattern: ^/(_(profiler|wdt)|css|images|js)/
          security: false
      main:
          anonymous: ~
          form_login_ldap:
              service: Symfony\Component\Ldap\Ldap
              login_path: login
              check_path: login
              dn_string: '%env(ADLDAP_BASEDN)%'
              query_string: '(samaccountname={username})'
          logout:
              path: /logout
              target: login

相关的是dn_stringquery_string。不确定是否所有必要,这是我第一次使用symfony。

ADLDAP_BASEDN在我的.env文件中定义为:

ADLDAP_BASEDN=DC=blah,DC=example,DC=com

修改 抱歉,我误读了您的问题,以某种方式我认为您是根据Active Directory进行身份验证的。使用openldap时,uid键应为uid,这很可能是默认键。但是您的dn_string在我看来错了,也许还需要query_string。明天不在手机上时,我将相应地编辑答案。

相关问题