public function testIsUserAllowedAccessDecisionStrategyAffirmative() { // lets mock the address to one that doesn't match any rules Request::getInstance()->setCurrentUrl('http://admin.w3.com/about/'); $user = new UserMock(); $user->populate('test', 'test', [new Role('ROLE_MOCK')], true); $config = new ConfigObject(['DecisionStrategy' => 'affirmative', 'Rules' => [['Path' => '/^\\/about/', 'Roles' => 'ROLE_GOD']]]); $instance = new AccessControl($user, $config); $this->assertTrue($instance->isUserAllowedAccess()); }
/** * Checks if current user has access to current area based by access rules. * * @return bool */ public function isUserAllowedAccess() { if (!is_object($this->accessControl)) { $this->accessControl = new AccessControl($this->user, $this->config->get('AccessControl', false)); } $isAccessAllowed = $this->accessControl->isUserAllowedAccess(); if (!$isAccessAllowed) { $this->eventManager()->fire(SecurityEvent::ROLE_INVALID, new SecurityEvent($this->user)); } return $isAccessAllowed; }