Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
bac2c455
Commit
bac2c455
authored
Aug 20, 2015
by
Henrik Bjornskov
Committed by
Haralan Dobrev
Feb 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test and documentation for using a service id string instead of a closure
parent
dc7572ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
doc/providers/security.rst
doc/providers/security.rst
+2
-2
tests/Silex/Tests/Provider/SecurityServiceProviderTest.php
tests/Silex/Tests/Provider/SecurityServiceProviderTest.php
+29
-0
No files found.
doc/providers/security.rst
View file @
bac2c455
...
...
@@ -495,8 +495,8 @@ Defining a custom User Provider
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.
The ``users`` setting can be defined as a service
that returns an instance of
`UserProviderInterface
The ``users`` setting can be defined as a service
or an service id that returns
an instance of
`UserProviderInterface
<http://api.symfony.com/master/Symfony/Component/Security/Core/User/UserProviderInterface.html>`_::
'users' => function () use ($app) {
...
...
tests/Silex/Tests/Provider/SecurityServiceProviderTest.php
View file @
bac2c455
...
...
@@ -278,6 +278,35 @@ class SecurityServiceProviderTest extends WebTestCase
$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
()
{
$app
=
new
Application
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment