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
33b352f8
Commit
33b352f8
authored
Jun 16, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed security.context to security
parent
2ebc4768
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
19 deletions
+19
-19
doc/providers/security.rst
doc/providers/security.rst
+5
-5
src/Silex/Provider/SecurityServiceProvider.php
src/Silex/Provider/SecurityServiceProvider.php
+9
-9
src/Silex/Provider/TwigServiceProvider.php
src/Silex/Provider/TwigServiceProvider.php
+2
-2
tests/Silex/Tests/Provider/SecurityServiceProviderTest.php
tests/Silex/Tests/Provider/SecurityServiceProviderTest.php
+3
-3
No files found.
doc/providers/security.rst
View file @
33b352f8
...
...
@@ -12,8 +12,8 @@ n/a
Services
--------
* **security
.context**: The main entry point for the security provider. Use i
t
t
o get t
he current user token.
* **security
**: The main entry point for the security provider. Use it to ge
t
the current user token.
* **security.authentication_manager**: An instance of
`AuthenticationProviderManager
...
...
@@ -78,9 +78,9 @@ Accessing the current User
~~~~~~~~~~~~~~~~~~~~~~~~~~
The current user information is stored in a token that is accessible via the
``security
.context
`` service::
``security`` service::
$token = $app['security
.context
']->getToken();
$token = $app['security']->getToken();
If there is no information about the user, the token is ``null``. If the user
is known, you can get it with a call to ``getUser()``::
...
...
@@ -281,7 +281,7 @@ Checking User Roles
To check if a user is granted some role, use the ``isGranted()`` method on the
security context::
if ($app['security
.context
']->isGranted('ROLE_ADMIN') {
if ($app['security']->isGranted('ROLE_ADMIN') {
// ...
}
...
...
src/Silex/Provider/SecurityServiceProvider.php
View file @
33b352f8
...
...
@@ -68,7 +68,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
$app
[
'security.role_hierarchy'
]
=
array
();
$app
[
'security.access_rules'
]
=
array
();
$app
[
'security
.context
'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
$app
[
'security'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
return
new
SecurityContext
(
$app
[
'security.authentication_manager'
],
$app
[
'security.access_manager'
]);
});
...
...
@@ -211,7 +211,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
$app
[
'security.access_listener'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
return
new
AccessListener
(
$app
[
'security
.context
'
],
$app
[
'security'
],
$app
[
'security.access_manager'
],
$app
[
'security.access_map'
],
$app
[
'security.authentication_manager'
],
...
...
@@ -263,7 +263,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
$app
[
'security.context_listener._proto'
]
=
$app
->
protect
(
function
(
$providerKey
,
$userProviders
)
use
(
$app
)
{
return
new
ContextListener
(
$app
[
'security
.context
'
],
$app
[
'security'
],
$userProviders
,
$providerKey
,
$app
[
'logger'
],
...
...
@@ -286,7 +286,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
}
return
new
ExceptionListener
(
$app
[
'security
.context
'
],
$app
[
'security'
],
$app
[
'security.trust_resolver'
],
$app
[
'security.http_utils'
],
$app
[
'security.entry_point.'
.
$entryPoint
.
'.'
.
$name
],
...
...
@@ -300,7 +300,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
$that
->
addFakeRoute
(
array
(
'post'
,
$tmp
=
isset
(
$options
[
'check_path'
])
?
$options
[
'check_path'
]
:
'/login_check'
,
str_replace
(
'/'
,
'_'
,
ltrim
(
$tmp
,
'/'
))));
return
new
UsernamePasswordFormAuthenticationListener
(
$app
[
'security
.context
'
],
$app
[
'security'
],
$app
[
'security.authentication_manager'
],
$app
[
'security.session_strategy'
],
$app
[
'security.http_utils'
],
...
...
@@ -316,7 +316,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
$app
[
'security.authentication.http._proto'
]
=
$app
->
protect
(
function
(
$providerKey
,
$options
)
use
(
$app
)
{
return
new
BasicAuthenticationListener
(
$app
[
'security
.context
'
],
$app
[
'security'
],
$app
[
'security.authentication_manager'
],
$providerKey
,
$app
[
'security.entry_point.http'
],
...
...
@@ -326,7 +326,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
$app
[
'security.authentication.anonymous._proto'
]
=
$app
->
protect
(
function
(
$providerKey
,
$options
)
use
(
$app
)
{
return
new
AnonymousAuthenticationListener
(
$app
[
'security
.context
'
],
$app
[
'security'
],
$providerKey
,
$app
[
'logger'
]
);
...
...
@@ -336,7 +336,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
$that
->
addFakeRoute
(
array
(
'get'
,
$tmp
=
isset
(
$options
[
'logout_path'
])
?
$options
[
'logout_path'
]
:
'/logout'
,
str_replace
(
'/'
,
'_'
,
ltrim
(
$tmp
,
'/'
))));
$listener
=
new
LogoutListener
(
$app
[
'security
.context
'
],
$app
[
'security'
],
$app
[
'security.http_utils'
],
$options
,
null
,
// LogoutSuccessHandlerInterface
...
...
@@ -350,7 +350,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
$app
[
'security.authentication.switch_user._proto'
]
=
$app
->
protect
(
function
(
$name
,
$options
)
use
(
$app
,
$that
)
{
return
new
SwitchUserListener
(
$app
[
'security
.context
'
],
$app
[
'security'
],
$app
[
'security.user_provider.'
.
$name
],
$app
[
'security.user_checker'
],
$name
,
...
...
src/Silex/Provider/TwigServiceProvider.php
View file @
33b352f8
...
...
@@ -59,8 +59,8 @@ class TwigServiceProvider implements ServiceProviderInterface
$twig
->
addExtension
(
new
TranslationExtension
(
$app
[
'translator'
]));
}
if
(
isset
(
$app
[
'security
.context
'
]))
{
$twig
->
addExtension
(
new
SecurityExtension
(
$app
[
'security
.context
'
]));
if
(
isset
(
$app
[
'security'
]))
{
$twig
->
addExtension
(
new
SecurityExtension
(
$app
[
'security'
]));
}
if
(
isset
(
$app
[
'form.factory'
]))
{
...
...
tests/Silex/Tests/Provider/SecurityServiceProviderTest.php
View file @
33b352f8
...
...
@@ -117,15 +117,15 @@ class SecurityServiceProviderTest extends WebTestCase
});
$app
->
get
(
'/'
,
function
()
use
(
$app
)
{
$user
=
$app
[
'security
.context
'
]
->
getToken
()
->
getUser
();
$user
=
$app
[
'security'
]
->
getToken
()
->
getUser
();
$content
=
is_object
(
$user
)
?
$user
->
getUsername
()
:
'ANONYMOUS'
;
if
(
$app
[
'security
.context
'
]
->
isGranted
(
'IS_AUTHENTICATED_FULLY'
))
{
if
(
$app
[
'security'
]
->
isGranted
(
'IS_AUTHENTICATED_FULLY'
))
{
$content
.=
'AUTHENTICATED'
;
}
if
(
$app
[
'security
.context
'
]
->
isGranted
(
'ROLE_ADMIN'
))
{
if
(
$app
[
'security'
]
->
isGranted
(
'ROLE_ADMIN'
))
{
$content
.=
'ADMIN'
;
}
...
...
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