get bjyauthorize allowed modules and priviledges from tables

282 views Asked by At

Every bjyauthorize.global file has an 'allow' section which has an array.

'rule_providers' => array(
    'BjyAuthorize\Provider\Rule\Config' => array(
        'allow' => array(
            // allow guests and users (and admins, through inheritance)
            // the "wear" privilege on the resource "pants"
            array(array('guest', 'user'), 'pants', 'wear')
        ),

        'deny' => array(
            // ...
        ),
    ),
),

This array contains all the allowed roles. But these roles are hard coded. I just want to return those array sets from table via function. How can i do this??..please advise.....

2

There are 2 answers

0
Aditya On

Hey i have found the answer to this.......this can be simply done by overriding the bjyauthorize rule and resource class. The array which is fed via bjyauthorize.global.php is filtered into its rule and resource class respectively. Instead of hard coding it, simply write your own resource and rule class, and inside its get method, open up a table gateway, connect to DB and bring in the information....:)

0
cptnk On

Alright. There probably various ways to achieve this and I am pretty sure you'll run into troubles here and there but you could override the config within your onBootstrap method in the module.php.

../Project/module/Application/Module.php

public function onBootstrap(MvcEvent $e) {
    $eventManager = $e->getApplication()->getEventManager();
    $serviceManager = $e->getApplication()->getServiceManager();
    $config = $serviceManager->get('Config');
    // You'll need to get the information from the DB here
    var_dump($config['bjyauthorize']['rule_providers']);exit;
}

From here on you should be fine, just get the information from your db and override $config['bjyauthorize']['rule_providers'] with your roles from the db.

Edit: I'am not to familiar with the bjyauthorize module but im pretty sure it has methods to Add or remove ACL entries. It prob be a good idea peeking into the modules code and see if you can find any and/or it provides any method's within it's service. If it does it probably is a way better solution then overriding the config.