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