Coder Social home page Coder Social logo

php-abac's Introduction

[Kilix] php-abac

Attribute-Based Access Control implementation library

Latest Stable Version Latest Unstable Version Build Status Code Coverage Scrutinizer Code Quality Total Downloads License

Introduction

This library is meant to implement the concept of ABAC in your PHP applications.

The concept is to manage access control using attributes : from users, from resources and environment.

It allows us to define rules based on the properties of the user object and optionally the accessed object.

These rules will be checked in your application to determine if an user is allowed to perform an action.

The following links explain what ABAC is :

Installation

Using composer :

Write the following line in your composer.json file :

"require" : {
    "kilix/php-abac": "dev-master"
}

Then just do :

composer install

Then you will have to configure the attributes and the rules of your application.

For more details about this, please refer to the dedicated documentation

Documentation

Usage Examples

Example with only user attributes defined in the rule

We have in this example a single object, representing the current user.

This object have properties, with getter methods to access the values.

For example, we can code :

<?php

use PhpAbac\Abac;

class User{
    protected $id;

    protected $isBanned;

    public function getId() {
        return $this->id;
    }

    public function setIsBanned($isBanned) {
        $this->isBanned = $isBanned;

        return $this;
    }

    public function getIsBanned() {
        return $this->isBanned;
    }
}

$user = new User();
$user->setIsBanned(true);

$abac = new Abac([
    'policy_rule_configuration.yml'
]);
$abac->enforce('create-group', $user);

The attributes checked by the rule can be :

User
isBanned = false

Example with both user and object attributes

use PhpAbac\Abac;

$abac = new Abac([
    'policy_rule_configuration.yml'
]);
$check = $abac->enforce('read-public-group', $user, $group);

The checked attributes can be :

User Group
isBanned = 0 isActive = 1
isPublic = 1

Example with dynamic attributes

<?php

use PhpAbac\Abac;

$abac = new Abac([
    'policy_rule_configuration.yml'
]);
$check = $abac->enforce('edit-group', $user, $group, [
    'dynamic-attributes' => [
        'group-owner' => $user->getId()
    ]
]);

Example with cache

$check = $abac->enforce('edit-group', $user, $group, [
    'cache_result' => true,
    'cache_ttl' => 3600, // Time To Live in seconds
    'cache_driver' => 'memory' // memory is the default driver, you can avoid this option
]);

Contribute

If you want to contribute, don't hesitate to fork the library and submit Pull Requests.

You can also report issues, suggest enhancements, feel free to give advices and your feedback about this library.

It's not finished yet, there's still a lot of features to implement to make it better. If you want to be a part of this library improvement, let us know !

See also

php-abac's People

Contributors

kern046 avatar

Watchers

Rich Shank avatar James Cloos avatar

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.