Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the display name using memory provider in Symfony2

I am currently trying to create some tests for an application, but I'm stuck on authentication.

In the app I use ldap authentication, which also determines the role of each user. It works well, but to simplify the testing (and to not use real users) I use the in_memory provider in my tests.

The problem is that in my views I use {{ app.user.displayname }}, and the display name is not available with the in_memory provider.

Is there a way to add it ? For example this solution (which does not work) would be perfect :

providers:
    in_memory:
        memory:
            users:
                john:  { password: john, roles: 'ROLE_USER', displayname: 'John Doe' }
                admin:  { password: admin, roles: 'ROLE_ADMIN', displayname: 'Admin' }
like image 286
ncrocfer Avatar asked Jan 26 '26 21:01

ncrocfer


1 Answers

You could either modify the class

src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php

so it uses the displayname as well or (even better) create your own class which will extend the InMemoryUserProvider and use your own provider (http://symfony.com/doc/current/cookbook/security/custom_provider.html)

like image 53
Michal Trojanowski Avatar answered Jan 29 '26 12:01

Michal Trojanowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!