Symfony3 LDAP用户身份验证

时间:2016-05-31 11:29:00

标签: php symfony ldap

我正在编写一个Symfony3应用程序,并希望为用户登录配置LDAP连接。

所以我需要连接到服务目录获取用户对象并检查该对象天气用户名和密码再次匹配用户登录页面输入。

为了达到这个目的,我们计划使用这两个组合的组合:

FR3DLdapBundle
FOSUserBundle

但有一点我不明白,即:对于FOSU​​serBundle我会创建用户实体,这个用户实体类参数是否需要exacley作为SD对象的属性?

我也有一个应用程序数据库我只想使用LDAP连接来验证用户,因为那里存储了用户名和密码。

你能帮我理解这个过程吗。

Symfony LDAP componetn错误:

所以我按照SYmfony文档复制了代码但是仍然得到了这个错误信息,即使代码是相同的:

ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php line 58:
The service "security.authentication.manager" has a dependency on a non-existent service "app.ldap".
in CheckExceptionOnInvalidReferenceBehaviorPass.php line 58
at CheckExceptionOnInvalidReferenceBehaviorPass->processReferences(array(object(Reference), object(Reference), 'api', object(Reference), '{username}@example', true)) 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))) in CheckExceptionOnInvalidReferenceBehaviorPass.php line 51
at CheckExceptionOnInvalidReferenceBehaviorPass->processReferences(array(array(object(Definition), object(Definition), object(Definition)), true)) 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
at require('app_dev.php') in router_dev.php line 40

应用程序/配置/ services.yml:

services:
    app.ldap:
        class: Symfony\Component\Security\Ldap\Ldap
        arguments: [ "ldap.example.com" ]

应用程序/配置/ security.yml:

# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:

    # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
    providers:
#        in_memory:
#            memory: ~
        app_users:
            ldap:
                service: app.ldap
                base_dn: dc=example,dc=com
                search_dn: CN=My User,OU=Users,DC=example,DC=com
                search_password: p455w0rd
                filter: (sAMAccountName={username})
                default_roles: ROLE_USER
#
    firewalls:
        api:
            provider:  app_users
            stateless: true
            pattern:   ^/api
            http_basic_ldap:
                service: app.ldap
                dn_string: "{username}@example"
        backend:
            provider: app_users
            pattern:  ^/admin
            logout:
                path:   logout
                target: login
            form_login_ldap:
                service: app.ldap
                dn_string: CN={username},OU=Users,DC=example,DC=com
                check_path: login_check
                login_path: login

        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        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

0 个答案:

没有答案