Commit bac2c455 authored by Henrik Bjornskov's avatar Henrik Bjornskov Committed by Haralan Dobrev

add test and documentation for using a service id string instead of a closure

parent dc7572ef
...@@ -495,8 +495,8 @@ Defining a custom User Provider ...@@ -495,8 +495,8 @@ Defining a custom User Provider
Using an array of users is simple and useful when securing an admin section of Using an array of users is simple and useful when securing an admin section of
a personal website, but you can override this default mechanism with you own. a personal website, but you can override this default mechanism with you own.
The ``users`` setting can be defined as a service that returns an instance of The ``users`` setting can be defined as a service or an service id that returns
`UserProviderInterface an instance of `UserProviderInterface
<http://api.symfony.com/master/Symfony/Component/Security/Core/User/UserProviderInterface.html>`_:: <http://api.symfony.com/master/Symfony/Component/Security/Core/User/UserProviderInterface.html>`_::
'users' => function () use ($app) { 'users' => function () use ($app) {
......
...@@ -278,6 +278,35 @@ class SecurityServiceProviderTest extends WebTestCase ...@@ -278,6 +278,35 @@ class SecurityServiceProviderTest extends WebTestCase
$this->assertEquals('fabien', $app['user']->getUsername()); $this->assertEquals('fabien', $app['user']->getUsername());
} }
public function testUserAsServiceString()
{
$users = array(
'fabien' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='),
);
$app = new Application();
$app->register(new SecurityServiceProvider(), array(
'security.firewalls' => array(
'default' => array(
'http' => true,
'users' => 'my_user_provider',
),
),
));
$app['my_user_provider'] = $app['security.user_provider.inmemory._proto']($users);
$app->get('/', function () { return 'foo'; });
$request = Request::create('/');
$app->handle($request);
$this->assertNull($app['user']);
$request->headers->set('PHP_AUTH_USER', 'fabien');
$request->headers->set('PHP_AUTH_PW', 'foo');
$app->handle($request);
$this->assertInstanceOf('Symfony\Component\Security\Core\User\UserInterface', $app['user']);
$this->assertEquals('fabien', $app['user']->getUsername());
}
public function testUserWithNoToken() public function testUserWithNoToken()
{ {
$app = new Application(); $app = new Application();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment