Пример #1
0
$acl->addResource(ROLE_GUEST, array('auth.php', 'optout.php'));
if (getConfiguration('auth.mode') == AuthHandler::AUTH_MODE_PASS) {
    $acl->addResource(ROLE_GUEST, array('join.php', 'help.php', 'AddRideAll.php', 'GetRegionConfiguration.php'));
} else {
    if (AuthHandler::getAuthMode() == AuthHandler::AUTH_MODE_TOKEN) {
        $acl->addResource(ROLE_GUEST, array('join.php', 'help.php', 'index.php', 'AddRideAll.php', 'feedback.php', 'SearchRides.php', 'GetRegionConfiguration.php'));
    }
}
$acl->addResource(ROLE_IDENTIFIED, array('join.php', 'help.php', 'index.php', 'feedback.php', 'logout.php', 'thanks.php', 'SearchRides.php', 'AddRideAll.php', 'GetRegionConfiguration.php'));
$acl->addResource(ROLE_IDENTIFIED_REGISTERED, array('ActivateToggle.php', 'DeleteRide.php', 'ShowInterest.php'));
// Content management
$acl->addResource(ROLE_ADMINISTRATOR, array('translations.php'));
// Enfore access control
$role = AuthHandler::getRole();
$resource = Utils::getRunningScript();
if (!$acl->isAllowed($role, $resource)) {
    if ($role == ROLE_GUEST && $acl->isAllowed($role, 'auth.php')) {
        // Not allowed: if not logged in and allowed to - redirect to login page
        GlobalMessage::setGlobalMessage(_('Please login to access this page'), GlobalMessage::ERROR);
        Utils::redirect('auth.php', array('ref' => $resource));
    } else {
        if ($acl->isAllowed($role, 'auth.php')) {
            // User is logged in but not permitted to use this page
            header("HTTP/1.1 401 Unauthorized");
            die('<p>' . _('Access Denied') . '</p>');
        } else {
            // User is not logged-in and not allowed to do that - totally forbidden
            header("HTTP/1.1 403 Forbidden");
            die('<p>' . _('Sorry, you are not allowed to use this application.') . '</p>');
        }
    }
Пример #2
0
 function testSetters()
 {
     $acl = new SimpleAcl();
     $roles = array(ROLE_GUEST => array(ROLE_GUEST), ROLE_IDENTIFIED => array(ROLE_IDENTIFIED));
     $accessList = array('resource1' => array(ROLE_GUEST), 'resource2' => array(ROLE_GUEST, ROLE_IDENTIFIED));
     $acl->setRoles($roles);
     $acl->setAcl($accessList);
     $this->assertTrue($acl->isAllowed(ROLE_GUEST, 'resource1'));
     $this->assertFalse($acl->isAllowed(ROLE_IDENTIFIED, 'resource1'));
     $this->assertTrue($acl->isAllowed(ROLE_GUEST, 'resource2'));
     $this->assertTrue($acl->isAllowed(ROLE_IDENTIFIED, 'resource2'));
 }