All Projects â†’ geggleto â†’ geggleto-acl

geggleto / geggleto-acl

Licence: MIT License
PSR-7 Zend ACL implementation - Permission Library [ slim, psr7, acl, permissions, zend ]

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to geggleto-acl

Cors
🔮Supported(Laravel/Lumen/PSR-15/Swoft/Slim/ThinkPHP) - PHP CORS (Cross-origin resource sharing) middleware.
Stars: ✭ 266 (+706.06%)
Mutual labels:  middleware, slim
Laravel Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Stars: ✭ 136 (+312.12%)
Mutual labels:  middleware, acl
Defender
Roles & Permissions for Laravel 8 / 7 / 6 / 5
Stars: ✭ 403 (+1121.21%)
Mutual labels:  middleware, acl
Negroni Authz
negroni-authz is an authorization middleware for Negroni
Stars: ✭ 152 (+360.61%)
Mutual labels:  middleware, acl
Slim Oauth2
Routes and Middleware for Using OAuth2 Server within a Slim Framework API
Stars: ✭ 121 (+266.67%)
Mutual labels:  middleware, slim
Caddy Authz
Caddy-authz is a middleware for Caddy that blocks or allows requests based on access control policies.
Stars: ✭ 221 (+569.7%)
Mutual labels:  middleware, acl
nestjs-toolbox
The repository contains a suite of components and modules for Nest.js
Stars: ✭ 166 (+403.03%)
Mutual labels:  acl
fjage
Framework for Java and Groovy Agents
Stars: ✭ 19 (-42.42%)
Mutual labels:  middleware
access-control
Simple, flexible and reliable access control for NodeJS and Typescript. Supports both RBAC and ABAC.
Stars: ✭ 29 (-12.12%)
Mutual labels:  acl
REST-Api-with-Slim-PHP
REST API with PHP Slim Framework 3 and MySQL
Stars: ✭ 69 (+109.09%)
Mutual labels:  slim
cute
An event-centric publisher/subscribe model for objects inspired by the Qt framework
Stars: ✭ 37 (+12.12%)
Mutual labels:  middleware
Casbin4D
An authorization library that supports access control models like ACL, RBAC, ABAC in Delphi
Stars: ✭ 25 (-24.24%)
Mutual labels:  acl
use
Easily add plugin support to your node.js application.
Stars: ✭ 25 (-24.24%)
Mutual labels:  middleware
vue-acl
Access Control List plugin for VueJS 2.0
Stars: ✭ 381 (+1054.55%)
Mutual labels:  acl
falcon-policy
Policy Middleware for Falcon APIs
Stars: ✭ 30 (-9.09%)
Mutual labels:  middleware
slim-nette-extension
Nette Extension for Slim API micro-framework using middlewares.
Stars: ✭ 17 (-48.48%)
Mutual labels:  slim
node-uploadx
Node.js middleware for handling resumable uploads
Stars: ✭ 17 (-48.48%)
Mutual labels:  middleware
lagan
Lagan is a different take on a CMS, with a focus on flexibility. Built with Slim, Redbean and Twig.
Stars: ✭ 44 (+33.33%)
Mutual labels:  slim
fence
🔰 Framework-agnostic package who provides powerful ACL abilities to JavaScript
Stars: ✭ 64 (+93.94%)
Mutual labels:  acl
tiny-framework
A light wight easy to use RESTful apis framework for education & demo purposes. stripped down framework to the fundamental components that that every one would essentially need to (learn / make a demo application).
Stars: ✭ 13 (-60.61%)
Mutual labels:  slim

Build Status

geggleto-acl

Provides a ACL repository and Middleware using Zend/Permissions/Acl library PSR-7 Compliant

How it works

  • Resources are end-points
  • Roles are a group of resources
  • You can either allow or deny those roles.

The roles a user has are loaded into the AclRepo on every request. I suggest loading them into a session variable rather than pulling them from storage everytime (usage case depending).

The current route is then inspected and compared to the list of accessable resources in a middleware. a 401 is returned if a user is not allowed. If the user is allowed the application is allowed to continue.

