Skip to content

PolicyRuleManager suggestion #45

@altaraven

Description

@altaraven

Please take a look at PolicyRuleManager::getRule() method.
I suppose it will be very usefull in some cases to make 2 steps authorization. Especially when using frameworks:

  1. We need to check if user can acces this action at all. If not, we just stop the code and dont try to get the object:
$abac->enforce('blabla', $user);
  1. Only after that we want to perform query to database to find an object and check acces to the object:
$abac->enforce('blabla', $user, $object);

This can be very usefull when db query (or 3rd party service query) is heavy and takes much time.

But in current implementation it is not possible with a single rule. The library will always try to check $object even if it wasnt passed to enforce() method.

So, I suggest to add a check to the PolicyRuleManager::getRule() method like this:

            foreach ($this->processRuleAttributes($rule['attributes'], $user, $resource) as $pra) {
                if(!$resource && $pra->getAttribute()->getType() == 'resource') {
                    continue;
                }
                $Policy->addPolicyRuleAttribute($pra);
            }

Maybe there can be more pretty way to do this. So what do you think? Another option is to add a method to Abac class

$abac->enforceUserOnly('blabla', $user);// or somth like this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions