Exemplo n.º 1
0
 /**
  *  Notes de Marc : onFilterController est un membre de classe qui est automatiquement
  * appelé par le moteur symfony2 (la classe doit avoir été déclarée en Service et doit être
  * instancié dans le Container de symfony) en amont de chaque traitement de requête
  * Dans ce cas particulier, le filtre va employer un autre Service, déclaré dans 
  * 'GaiaService.php' pour tester la présence de certains codes qui sont la preuve de
  * l'autorisation de l'originaire de la requête.
  * @param FilterControllerEvent $event
  * @return type
  * @throws \Exception
  */
 public function onFilterController(FilterControllerEvent $event)
 {
     // Marc inserted this to test if it's being used
     throw new \Exception('SUCCES : Nous sommes dans onFilterController !', 8701);
     //Return if no controller
     if (!is_array($controller = $event->getController())) {
         return;
     }
     list($object, $method) = $controller;
     // the controller could be a proxy, e.g. when using the JMSSecuriyExtraBundle or JMSDiExtraBundle
     $className = ClassUtils::getClass($object);
     $reflectionClass = new \ReflectionClass($className);
     $reflectionMethod = $reflectionClass->getMethod($method);
     $allAnnotations = $this->reader->getMethodAnnotations($reflectionMethod);
     $gaiaAnnotations = array_filter($allAnnotations, function ($annotation) {
         return $annotation instanceof RequiresGaia;
     });
     foreach ($gaiaAnnotations as $gaiaAnnotation) {
         // ... verify
         // throw an exception, catch it using an exception listener
         // then in the exception listener, create a RedirectResponse or something
         // and set it on the $event object
         $gaia = $this->gaia->getGaiaValues('gaia');
         if (strlen($gaia) === 0) {
             throw new \Exception('GAIA non détecté !', 8701);
         }
         if ($gaiaAnnotation->value === 'admin' && $this->security->isAdmin() === false || $gaiaAnnotation->value === 'admin_app' && $this->security->isAdminOrAdminApp() === false) {
             throw new \Exception("Vous n'avez pas les droits nécessaires !", 8702);
         }
     }
 }
Exemplo n.º 2
0
 public function gaiaInfosFunction($key)
 {
     //Retour
     return $this->gaia->getGaiaValues($key);
 }