Symfony 4 FOSUser and LDAP Trying to override LDAPUserProvider

I’m developing a website using FOSUser and LDAP autentication. The problem is, in the ProfileController to access the profile of the user it checks that the user is an instance of FOSUserBundleUserInterface. But since there are LDAP users, they are instances of Symfony…UserInterface and they get the error "this user doesn’t have access" when trying to see their profiles.
So I tried to override LDapUser and LDapUserProvider and in my services.yml:

     AppSecurityLdapUserProvider:
        arguments:
            - $ldap: '@SymfonyComponentLdapLdap'
            - $baseDn: 'OU=xxx,DC=xxx,DC=xx'
            - $searchDn: '[email protected]'
            - $searchPassword: 'xxx'
            - $defaultRoles:
               'ROLE_USER'
            - $uidKey: 'xxx'
            - $filter: '{uid_key}={username}'
    SymfonyComponentLdapLdap:
        arguments: ['@SymfonyComponentLdapAdapterExtLdapAdapter']
    SymfonyComponentLdapAdapterExtLdapAdapter:
        arguments:
            - host: "xxx"
              port: xxx
              encryption: none
              options:
                protocol_version: 3
                referrals: false

And in the security.yml:

security:
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username 
        intranet_ldap:
            id: AppSecurityLdapUserProvider

    firewalls:
        main:
            pattern:            ^/
            context:            user
            anonymous:          true
            form_login_ldap:
                service:        SymfonyComponentLdapLdap
                provider:       intranet_ldap
                login_path:     /login
                check_path:     /login_check
                dn_string:      'DC=xxx, DC=xxx'
                query_string:   '(&(xxx={username}))'

But then I get the error "Argument 1 passed to AppSecurityLdapUserProvider::__construct() must be an instance of SymfonyComponentLdapLdap, array given, called in /var/www/intranet/var/cache/dev/ContainerZEzZ03v/getLdapUserProviderService.php on line 13".

Does anyone has an idea to resolve this?

Thanks

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *