Example #1
0
 /**
  * Handle a firewall event for an incoming requests, check if the ip
  * is within a valid range, and handle according to mode.
  *
  * @param  FirewallEvent      $e
  * @throws InvalidIpException If the IP is not allowed based on received configuration.
  */
 public function onFirewallRequest(FirewallEvent $e)
 {
     $ip = $e->getRequest()->getClientIp();
     foreach ($this->patterns as $pattern) {
         if ($this->isIpInRange($ip, $pattern)) {
             //if the mode is blacklist, we can fail now because we got a match
             if (self::BLACKLIST === $this->mode) {
                 throw new InvalidIpException("Access is denied from your location.");
             } else {
                 //if we got a match, and this is a whitelist, then the request is allowed
                 //so we can return early
                 return;
             }
         }
     }
     //if we made it this far with no matches, and the mode is whitelist, then the
     //request is NOT allowed
     if (self::WHITELIST === $this->mode) {
         throw new InvalidIpException("Access is denied from your location.");
     }
     return true;
 }
 public function __construct(Firewall $firewall, Request $request)
 {
     $this->firewall = $firewall;
     parent::__construct($request);
 }
 public function __construct(Request $request, Response $response)
 {
     parent::__construct($request);
     $this->response = $response;
 }
 public function __construct(Request $r, \Exception $e)
 {
     $this->exception = $e;
     parent::__construct($r);
 }