0

我正在 Symfony3 中编写一个测试应用程序,我试图在FOSUserBundle我发现这个 Symfony ldap Bundle 的基础上设置 LDAP 用户身份验证:FR3DLdapBundle我遵循了文档并且“我认为我设置正确”。一旦我完成了此处指定的配置,当我刷新我的页面时,什么也没有发生,也没有错误。为了检查是否发生了任何事情,我使用 Wireshark 来跟踪是否有 LDAP 调用/包但什么也没有。

安全.yml:

security:
    erase_credentials: false

    firewalls:
        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

    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


    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 }

`conig.yml:

fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: Test\TestBundle\Entity\User

# app/config/config.yml
fr3d_ldap:
      driver:
          host:                ldap.forumsys.com
  #       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`

这个捆绑包的文档很差,但我在谷歌 ldap Symfony 上的每个人都建议使用它。

问题 1. 我如何检查或知道正在发生的事情......?

让我们假设它可以工作,然后我创建了一个这样的服务:

`        <!-- LDAP Connection -->
        <service id="test.testldap.ldap_adapter"
                 class="Test\TestBundle\CambioLDAP\LdapAdapter">
            <argument type="service" id="fr3d_ldap.driver"/>
        </service>`

还添加了 LdapAdapter:

<?php

namespace Test\TestBundle\CambioLDAP;

use FR3D\LdapBundle\Model\LdapUserInterface;

class LdapAdaptor
{
    private $ldap;

    public function __construct
    (
        LdapUserInterface $userInterface
    ) {
        $this->ldap = $userInterface;
    }
} 

甚至不确定我是否应该使用它的 LdapUserInreface 它只给了我两个选择:

getDn
setDN

无论哪种方式,Symfony 都会给我这个错误:

The service "test.testldap.ldap_adapter" has a dependency on a non-existent service "fr3d_ldap.driver".

当然 fr3d_ldap.driver 来自 config.yml。

Question2 我应该扩展哪些课程

对不起这个问题的长度,但似乎 Symfony2-3 很少被 LDAP 以及这个捆绑包所覆盖,使用直接 php 来做到这一点会不会更容易......?

4

1 回答 1

0

问题一

您可以在控制台中检查的已加载服务列表:

php 应用程序/控制台调试:容器 | grep YOUR_SERVICE_ID

也许您的带有服务的 xml 文件没有加载?检查 YourBundle\DependencyInjection\YourBundleExtension 文件正在加载哪个服务文件。

于 2016-06-09T12:49:59.643 回答