working on a Symfony3 project and trying to use this two bundles in conjunction authenticate a user agains Directory service through LDAP :
FR3DLdapBundle
FOSUserBundle
I have followed the docs to config these FSOUserBundel works fine on ints own, its when i added FR3DLdapBundle according to its Docks and am left with this error:
Catchable Fatal Error: Argument 2 passed to FR3D\LdapBundle\Driver\ZendLdapDriver::__construct() must be an instance of
Symfony\Component\HttpKernel\Log\LoggerInterface, instance of
Symfony\Bridge\Monolog\Logger given, called in /Users/tomasz.koprowski/Dev/cambio-
back_end/var/cache/dev/appDevDebugProjectContainer.php on line 1729 and defined
ps. I did clear my cache.
now the file where i think i might have a mistake is security.yml:
# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:
# Preserve plain text password in token for refresh the user.
# Analyze the security considerations before turn off this setting.
erase_credentials: false
encoders:
AcmeBundle\Acme\User\LdapUser: plaintext
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
chain_provider:
chain:
providers: [fos_userbundle, fr3d_ldapbundle]
fr3d_ldapbundle:
id: fr3d_ldap.security.user.provider
fos_userbundle:
id: fos_user.user_provider.username
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
# providers:
# in_memory:
# memory: ~
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
# dev:
# pattern: ^/(_(profiler|wdt)|css|images|js)/
# security: false
main:
pattern: ^/
fr3d_ldap: ~
form_login:
always_use_default_target_path: true
default_target_path: /profile
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
# main:
# anonymous: ~
# activate different ways to authenticate
# http_basic: ~
# http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate
# form_login: ~
# http://symfony.com/doc/current/cookbook/security/form_login_setup.html
and config.yml:
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Cambio\CambioBundle\Entity\User
fr3d_ldap:
fr3d_ldap:
driver:
host: your.host.foo
# port: 389 # Optional
# username: foo # Optional
# password: bar # Optional
# bindRequiresDn: true # Optional
# baseDn: ou=users, dc=host, dc=foo # Optional
# accountFilterFormat: (&(uid=%s)) # Optional. sprintf format %s will be the username
# optReferrals: false # Optional
# useSsl: true # Enable SSL negotiation. Optional
# useStartTls: true # Enable TLS negotiation. Optional
# accountCanonicalForm: 3 # ACCTNAME_FORM_BACKSLASH this is only needed if your users have to login with something like HOST\User
# accountDomainName: HOST
# accountDomainNameShort: HOST # if you use the Backslash form set both to Hostname than the Username will be converted to HOST\User
user:
baseDn: ou=users, dc=host, dc=foo
filter: (&(ObjectClass=Person))
# usernameAttribute: uid # Optional
attributes: # Specify ldap attributes mapping [ldap attribute, user object method]
# - { ldap_attr: uid, user_method: setUsername } # Default
# - { ldap_attr: cn, user_method: setName } # Optional
# - { ldap_attr: ..., user_method: ... } # Optional
# service:
# user_hydrator: fr3d_ldap.user_hydrator.default # Overrides default user hydrator
# ldap_manager: fr3d_ldap.ldap_manager.default # Overrides default ldap manager
user:
- { ldap_attr: uid, user_method: setUsername }
- { ldap_attr: mail, user_method: setEmail }
Any idea guys? thank
I think this is because FR3DLdapBundle does not fully support Symfony3. earlier in 2.8 version class Symfony\Bridge\Monolog\Logger implemented Symfony\Component\HttpKernel\Log\LoggerInterface that extended Psr\Log\LoggerInterface, in Symfony 3 class implements only Symfony\Component\HttpKernel\Log\DebugLoggerInterface that does not extend anything, it's just an interface. And in FR3DLdapBundle class FR3D\LdapBundle\Driver\ZendLdapDriver expects as second argument Psr\Log\LoggerInterface. That's all.
You can write this as issue on their github page
Or you can fork their repo, fix expected argument here and make pull request. at the meantime work with your bundle, then change it back to theirs when they accept and merge your pull request
why don't you read through my blog Symfony AD Integration.
I see in your "config.yml" file, you've got "fr3d_ldap:" twice. That could be a problem...
I suggest using the LDAP test server I show in the blog to verify things work first, then you can move on to your own AD server.
In case anyone else is still attempting to upgrade from Symfony 2.8 to 3.4 and encountering issues with the FR3DLdapBundle as seen in the original post:
1) Upgrade FR3DLdapBundle from v2.0 to v3.0 using composer
This should remove the bug that is being seen by the original poster in their question above.
2) In your Symfony app/config.yml, under the settings for the FR3DLdapBundle, add the "usernameAttribute" setting under the "user" section, and set it to "sAMAccountName"
Example:
fr3d_ldap:
driver:
host: XX.XX.XX.XX
username: user@domain.com
password: password
accountDomainName: domain.com
accountDomainNameShort: DOMA
user:
baseDn: Ou=ListingUsers,DC=domain,DC=com
usernameAttribute: sAMAccountName
filter: (&(ObjectClass=Person))
attributes:
- { ldap_attr: samaccountname, user_method: setUsername }
If you had been using an older version of the bundle, you probably didn't have this in your configuration, and you will need it to make it work. I found this solution here: https://github.com/Maks3w/FR3DLdapBundle/issues/131
These two changes together solved my issues and made it possible for me to use FR3DLdapBundle on Symfony 3.4