Пример #1
0
	public function testParseMatch() {
		$request = new Request(array('params' => array(
			'library' => 'test_library',
			'controller' => 'test_controllers',
			'action' => 'test_action'
		)));

		$match = array(
			'library' => 'test_library',
			'controller' => 'TestControllers',
			'action' => 'test_action'
		);
		$this->assertTrue(Access::adapter('test_check')->parseMatch($match, $request));

		$match = array('controller' => 'TestControllers', 'action' => 'test_action');
		$this->assertTrue(Access::adapter('test_check')->parseMatch($match, $request));

		$match = array('library' => 'test_library', 'action' => 'test_action');
		$this->assertTrue(Access::adapter('test_check')->parseMatch($match, $request));

		$match = array('library' => 'test_library', 'controller' => 'TestControllers');
		$this->assertTrue(Access::adapter('test_check')->parseMatch($match, $request));

		$match = array(
			'library' => 'test_no_match',
			'controller' => 'TestControllers',
			'action' => 'test_action'
		);
		$this->assertFalse(Access::adapter('test_check')->parseMatch($match, $request));

		$match = 'TestControllers::test_action';
		$this->assertTrue(Access::adapter('test_check')->parseMatch($match, $request));

		$match = 'TestControllers::*';
		$this->assertTrue(Access::adapter('test_check')->parseMatch($match, $request));

		$match = '*::test_action';
		$this->assertTrue(Access::adapter('test_check')->parseMatch($match, $request));

		$match = '*::*';
		$this->assertTrue(Access::adapter('test_check')->parseMatch($match, $request));

		$match = array('library' => 'test_library', '*::*');
		$this->assertTrue(Access::adapter('test_check')->parseMatch($match, $request));

		$match = array('library' => 'test_no_match', '*::*');
		$this->assertFalse(Access::adapter('test_check')->parseMatch($match, $request));

		$match = null;
		$this->assertFalse(Access::adapter('test_check')->parseMatch($match, $request));

		$test = function() { return true; };
		$this->assertTrue(Access::adapter('test_closures')->parseMatch(array($test), $request));

		$test = function() { return false; };
		$this->assertFalse(Access::adapter('test_closures')->parseMatch(array($test), $request));
		$this->assertFalse(Access::adapter('test_closures')->parseMatch(array(), $request));
	}
Пример #2
0
                header('Location: ' . Router::match(array('library' => 'li3b_users', 'controller' => 'users', 'action' => 'login')));
            }
            // None shall pass.
            exit;
        }
    }
    // Sets the current user in each request for convenience.
    $params['request']->user = $user;
    return $next;
    // return $chain->next($self, $params, $chain);
});
Access::config(array('default' => array('adapter' => 'Rules', 'filters' => array())));
// Set some basic rules to be used from anywhere
// Allow access for users with a role of "administrator" or "content_editor"
Access::adapter('default')->add('allowManagers', function ($user, $request, $options) {
    if ($user && ($user['role'] == 'administrator' || $user['role'] == 'content_editor')) {
        return true;
    }
    return false;
});
// Restrict access to documents that have a published field marked as true
// (except for users with a role of "administrator" or "content_editor")
Access::adapter('default')->add('allowIfPublished', function ($user, $request, $options) {
    if (isset($options['document']['published']) && $options['document']['published'] === true) {
        return true;
    }
    if ($user && ($user['role'] == 'administrator' || $user['role'] == 'content_editor')) {
        return true;
    }
    return false;
});
Пример #3
0
	public function testAdd() {
		$request = new Request();

		// The add() method to add a rule
		Access::adapter('test_rulebased')->add('testDeny', function($requester, $request, $options) {
			return false;
		});

		$rules = array(
			array('rule' => 'testDeny', 'message' => 'Access denied.')
		);
		$expected = array('rule' => 'testDeny', 'message' => 'Access denied.', 'redirect' => '/');
		$result = Access::check('test_rulebased', array('username' => 'Tom'), $request, array('rules' => $rules));
		$this->assertEqual($expected, $result);

		// Make sure the rule got added to the $_rules property
		$this->assertTrue(is_callable(Access::adapter('test_rulebased')->getRules('testDeny')));

		$this->assertTrue(is_array(Access::adapter('test_rulebased')->getRules()));
	}
Пример #4
0
            )
	)
));

// Set some rules to be used from anywhere

// Allow access for users with a role of "administrator" or "content_editor"
Access::adapter('minerva_access')->add('allowManagers', function($user, $request, $options) {
   if(($user) && ($user['role'] == 'administrator' || $user['role'] == 'content_editor')) {
   return true;
   }
   return false;
});

// Add a base document access rule to check against
Access::adapter('minerva_access')->add('publishStatus', function($user, $request, $options) {
   if($options['document']['published'] === true) {
   return true;
   }
   if(($user) && ($user['role'] == 'administrator' || $user['role'] == 'content_editor')) {
   return true;
   }
   return false;
});

/*
Dispatcher::applyFilter('_call', function($self, $params, $chain) {
    
    if(isset($params['callable']::$access)) {
        // TODO: maybe move this to MinervaController and even add an "admin" key to the Controller::$access array for even greater control and flexibility
        // Check for protected "admin" routes. Only administrators and content editors can access these routes.