By default no message body is provided on the 401, and if you require a page to be rendered then you will need to write your own middleware.

Usage Example

//Define or Pull your ACL's into the following format
/*
$config = [
    "resources" => ["/", "/no", "/yes"],
    "roles" => ["guest", "user1", "user2"],
    "assignments" => [
        "allow" => [
            "guest" => ["/"],
            "user1" => ["/", "/no"],
            "user2" => ["/", "/yes"]
        ],
        "deny" => [
            "guest" => ["/no", "/yes"],
            "user1" => ["/yes"],
            "user2" => ["/no"]
        ]
    ]
];
*/

//In Slim v3
$app->add(\Geggleto\Acl\AclRepository(["guest"], 
//This should be in a nice php file by itself for easy inclusion... include '/path/to/acl/definition.php'
[
    "resources" => ["/", "/no", "/yes"],
    "roles" => ["guest", "user1", "user2"],
    "assignments" => [
        "allow" => [
            "guest" => ["/"],
            "user1" => ["/", "/no"],
            "user2" => ["/", "/yes"]
        ],
        "deny" => [
            "guest" => ["/no", "/yes"],
            "user1" => ["/yes"],
            "user2" => ["/no"]
        ]
    ]
]));

Dynamic Routes

In the case where your resource changes, it is possible to still correctly match by setting a resources with a Route Pattern. By default the system will inspect the $request's 'route' attribute and this Object should return the route pattern with ->getPatter(); Out of the box this will work with Slim 3 routes if you have turned on the 'determineRouteBeforeAppMiddleware' => true option.

Example Config:

return [
    "resources" => ["/", "/login", "/grid", "/404", "/logout", "/roles", "/roles/{pein}"],
    "roles" => ["guest", "grid", "roles"],
    "assignments" => [
        "allow" => [
            "guest" => ["/", "/404", "/login"],
            "grid" => [ '/grid', '/logout' ],
            "roles" => ['/roles', '/roles/{pein}']
        ],
        "deny" => []
    ]
];

If this does not fit your usage, feel free to override the default handler by setting your own via setHandler(callable)

Middleware

You can use the repo class directly which contains this code block... or modify this code block to suit your needs.

$app->add(function (Request $request, Response $res, $next) {
    /** @var $aclRepo AclRepository */ 
    $aclRepo = $this->get(AclRepository::class); //In Slim 3 the container is bound to function definitions
    $allowed = false; // We assume that the user cannot access the route

    $route = '/' . ltrim($request->getUri()->getPath(), '/'); //We construct our path

    try { //Check here... This will pass when a route is simple and there is no route parameters
        $allowed = $aclRepo->isAllowedWithRoles($aclRepo->getRole(), $route);
    } catch (InvalidArgumentException $iae) { //This is executed in cases where there is a route parameters... /user/{id:} 
        $fn = function (ServerRequestInterface $requestInterface, AclRepository $aclRepo) {
            //This will likely only work in Slim 3... This requires the determineRouteBeforeAppMiddleware => true to be set in the container
            $route = $requestInterface->getAttribute('route'); // Grab the route to get the pattern
            if (!empty($route)) {
                foreach ($aclRepo->getRole() as $role) {
                    if ($aclRepo->isAllowed($role, $route->getPattern())) { // check to see fi the user can access the pattern
                        return true; //Is allowed
                    }
                }
            }
            return false;
        };

        $allowed = $fn($request, $aclRepo); // Execute the fail-safe
    }

    if ($allowed) {
        return $next($request, $res);
    } else {
        return $res->withStatus(401); //Is not allowed. if you need to render a template then do that.
    }
});

White listing

You may add a URI path for white listing. The whitelisting is based upon strpos() so you may use a URI fragment to whitelist a whole class of URIs. With this it is possible to whitelist URIs by accident.

Example:

$acl = new Acl();
$acl->addWhitelistItem('/api');

In this example any URI with /api will be whitelisted.

  • /api/*
  • /myexample/api/*
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].