Symfony3 FSOUserbundle和FR3LdapBundle配置

时间:2016-06-01 17:23:23

标签: php ldap symfony

处理Symfony3项目并尝试结合使用这两个捆绑包通过LDAP验证用户再次目录服务:

FR3DLdapBundle
FOSUserBundle 

我已经按照文档来配置这些FSOUserBundel在ints中运行正常,当我根据Docks添加FR3DLdapBundle时,我留下了这个错误:

    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。我确实清除了缓存。

现在我觉得我可能有错误的文件是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

和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 }

任何想法的人?感谢

3 个答案:

答案 0 :(得分:0)

我认为这是因为FR3DLdapBundle并不完全支持Symfony3。早期的2.8版本类Symfony \ Bridge \ Monolog \ Logger实现了扩展Psr \ Log \ LoggerInterface的Symfony \ Component \ HttpKernel \ Log \ LoggerInterface,在Symfony 3类中只实现了没有扩展任何东西的Symfony \ Component \ HttpKernel \ Log \ DebugLoggerInterface ,它只是一个界面。并且在FR3DLdapBundle类FR3D \ LdapBundle \ Driver \ ZendLdapDriver期望作为第二个参数Psr \ Log \ LoggerInterface。就是这样。

您可以在github page

上将其写为问题

或者您可以分叉他们的仓库,修复预期的参数here并提出拉取请求。在此期间使用您的捆绑包,然后在他们接受并合并您的请求时将其更改回他们的

答案 1 :(得分:0)

为什么不通读我的博客Symfony AD Integration

我在你的&#34; config.yml&#34;文件,你已经&#34; fr3d_ldap:&#34;两次。那可能是个问题...

我建议使用我在博客中显示的LDAP测试服务器来验证工作是否正常,然后您可以转到自己的AD服务器。

答案 2 :(得分:0)

万一其他人仍在尝试从Symfony 2.8升级到3.4并遇到FR3DLdapBundle的问题,如原始文章所示:

1)使用作曲家将FR3DLdapBundle从v2.0升级到v3.0

这应该删除原始海报在上述问题中看到的错误。

2)在您的Symfony app / config.yml中,在FR3DLdapBundle的设置下,在“用户”部分下添加“ usernameAttribute”设置,并将其设置为“ sAMAccountName”

示例:

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 }

如果您使用的是较旧版本的捆绑软件,则您的配置中可能没有此设置,因此将需要它才能使其正常运行。我在这里找到了此解决方案:https://github.com/Maks3w/FR3DLdapBundle/issues/131

这两个更改共同解决了我的问题,使我可以在Symfony 3.4上使用FR3DLdapBundle