Can't connect to ldap server with symfony ldap

1.8k views Asked by At

I have site on symfony 4 and i want to authenticating against an LDAP server, use symfony ldap component. I did everything step by step as written in the official documentation https://symfony.com/doc/current/security/ldap.html

I have the next error:

"exception" => BadCredentialsException {#268 ▼
    -token: UsernamePasswordToken {#260 …}
    #message: "Bad credentials."
    #code: 0
    #file: "/var/www/dev.apps/vendor/symfony/security/Core/Authentication/Provider/UserAuthenticationProvider.php"
    #line: 67
    -previous: Use

rnameNotFoundException {#280 …} trace: {▶}

My services.yaml:

parameters:
    locale: 'en'    
services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

    Symfony\Component\Ldap\Ldap:
        arguments: ['@Symfony\Component\Ldap\Adapter\ExtLdap\Adapter']
    Symfony\Component\Ldap\Adapter\ExtLdap\Adapter:
        arguments:
        -   host: example.com
            port: 389
            #encryption: none
            options:
                protocol_version: 3
                referrals: false

My security.yaml

security:
#    encoders:
#        App\Entity\User:
#            algorithm: plaintext

    providers:
#        in_memory: { memory: ~ }
        my_ldap:
            ldap:
                service: Symfony\Component\Ldap\Ldap
                base_dn: DC=example,DC=com
                search_dn: "[email protected]"
                search_password: somepass
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: ~
            logout:    true

            form_login_ldap:
                provider:  my_ldap
                service: Symfony\Component\Ldap\Ldap
                login_path: login
                check_path: login
                dn_string: '{username}'
    access_control:
#        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
#        - { path: ^/, roles: ROLE_USER }
1

There are 1 answers

0
Allan On

The symfony LDPA Component works fine for me.

Have you follow the documentation : https://symfony.com/doc/current/security/ldap.html ?

However, can you post the services.yaml and security.yaml files ?