Welcome Guest, Not a member yet? Register   Sign In
Khaos :: KhACL
#85

[eluser]sophistry[/eluser]
Code:
function testacl()
    {
        // This is what we want to restrict access to
        $this->khacl->aco->create('Website');
        $this->khacl->aco->create('Database', 'Website');
        $this->khacl->aco->create('Email', 'Website');

        // create tree root group and nested sub-groups
        $this->khacl->aro->create('Company');
        // all users are part of company
        $this->khacl->aro->create('User', 'Company');
        // admin and guest are both users so inherit user permissions
        $this->khacl->aro->create('Admin', 'User');
        $this->khacl->aro->create('Guest', 'User');

        // create some users belonging to the nested groups
        // first the overall group
        $this->khacl->aro->create('Bob','Company');
        // now the next level down
        $this->khacl->aro->create('David','User');
        // finally the lowest levels where
        // the axos get detailed
        $this->khacl->aro->create('Jim', 'Admin');
        $this->khacl->aro->create('Bernice', 'Guest');
        
        
        // These are the actions axos
        // View is generic action we will use
        // several times applied to different acos
        $this->khacl->axo->create('View');
        
        // these will be restricted to admins
        $this->khacl->axo->create('Add');
        $this->khacl->axo->create('Edit');
        $this->khacl->axo->create('Delete');
        
        
        // OK lets first deny all users everything
        // (company is the root group)
        $this->khacl->deny('Company','Website');
        
            // test this to see if it worked to deny access
            // at this point, a specific user should not
            // be able to view any part of the website
            $this->_can('Bob', 'Website', 'View', FALSE);
        
        // allow anyone in company to view
        // anything in entire website
        $this->khacl->allow('Company','Website','View');
        
        // deny Guest all access to Email and Database
        // guests can't do anything to email or database
        // they can't even view, but the rest of the
        // website remains fully open to guests
        $this->khacl->deny('Guest','Email');
        $this->khacl->deny('Guest','Database');
        
        // allow admin group to administrate any part of
        // the website including the email and database
        $this->khacl->allow('Admin','Website','Add');  
        $this->khacl->allow('Admin','Website','Edit');
        $this->khacl->allow('Admin','Website','Delete');
        
        
        
        
        // now test the settings
        echo 'these should be true<hr>';
        // any admin should be able to edit email
        $this->_can('Admin', 'Website', 'Edit', TRUE);
        // specific admin should be able to view any part of website
        $this->_can('Jim', 'Website', 'View', TRUE);
        // specific admin should be able to delete any part of website
        $this->_can('Jim', 'Website', 'Delete', TRUE);
        // specific admin should be able to delete any part of database
        $this->_can('Jim', 'Database', 'Delete', TRUE);
        // specific user should be able to view any part of the website
        $this->_can('Bob', 'Website', 'View', TRUE);
        // specific user should be able to view any part of the database
        $this->_can('Bob', 'Database', 'View', TRUE);
        // specific user should be able to view any part of the database
        $this->_can('David', 'Database', 'View', TRUE);
        
        echo '<br>these should be false<hr>';
        // specific user should not be able to edit any part of the website
        $this->_can('Bob', 'Website', 'Edit', FALSE);
        // specific user should not be able to edit any part of the website
        $this->_can('David', 'Website', 'Edit', FALSE);
        // specific user should not be able to edit any part of the database
        $this->_can('Bob', 'Database', 'Edit', FALSE);
        // guest should not be allowed to view any email
        $this->_can('Guest', 'Email', 'View', FALSE);
        // guest should not be allowed to view any database
        $this->_can('Guest', 'Database', 'View', FALSE);
        // specific guest user should not be allowed to view any email
        $this->_can('Bernice', 'Email', 'View', FALSE);
        // specific user should not be able to edit any part of the Email
        $this->_can('Bob', 'Email', 'Edit', FALSE);
        // guest should not be able to edit any part of the Email
        $this->_can('Guest', 'Email', 'Edit', FALSE);
        // specific guest user should not be allowed to edit any email
        $this->_can('Bernice', 'Email', 'Edit', FALSE);
        
        // the khhaos_acl system returns FALSE if indeterminate
        echo '<br>these should confuse the system and give indeterminate answers<hr>';
        // only admin should be able to edit email,
        // system should not allow generic user, but answer is ambiguous
        $this->_can('User', 'Email', 'Edit', 'UNKNOWN');
        // generic user should not be able to edit any part of
        // the website, only admin in the next level down can
        $this->_can('User', 'Website', 'Edit', 'UNKNOWN');
        
    }
    
    // utility to wrap the kh_acl_check() method
    // and allow printing of results to browser
    function _can($aro, $aco, $axo, $expected)
    {
        $can = kh_acl_check($aro, $aco, $axo);
        print_r(var_export($can, TRUE) . '='. var_export($expected, TRUE) .'<br>');
        return $can;
    }


