Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function process($request)
 {
     $config = ConfigProvider::getInstance();
     $client = $request->getUserAgent();
     $IP = $request->getIP();
     // if no user agent string or IP are provided, we can't filter by these anyway to might as well skip
     if ($client == null || $IP == null) {
         return;
     }
     if (!empty($client) && !empty($IP)) {
         $badRequest = new BadRequest();
         $badRequest->set('client', $client);
         $badRequest->set('IP', $IP);
         $badRequestCount = $badRequest->getBadRequestCount();
         if ($badRequestCount >= $config->get('security.client.temp.blacklist.filter.limit')) {
             // if we got this far then the client is bad
             self::$logger->warn('The client [' . $client . '] was blocked from accessing the resource [' . $request->getURI() . '] on a temporary basis');
             throw new ResourceNotAllowedException('Not allowed!');
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Testing the addProperty() method.
  *
  * @since 2.0
  */
 public function testAddProperty()
 {
     $record = new BadRequest();
     $record->newStringField = new String();
     $record->addProperty('newStringField');
     $record->set('newStringField', 'test value');
     $record->save();
     $record->reload();
     $this->assertEquals('test value', $record->get('newStringField'), 'Testing that we can save and retrieve from a newly-added column');
     $record = new BadRequest();
     $record->setMaintainHistory(true);
     $record->rebuildTable();
     $record->anotherNewStringField = new String();
     $record->addProperty('anotherNewStringField');
     $record->set('anotherNewStringField', 'test value');
     $record->save();
     $record->load($record->getOID(), 1);
     $this->assertEquals('test value', $record->get('anotherNewStringField'), 'Testing that the new column was added to the _history table');
 }
Ejemplo n.º 3
0
 /**
  * Called before the test functions will be executed
  * this function is defined in PHPUnit_TestCase and overwritten
  * here.
  *
  * @since 1.0
  */
 protected function setUp()
 {
     $config = ConfigProvider::getInstance();
     $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray');
     $this->blacklistedClient = new BlacklistedClient();
     $this->blacklistedClient->rebuildTable();
     $this->blacklistedClient->set('client', $this->badAgent);
     $this->blacklistedClient->save();
     $this->blacklistedIP = new BlacklistedIP();
     $this->blacklistedIP->rebuildTable();
     $this->blacklistedIP->set('IP', $this->badIP);
     $this->blacklistedIP->save();
     $this->badRequest1 = new BadRequest();
     $this->badRequest1->rebuildTable();
     $this->badRequest1->set('client', $this->badAgent);
     $this->badRequest1->set('IP', $this->badIP);
     $this->badRequest1->set('requestedResource', '/doesNotExist');
     $this->badRequest1->save();
     $this->badRequest2 = new BadRequest();
     $this->badRequest2->set('client', $this->badAgent);
     $this->badRequest2->set('IP', $this->badIP);
     $this->badRequest2->set('requestedResource', '/doesNotExist');
     $this->badRequest2->save();
     $this->badRequest3 = new BadRequest();
     $this->badRequest3->set('client', $this->badAgent);
     $this->badRequest3->set('IP', $this->badIP);
     $this->badRequest3->set('requestedResource', '/doesNotExist');
     $this->badRequest3->save();
 }