Symfony3 imag ldap设置配置

时间:2016-06-08 17:06:24

标签: php ldap symfony

编写一个Symfony3应用程序,需要通过LDAP连接到AD以登录用户。我做了一些谷歌搜索并发现:{{3}}所以我已经遵循了这个文档,但得到了这个错误:

Whoops, looks like something went wrong.

1/1
ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php line 58:
The service "security.firewall.map.context.restricted_area" has a dependency on a non-existent service "security.context".
in CheckExceptionOnInvalidReferenceBehaviorPass.php line 58

at CheckExceptionOnInvalidReferenceBehaviorPass->processReferences(array(object(Reference), object(Reference), object(Reference), object(Definition), 'restricted_area', object(Definition), object(Definition), array('check_path' => '/login_check', 'use_forward' => false, 'require_previous_session' => true, 'username_parameter' => '_username', 'password_parameter' => '_password', 'csrf_parameter' => '_csrf_token', 'intention' => 'ldap_authenticate', 'post_only' => true), object(Reference), object(Reference))) in CheckExceptionOnInvalidReferenceBehaviorPass.php line 42
at CheckExceptionOnInvalidReferenceBehaviorPass->processDefinition(object(Definition)) in CheckExceptionOnInvalidReferenceBehaviorPass.php line 53
at CheckExceptionOnInvalidReferenceBehaviorPass->processReferences(array(object(Definition), object(Definition), object(Definition), object(Definition), object(Definition), object(Definition))) in CheckExceptionOnInvalidReferenceBehaviorPass.php line 51
at CheckExceptionOnInvalidReferenceBehaviorPass->processReferences(array(array(object(Definition), object(Definition), object(Definition), object(Definition), object(Definition), object(Definition)), object(Definition))) in CheckExceptionOnInvalidReferenceBehaviorPass.php line 42
at CheckExceptionOnInvalidReferenceBehaviorPass->processDefinition(object(Definition)) in CheckExceptionOnInvalidReferenceBehaviorPass.php line 36
at CheckExceptionOnInvalidReferenceBehaviorPass->process(object(ContainerBuilder)) in Compiler.php line 104
at Compiler->compile(object(ContainerBuilder)) in ContainerBuilder.php line 545
at ContainerBuilder->compile() in Kernel.php line 477
at Kernel->initializeContainer() in Kernel.php line 117
at Kernel->boot() in Kernel.php line 166
at Kernel->handle(object(Request)) in app_dev.php line 30

security.yml:

# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:
    firewalls:
      restricted_area:
        pattern:          ^/
        anonymous:        ~
        provider:         ldap
        imag_ldap:        ~
            # alternative configuration
            # imag_ldap:
            #   login_path:   /ninja/login
        logout:
          path:           /logout
          target:         /

    providers:
      chain_provider:
        chain:
            providers: [fos_userbundle, ldap]
      fos_userbundle:
        id: fos_user.user_provider.username
      ldap:
        id: imag_ldap.security.user.provider

    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt
        IMAG\LdapBundle\User\LdapUser: plaintext

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, roles: IS_AUTHENTICATED_FULLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

imag_ldap:
  client:
    host: someip
    port: 389
        #    version: 3 # Optional
        #    username: foo # Optional
        #    password: bar # Optional
        #    network_timeout: 10 # Optional
        #    referrals_enabled: true # Optional
        #    bind_username_before: true # Optional
        #    skip_roles: false # Optional

  user:
    base_dn: ou=group, dc=host, dc=foo
        #    filter: (&(foo=bar)(ObjectClass=Person)) #Optional
    name_attribute: uid
  role:
    base_dn: ou=group, dc=host, dc=foo
        #    filter: (ou=group) #Optional
    name_attribute: cn
    user_attribute: member
#    user_id: [ dn || username ]

    #  user_class: IMAG\LdapBundle\User\LdapUser # Optional

据我所知,secyrity.yml依赖于上下文,但在ldap设置文档中没有提到任何关于它的内容......?

也许我做错了什么?

1 个答案:

答案 0 :(得分:0)

我认为BorisMorel / LdapBundle不适用于Symfony3;它已经多年没有更新......

我强烈建议您使用Maks3w / FR3DLdapBundle,因为维护者经常会检查Stackoverflow是否存在问题。 fr3dldapbundle on stackoverflow有一个用于发布问题的标记。