Symfony FR3DLdapBundle配置和服务

时间:2016-06-09 11:52:58

标签: php symfony fr3dldapbundle

我正在Symfony3中编写一个测试应用程序,我正在尝试在FOSUserBundle之上设置LDAP用户身份验证我找到了这个Symfony ldap Bundle:FR3DLdapBundle我按照文档和&# 39;我认为我正确设置了#39;。完成指定here的配置后,当我刷新页面时,没有任何错误发生。为了检查是否发生了任何事情,我使用Wireshark来跟踪是否存在LDAP调用/ pacage,但没有。

Security.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 }

`congig.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`

关于这个捆绑包的文档很差但是每个人都建议我google 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。

问题2我应该扩展哪些课程

很抱歉这个问题的长度但似乎Symfony2-3很难被LDAP以及这个捆绑包覆盖,使用直接php更容易使用这个...?

1 个答案:

答案 0 :(得分:0)

问题1

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

php app / console debug:container | grep YOUR_SERVICE_ID

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