Symfony2 img/LdapBundle Bad credentials error

2019-07-12 02:25发布

问题:

I am new to Symfony2 and am trying to connect to ldap using the above bundle; however i keep getting Bad credentials errors. I cannot figure out why..

My Security.yml file looks like this:

security:
firewalls:
    restricted_area:
        pattern:          ^/login
        anonymous:        ~
        imag_ldap:
            check_path: login_check
            login_path: login
            csrf_provider: form.csrf_provider
            intention: authenticate
            provider: ldap
        logout:
            path:           /logout
            target:         /

providers:
    ldap:
        id: imag_ldap.security.user.provider

encoders:
    IMAG\LdapBundle\User\LdapUser: plaintext

access_control:
    - { path: ^/login,          roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/,               roles: IS_AUTHENTICATED_FULLY }

imag_ldap:
client:
    host: someip
    port: 389
#    version: 3 # Optional
#    username:  
#    password: 
#    network_timeout:
#    referrals_enabled:
#    bind_username_before:
#    skip_roles:

user:
    base_dn: dc=some, dc=dom, dc=ain
#    filter: null
    name_attribute: uid
#    attributes:

role:
    base_dn: dc=some, dc=dom, dc=ain
#    filter: null #Optional
    name_attribute: cn
    user_attribute: member
#    user_id: [ dn or username ] #Default dn

my routes are as follows:

login:
    pattern:              /login
    defaults:             { _controller: IMAGLdapBundle:Default:login }
    requirements:
    _method:            GET

login_check:
    pattern:              /login_check

logout:
    pattern:              /logout

I cant seem to test if its actually connecting but when i try to go to http://domain/app_dev.php/check_login i get the following error:

Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration?

Im guessing i need to add a route for /login_check but not sure. and if so how to i call the ldap connection?

EDIT

OK I think I need hand holding.. I have changed my security.yml to the following:

security:
    firewalls:
        login_firewall:
            pattern:    ^/login$
            anonymous:  ~
            imag_ldap:
                check_path: login_check
                login_path: login
                csrf_provider: form.csrf_provider
                intention: authenticate
                provider: ldap
            logout:
                path:           /logout
                target:         /
        restricted_area:
            pattern:          ^/
            #anonymous:        ~ 
    providers:
        ldap:
           id: imag_ldap.security.user.provider

    encoders:
        IMAG\LdapBundle\User\LdapUser: plaintext

    access_control:
        - { path: ^/login,          roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/,               roles: IS_AUTHENTICATED_FULLY }

but now im getting the following error: LogicException: No authentication listener registered for firewall "restricted_area".

SO i tried the following:

security:
    firewalls:
        login_firewall:
            pattern:    ^/login$
            anonymous:  ~
            imag_ldap:
                check_path: login_check
                login_path: login
                csrf_provider: form.csrf_provider
                intention: authenticate
                provider: ldap
            logout:
                path:           /logout
                target:         /
        restricted_area:
            pattern:          ^/
            #anonymous:        ~ 
            imag_ldap:
                check_path: login_check
                login_path: login
                csrf_provider: form.csrf_provider
                intention: authenticate
                provider: ldap
            logout:
                path:           /logout
                target:         /

but this causes a redirect loop.

Edit 2 As mentioned in the comments the second part of this is a separate issue, which can be found here:Symfony 2 Security.yml redirect loop and LogicException issues

回答1:

You need to put login_check behind your firewall as well:

firewalls:
    restricted_area:
        pattern: ^/
        #anonymous: ~
    login_firewall:
            pattern:    ^/login$
            anonymous:  ~

BTW, this is a common pitfall listed in the Avoid Common Pitfalls section.

There is something similar that might help you here.



标签: symfony ldap