简体   繁体   中英

Symfony 4 LDAP authentication

I am currently trying to implement an LDAP authentication using the Symfony built-in module. I followed this tutorial : http://symfony.com/doc/current/security/ldap.html

But I can't make it work, and most of the research I have made concern Symfony 2.8 and none of this worked.

Here are my settings:

config/services.yaml

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

Symfony\Component\Ldap\Adapter\ExtLdap\Adapter:
    arguments:
        -   host: ######
            port: 389
            encryption: tls
            options:
                protocol_version: 3
                referrals: false

config/packages/security.yaml

providers:
        app_users:
            ldap:
                service: Symfony\Component\Ldap\Ldap
                base_dn: 'DC=company,DC=com'
                search_dn: 'CN=######,DC=company,DC=com'
                search_password: '#######'
                uid_key: 'sAMAccountName'
                filter: '({uid_key}={username})'
                default_roles: 'ROLE_USER'
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            anonymous: false

            http_basic_ldap:
                provider: app_users
                service: Symfony\Component\Ldap\Ldap
                dn_string: '{username}'

currently with this configuration I do have this error:

Warning: ldap_start_tls(): Unable to start TLS: Connect error

I found no workarround yet, so I tried to replace TLS by SSL in the services.yaml file (I think it does not do anything by the way).

With the SSL argument it loop me to connect.

I also use the PHP function ldap_connect() to make sure my LDAP server works and it does.

If any one has any ideas?

EDIT: using SSL the log file returns always the same issue (the credentials are correct)

[2018-01-04 13:30:36] security.INFO: Basic authentication Authorization header found for user. {"username":"#######"} []
[2018-01-04 13:30:36] php.DEBUG: Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server ...
[2018-01-04 13:30:36] security.INFO: Basic authentication failed for user. {"username":"#######","exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\BadCredentialsException(code: 0): Bad credentials. : User \"######\" not found. : Can't contact LDAP server

Happy new year and thanks in advance. AM.

我有同样的问题,只是删除了加密:“ Symfony \\ Component \\ Ldap \\ Adapter \\ Ext Ldap \\ Adapter”的参数中的tls,

Just remove ;

encryption: tls

from services.yaml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM