GithubHelp home page GithubHelp logo

php-abac's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-abac's Issues

PolicyRuleManager suggestion

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

Reference attribute in abac rules

The goal is to turn this configuration :

    troop_leadership:
        attributes:
            user.isActive:
                comparison_type: boolean
                comparison: boolAnd
                value: true
            user.troopAssociations:
                comparison_type: array
                comparison: contains
                with:
                    troopAssociation.troop.id:
                        comparison_type: numeric
                        comparison: isEqual
                        value: dynamic
                    troopAssociation.role.position:
                        comparison_type: numeric
                        comparison: isEqual
                        value: 1
if($this->get('kilix_abac.security')->enforce('troop_membership', $this->getUser(), $troop, [
    'dynamic_attributes' => ['troop-id' => $troop->getId()]
]) !== true) {
    throw new AccessDeniedHttpException('troops.access_denied');
}

to :

    troop_leadership:
        attributes:
            user.isActive:
                comparison_type: boolean
                comparison: boolAnd
                value: true
            user.troopAssociations:
                comparison_type: array
                comparison: contains
                with:
                    troopAssociation.troop.id:
                        comparison_type: object
                        comparison: isFieldEqual
                        value: id
                    troopAssociation.role.position:
                        comparison_type: numeric
                        comparison: isEqual
                        value: 1
if($this->get('kilix_abac.security')->enforce('troop_membership', $this->getUser(), $troop) !== true) {
    throw new AccessDeniedHttpException('troops.access_denied');
}

Thoughts on DI

Kern046,
first of all, thank you for this package since it looks like the only one ABAC implementation for native PHP at all :)
But I found this library very NON-extendable :(
One simple example. It is not possible at all to plug in your own Loader (I want to develop and use e.g. SQL or MongoDB loader for policies). And also all Managers are instantiated by class name too in Abac constructor...
By using classname-dependant code you don't give a chance for developer to extend your library ((( The only way to use it in real project is to copy-paste and rewrite the code.

Documentation for custom rules

I got myself into a situation where I needed to write a custom comparison method, and was able to figure it out, but the library didn't have a ton of documentation to go off of.

I'd be happy to contribute an example of writing and using a custom comparison class if there's interest in enhancing the documentation in this area?

Thanks for the great library!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.