cezar
cezar

Reputation: 12032

Authentication with the new LDAP component in Symfony 2.8

I wanted to try the new LDAP component in Symfony 2.8 and started to play with it few days ago. However I don't really get it and have problems to authenticate the users. I have followed this article: http://symfony.com/blog/new-in-symfony-2-8-ldap-component

Here are my configuration files:

# app/config/services.yml
services:
    app.ldap:
        class: Symfony\Component\Ldap\LdapClient
        arguments: ["ldaps://ldap.uni-rostock.de"]

and:

# app/config/security.yml
security:
    providers:
        # in_memory:
        #    memory: ~
        app_users:
            ldap:
                service: app.ldap
                base_dn: ou=people,o=uni-rostock,c=de
                search_dn: uid=tester,ou=people,o=uni-rostock,c=de
                search_password: testpass
                #filter: (sAMAccountName={username})
                filter: (uid={username})
                default_roles: ROLE_USER

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        admin:
            provider:  app_users
            stateless: true
            pattern:   ^/admin
            http_basic_ldap:
                service: app.ldap
                dn_string: "{username}"

Here is a guide (only in German, but the essential part is the code) to connecting to the server: http://www.itmz.uni-rostock.de/en/software/windows/universitaetsweite-dienste/ldap-authentifizierungsserver/

When I run the server like this: php app/console server:run -vvv and open http://localhost:8000/admin I'm prompted to enter the credentials. Unfortunately I'm not passing through even though I tried many times and I'm very sure I didn't make a typo. In the console there is only this relevant line:

[Fri Mar 11 08:39:32 2016] 127.0.0.1:36632 [401]: /admin

I'm unauthorized (401) and prompted again to enter the credentials.

Am I maybe missing something? I have tried many different combinations, put the values in quotes, tried to add:

access_control:
    - { path: ^/admin, roles: ROLE_USER }

to the security.yml, but it didn't help.

There is also another question with somewhat similar problematic:

LDAP Authentication with Symfony 2.8

but I couldn't really move further.

Does someone maybe have an idea what else could I try?

Upvotes: 3

Views: 1698

Answers (1)

ChadSikorra
ChadSikorra

Reputation: 2869

Just for reference, adding this in as the answer:

The issue would be dn_string: "{username}". Unless you're typing a full DN when prompted for a username/password, this will not work. For example, if all your users are in a common OU/container you could make it something like: dn_string: uid={username},ou=people,o=uni-rostock,c=de.

Glad this fixed it!

Upvotes: 3

Related Questions