15
15
use Symfony \Component \Security \Core \Role \RoleHierarchyInterface ;
16
16
use Symfony \Component \HttpFoundation \Request ;
17
17
use Symfony \Component \HttpFoundation \Response ;
18
+ use Symfony \Component \HttpFoundation \ParameterBag ;
18
19
use Symfony \Component \HttpKernel \DataCollector \DataCollector ;
19
20
use Symfony \Component \Security \Core \Role \RoleInterface ;
20
21
use Symfony \Component \Security \Http \Logout \LogoutUrlGenerator ;
21
22
use Symfony \Component \Security \Core \Authorization \AccessDecisionManagerInterface ;
22
23
use Symfony \Component \Security \Core \Authorization \DebugAccessDecisionManager ;
23
-
24
+ use Symfony \Component \Security \Http \FirewallMapInterface ;
25
+ use Symfony \Bundle \SecurityBundle \Security \ContextAwareFirewallMapInterface ;
24
26
/**
25
27
* SecurityDataCollector.
26
28
*
@@ -32,21 +34,24 @@ class SecurityDataCollector extends DataCollector
32
34
private $ roleHierarchy ;
33
35
private $ logoutUrlGenerator ;
34
36
private $ accessDecisionManager ;
37
+ private $ firewallMap ;
35
38
36
39
/**
37
40
* Constructor.
38
41
*
39
- * @param TokenStorageInterface|null $tokenStorage
40
- * @param RoleHierarchyInterface|null $roleHierarchy
41
- * @param LogoutUrlGenerator|null $logoutUrlGenerator
42
- * @param AccessDecisionManagerInterface|null $accessDecisionManager
42
+ * @param TokenStorageInterface|null $tokenStorage
43
+ * @param RoleHierarchyInterface|null $roleHierarchy
44
+ * @param LogoutUrlGenerator|null $logoutUrlGenerator
45
+ * @param AccessDecisionManagerInterface|null $accessDecisionManager
46
+ * @param ContextAwareFirewallMapInterface|null $firewallMap
43
47
*/
44
- public function __construct (TokenStorageInterface $ tokenStorage = null , RoleHierarchyInterface $ roleHierarchy = null , LogoutUrlGenerator $ logoutUrlGenerator = null , AccessDecisionManagerInterface $ accessDecisionManager = null )
48
+ public function __construct (TokenStorageInterface $ tokenStorage = null , RoleHierarchyInterface $ roleHierarchy = null , LogoutUrlGenerator $ logoutUrlGenerator = null , AccessDecisionManagerInterface $ accessDecisionManager = null , FirewallMapInterface $ firewallMap = null )
45
49
{
46
50
$ this ->tokenStorage = $ tokenStorage ;
47
51
$ this ->roleHierarchy = $ roleHierarchy ;
48
52
$ this ->logoutUrlGenerator = $ logoutUrlGenerator ;
49
53
$ this ->accessDecisionManager = $ accessDecisionManager ;
54
+ $ this ->firewallMap = $ firewallMap ;
50
55
}
51
56
52
57
/**
@@ -123,6 +128,31 @@ public function collect(Request $request, Response $response, \Exception $except
123
128
$ this ->data ['voter_strategy ' ] = 'unknown ' ;
124
129
$ this ->data ['voters ' ] = array ();
125
130
}
131
+
132
+ // collect firewall context informations
133
+ $ this ->data ['firewall ' ] = array ('name ' => null , 'config ' => array ());
134
+ if ($ this ->firewallMap instanceof ContextAwareFirewallMapInterface) {
135
+ $ firewallContext = $ this ->firewallMap ->getContext ($ request );
136
+
137
+ if (null !== $ firewallContext ) {
138
+ $ config = $ firewallContext ->getConfig ();
139
+ $ contextConfig = array ();
140
+ $ contextConfig ['request_matcher ' ] = $ config ->getRequestMatcher ();
141
+ $ contextConfig ['security ' ] = $ config ->hasSecurity ();
142
+ $ contextConfig ['context ' ] = $ config ->getContext ();
143
+ $ contextConfig ['entry_point ' ] = $ config ->getEntryPoint ();
144
+ $ contextConfig ['provider ' ] = $ config ->getProvider ();
145
+ $ contextConfig ['stateless ' ] = $ config ->isStateless ();
146
+ $ contextConfig ['access_denied_handler ' ] = $ config ->getAccessDeniedHandler ();
147
+ $ contextConfig ['access_denied_url ' ] = $ config ->getAccessDeniedUrl ();
148
+ $ contextConfig ['user_checker ' ] = $ config ->getUserChecker ();
149
+
150
+ $ this ->data ['firewall ' ]['name ' ] = $ config ->getName ();
151
+ $ this ->data ['firewall ' ]['config ' ] = new ParameterBag ($ contextConfig );
152
+ }
153
+ } else {
154
+ $ this ->data ['firewall ' ] = array ();
155
+ }
126
156
}
127
157
128
158
/**
@@ -236,6 +266,16 @@ public function getAccessDecisionLog()
236
266
return $ this ->data ['access_decision_log ' ];
237
267
}
238
268
269
+ /**
270
+ * Returns the configuration of the current firewall context.
271
+ *
272
+ * @return array
273
+ */
274
+ public function getFirewall ()
275
+ {
276
+ return $ this ->data ['firewall ' ];
277
+ }
278
+
239
279
/**
240
280
* {@inheritdoc}
241
281
*/
0 commit comments