Messages In This Thread
Khaos :: KhACL - by El Forum - 01-29-2008, 10:49 AM
Khaos :: KhACL - by El Forum - 01-29-2008, 11:42 AM
Khaos :: KhACL - by El Forum - 01-29-2008, 12:35 PM
Khaos :: KhACL - by El Forum - 01-30-2008, 07:10 AM
Khaos :: KhACL - by El Forum - 01-30-2008, 05:11 PM
Khaos :: KhACL - by El Forum - 01-30-2008, 08:17 PM
Khaos :: KhACL - by El Forum - 01-31-2008, 03:49 AM
Khaos :: KhACL - by El Forum - 01-31-2008, 09:14 AM
Khaos :: KhACL - by El Forum - 01-31-2008, 10:03 AM
Khaos :: KhACL - by El Forum - 01-31-2008, 10:33 AM
Khaos :: KhACL - by El Forum - 01-31-2008, 10:39 AM
Khaos :: KhACL - by El Forum - 01-31-2008, 10:50 AM
Khaos :: KhACL - by El Forum - 01-31-2008, 03:14 PM
Khaos :: KhACL - by El Forum - 02-03-2008, 11:00 AM
Khaos :: KhACL - by El Forum - 02-03-2008, 01:35 PM
Khaos :: KhACL - by El Forum - 02-04-2008, 12:22 PM
Khaos :: KhACL - by El Forum - 02-05-2008, 03:45 AM
Khaos :: KhACL - by El Forum - 02-25-2008, 12:42 PM
Khaos :: KhACL - by El Forum - 02-25-2008, 01:16 PM
Khaos :: KhACL - by El Forum - 02-25-2008, 02:53 PM
Khaos :: KhACL - by El Forum - 02-25-2008, 02:59 PM
Khaos :: KhACL - by El Forum - 02-25-2008, 03:55 PM
Khaos :: KhACL - by El Forum - 02-25-2008, 04:03 PM
Khaos :: KhACL - by El Forum - 02-29-2008, 09:56 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 06:23 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 07:03 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 07:28 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 07:34 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 07:44 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 08:05 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 08:20 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 09:06 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 09:12 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 09:19 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 09:26 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 09:46 AM
Khaos :: KhACL - by El Forum - 03-02-2008, 10:47 AM
Khaos :: KhACL - by El Forum - 03-08-2008, 05:37 PM
Khaos :: KhACL - by El Forum - 03-09-2008, 10:22 AM
Khaos :: KhACL - by El Forum - 03-09-2008, 10:24 AM
Khaos :: KhACL - by El Forum - 03-09-2008, 12:21 PM
Khaos :: KhACL - by El Forum - 03-20-2008, 05:25 AM
Khaos :: KhACL - by El Forum - 03-20-2008, 06:14 AM
Khaos :: KhACL - by El Forum - 03-20-2008, 07:08 AM
Khaos :: KhACL - by El Forum - 03-20-2008, 07:42 AM
Khaos :: KhACL - by El Forum - 03-20-2008, 11:31 AM
Khaos :: KhACL - by El Forum - 03-20-2008, 11:40 AM
Khaos :: KhACL - by El Forum - 03-21-2008, 05:16 AM
Khaos :: KhACL - by El Forum - 03-21-2008, 05:25 AM
Khaos :: KhACL - by El Forum - 03-21-2008, 07:54 AM
Khaos :: KhACL - by El Forum - 03-21-2008, 08:31 AM
Khaos :: KhACL - by El Forum - 03-21-2008, 12:35 PM
Khaos :: KhACL - by El Forum - 03-21-2008, 12:38 PM
Khaos :: KhACL - by El Forum - 03-21-2008, 01:28 PM
Khaos :: KhACL - by El Forum - 03-21-2008, 01:33 PM
Khaos :: KhACL - by El Forum - 03-21-2008, 03:18 PM
Khaos :: KhACL - by El Forum - 03-21-2008, 06:37 PM
Khaos :: KhACL - by El Forum - 03-26-2008, 05:13 AM
Khaos :: KhACL - by El Forum - 03-28-2008, 02:16 AM
Khaos :: KhACL - by El Forum - 03-30-2008, 02:17 AM
Khaos :: KhACL - by El Forum - 03-30-2008, 04:07 AM
Khaos :: KhACL - by El Forum - 03-30-2008, 04:26 AM
Khaos :: KhACL - by El Forum - 03-30-2008, 05:32 AM
Khaos :: KhACL - by El Forum - 03-30-2008, 06:28 AM
Khaos :: KhACL - by El Forum - 03-30-2008, 09:36 AM
Khaos :: KhACL - by El Forum - 03-30-2008, 10:23 AM
Khaos :: KhACL - by El Forum - 03-30-2008, 10:25 PM
Khaos :: KhACL - by El Forum - 03-31-2008, 02:59 AM
Khaos :: KhACL - by El Forum - 03-31-2008, 03:20 AM
Khaos :: KhACL - by El Forum - 03-31-2008, 06:43 AM
Khaos :: KhACL - by El Forum - 04-11-2008, 11:33 AM
Khaos :: KhACL - by El Forum - 04-11-2008, 11:48 AM
Khaos :: KhACL - by El Forum - 04-12-2008, 02:17 AM
Khaos :: KhACL - by El Forum - 04-14-2008, 02:32 AM
Khaos :: KhACL - by El Forum - 04-14-2008, 11:11 AM
Khaos :: KhACL - by El Forum - 05-02-2008, 01:04 AM
Khaos :: KhACL - by El Forum - 05-02-2008, 02:05 AM
Khaos :: KhACL - by El Forum - 05-19-2008, 05:01 PM
Khaos :: KhACL - by El Forum - 05-19-2008, 05:31 PM
Khaos :: KhACL - by El Forum - 05-19-2008, 05:40 PM
Khaos :: KhACL - by El Forum - 06-09-2008, 10:26 AM
Khaos :: KhACL - by El Forum - 06-17-2008, 02:31 PM
Khaos :: KhACL - by El Forum - 06-17-2008, 02:33 PM
Khaos :: KhACL - by El Forum - 06-25-2008, 09:43 AM
Khaos :: KhACL - by El Forum - 06-25-2008, 09:44 AM
Khaos :: KhACL - by El Forum - 06-26-2008, 06:54 AM
Khaos :: KhACL - by El Forum - 07-24-2008, 11:29 PM
Khaos :: KhACL - by El Forum - 07-27-2008, 06:06 PM
Khaos :: KhACL - by El Forum - 09-09-2008, 03:51 PM
Khaos :: KhACL - by El Forum - 05-06-2009, 03:18 AM
Khaos :: KhACL - by El Forum - 06-16-2009, 03:35 AM
Khaos :: KhACL - by El Forum - 07-24-2009, 12:48 AM
Khaos :: KhACL - by El Forum - 11-02-2010, 06:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB