コード例 #1
0
 public function testInstantiateWithWhitelistRules()
 {
     $s = new ConfigSubscriber(array("^/" => array('ip_whitelist' => array('192.168.*.*'))));
     $s->addConfigHandler(new IpWhitelistHandler());
     $f = new Firewall();
     $f->addSubscriber($s);
     $this->assertTrue($f->verifyRequest($this->createRequestFromIp("192.168.30.40")));
     $s = new ConfigSubscriber(array("^/" => array('ip_whitelist' => array('192.168.*.*'))));
     $s->addConfigHandler(new IpWhitelistHandler());
     $f = new Firewall();
     $f->addSubscriber($s);
     $this->setExpectedException("AC\\Component\\Firewall\\Exception\\InvalidIpException");
     $this->assertTrue($f->verifyRequest($this->createRequestFromIp("80.0.0.0")));
 }
コード例 #2
0
 public function register(Application $app)
 {
     //shared firewall service
     $app['firewall'] = $app->share(function ($app) {
         $f = new Firewall($app['dispatcher']);
         $f->addSubscriber($app['firewall.configurator']);
         return $f;
     });
     //configuration service - can be used by other extensions
     //in Application::boot to register other config handlers
     $app['firewall.configurator'] = $app->share(function ($c) {
         $s = new ConfigSubscriber($app->getParameter('firewall.rules', array()));
         $s->addConfigHandler(new IpBlacklistHandler());
         $s->addConfigHandler(new IpWhitelisttHandler());
     });
 }