瀏覽代碼

Merge remote branch 'schmittjoh/security'

Fabien Potencier 14 年之前
父節點
當前提交
cf2bffd760

+ 11 - 3
src/Symfony/Component/DependencyInjection/Compiler/CheckReferenceValidityPass.php

@@ -2,6 +2,8 @@
 
 namespace Symfony\Component\DependencyInjection\Compiler;
 
+use Symfony\Component\DependencyInjection\Exception\ScopeWideningException;
+use Symfony\Component\DependencyInjection\Exception\ScopeCrossingException;
 use Symfony\Component\DependencyInjection\Definition;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\DependencyInjection\Reference;
@@ -126,7 +128,7 @@ class CheckReferenceValidityPass implements CompilerPassInterface
         $id = (string) $reference;
 
         if (in_array($scope, $this->currentScopeChildren, true)) {
-            throw new \RuntimeException(sprintf(
+            $ex = new ScopeWideningException(sprintf(
                 'Scope Widening Injection detected: The definition "%s" references the service "%s" which belongs to a narrower scope. '
                .'Generally, it is safer to either move "%s" to scope "%s" or alternatively rely on the provider pattern by injecting the container itself, and requesting the service "%s" each time it is needed. '
                .'In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.',
@@ -136,11 +138,14 @@ class CheckReferenceValidityPass implements CompilerPassInterface
                $scope,
                $id
             ));
+            $ex->setServiceId($this->currentId);
+
+            throw $ex;
         }
 
         if (!in_array($scope, $this->currentScopeAncestors, true)) {
-            throw new \RuntimeException(sprintf(
-                'Cross-Scope Injection detected: The definition "%s" references the service "%s" which belongs to another scope hierarchy. '
+            $ex = new ScopeCrossingException(sprintf(
+                'Scope Crossing Injection detected: The definition "%s" references the service "%s" which belongs to another scope hierarchy. '
                .'This service might not be available consistently. Generally, it is safer to either move the definition "%s" to scope "%s", or '
                .'declare "%s" as a child scope of "%s". If you can be sure that the other scope is always active, you can set the reference to strict=false to get rid of this error.',
                $this->currentId,
@@ -150,6 +155,9 @@ class CheckReferenceValidityPass implements CompilerPassInterface
                $this->currentScope,
                $scope
             ));
+            $ex->setServiceId($this->currentId);
+
+            throw $ex;
         }
     }
 

+ 12 - 0
src/Symfony/Component/DependencyInjection/Exception/RuntimeException.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace Symfony\Component\DependencyInjection\Exception;
+
+/**
+ * Base RuntimeException for Dependency Injection Component.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+class RuntimeException extends \RuntimeException implements Exception
+{
+}

+ 23 - 0
src/Symfony/Component/DependencyInjection/Exception/ScopeCrossingException.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace Symfony\Component\DependencyInjection\Exception;
+
+/**
+ * This exception is thrown when the a scope crossing injection is detected.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+class ScopeCrossingException extends RuntimeException
+{
+    private $serviceId;
+
+    public function setServiceId($id)
+    {
+        $this->serviceId = $id;
+    }
+
+    public function getServiceId()
+    {
+        return $this->serviceId;
+    }
+}

+ 23 - 0
src/Symfony/Component/DependencyInjection/Exception/ScopeWideningException.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace Symfony\Component\DependencyInjection\Exception;
+
+/**
+ * Thrown when a scope widening injection is detected.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+class ScopeWideningException extends RuntimeException
+{
+    private $serviceId;
+
+    public function setServiceId($id)
+    {
+        $this->serviceId = $id;
+    }
+
+    public function getServiceId()
+    {
+        return $this->serviceId;
+    }
+}

+ 1 - 1
src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php

@@ -107,7 +107,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
      *
      * @param Event $event An Event instance
      */
-    public function handle(EventInterface $event)
+    public final function handle(EventInterface $event)
     {
         $request = $event->get('request');
 

+ 1 - 1
src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php

@@ -50,7 +50,7 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
      *
      * @param EventInterface $event An EventInterface instance
      */
-    public function handle(EventInterface $event)
+    public final function handle(EventInterface $event)
     {
         $request = $event->get('request');
 

+ 2 - 2
src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php

@@ -25,8 +25,8 @@ use Symfony\Component\Security\Core\Exception\BadCredentialsException;
  */
 class X509AuthenticationListener extends AbstractPreAuthenticatedListener
 {
-    protected $userKey;
-    protected $credentialKey;
+    private $userKey;
+    private $credentialKey;
 
     public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, $userKey = 'SSL_CLIENT_S_DN_Email', $credentialKey = 'SSL_CLIENT_S_DN', LoggerInterface $logger = null, EventDispatcherInterface $eventDispatcher = null)
     {