Пример #1
0
 /**
  * @return void
  */
 public function process(Event\Type\System\SecurityPolicyApplication $secAppEvent)
 {
     // check whether user is authenticated
     if ($secAppEvent->isAuthRequired() && !$this->authService->isAuthenticated()) {
         AuthRequired::create('Authentication required')->_throw();
     }
     // check X-Csrf-Token header field if necessary
     if ($secAppEvent->isCsrfTokenRequired()) {
         $this->csrfTokenRequired = true;
         $this->checkCsrfToken();
     }
 }
Пример #2
0
 /**
  * @return void
  */
 public function init()
 {
     $this->addEventListener(Event\Type\System\SecurityPolicyApplication::toType(), function ($event) {
         $success = $this->onSecurityPolicyApplication($event);
         if (false === $success) {
             $event->discard();
         }
     });
 }
Пример #3
0
 /**
  * @return void
  */
 protected function getTargetPackage($event)
 {
     $success = false;
     foreach ($this->getExtensions(true) as $pkg) {
         foreach ($pkg->getRouters() as $router) {
             $success = $router->process($event);
             if ($event->getStatus() == Event\STATUS_DISCARDED) {
                 return $this;
             }
             if ($success) {
                 $package = $router->getPackage();
                 break;
             }
         }
     }
     // if discarded then event was designated to the current router but
     // routing by some reason failed
     if (!$success) {
         return $this;
     }
     $fcInstance = $router->getFrontController();
     $ctrlInstance = $router->getController();
     $actionInstance = $router->getAction();
     // form a propagation path through which the event will be passed.
     // Package -> Front Controller -> Controller -> Action
     $package->dispatchChainAddElement($fcInstance)->dispatchChainAddElement($ctrlInstance)->dispatchChainAddElement($actionInstance);
     if (null !== $fcInstance && null !== $ctrlInstance && null !== $actionInstance) {
         $fcInstance->mergePriorEvents($event, $ctrlInstance, $actionInstance);
     }
     // hook default services into corresponding events
     if ($fcInstance && $this->context->get('phpcrystal.security_guard.enabled')) {
         $fcInstance->addEventListener(Event\Type\System\SecurityPolicyApplication::toType(), function ($event) {
             $securityGuard = SecurityGuard::create();
             return $securityGuard->process($event);
         });
     }
     // actions are terminate nodes
     $event->setTerminateNodeHandler(function ($event) {
         return $this->execute($event);
     });
     return $package;
 }
Пример #4
0
 /**
  * @return
  */
 public function getEvent()
 {
     $event = Event\Type\System\SecurityPolicyApplication::create()->setAuthRequired($this->authRequired);
     return $event;
 }