Skip to content

Commit

Permalink
Merge pull request #5
Browse files Browse the repository at this point in the history
Replace ACL component from Zend with Laminas
  • Loading branch information
mcaskill authored Mar 2, 2020
2 parents daaff65 + b66bb3b commit 1f9581d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 35 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Charcoal User
=============

User defintion (as Charcoal Model), authentication and authorization (with Zend ACL).
User defintion (as Charcoal Model), authentication and authorization (with Laminas ACL).


# Table of content
Expand All @@ -27,7 +27,7 @@ The preferred (and only supported) way of installing _charcoal-user_ is with **c
## Dependencies

- PHP 7.1+
- `zendframework/zend-permissions-acl`
- `laminas/laminas-permissions-acl`
- `locomotivemtl/charcoal-object`

# The User object
Expand Down Expand Up @@ -75,7 +75,7 @@ For quick prototypes or small projects, a full concrete class is provided as `\C

# Authorization

User authorization is managed with a role-based _Access Control List_ (ACL). Internally, it uses [`zendframework/zend-permissions-acl`](https://github.com/zendframework/zend-permissions-acl) for the ACL logic. It is recommended to read the [Zend ACL documentation](https://zendframework.github.io/zend-permissions-acl/) to learn more about how it all works.
User authorization is managed with a role-based _Access Control List_ (ACL). Internally, it uses [`laminas/laminas-permissions-acl`](https://github.com/laminas/laminas-permissions-acl) for the ACL logic. It is recommended to read the [Laminas ACL documentation](https://docs.laminas.dev/laminas-permissions-acl/) to learn more about how it all works.

There are 2 main concepts that must be managed, either from JSON config files or in the database (which works well with `locomotivemtl/charcoal-admin`), **roles** and **permissions**.

Expand All @@ -102,9 +102,8 @@ To set up ACL, it is highly recommended to use the `\Charcoal\User\Acl\Manager`.
```

```php
// Dependencies from `zendframework/zend-permissions`
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Resource\GenericResource as AclResource;
use Laminas\Permissions\Acl\Acl;
use Laminas\Permissions\Acl\Resource\GenericResource as AclResource;

// Dependencies from `charcoal-user`
use Charcoal\User\Acl\Manager as AclManager;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require": {
"php": ">7.1",
"psr/log": "^1.0",
"zendframework/zend-permissions-acl": "^2.6",
"laminas/laminas-permissions-acl": "^2.7",
"locomotivemtl/charcoal-object": "~0.7",
"locomotivemtl/charcoal-config": "~0.10",
"locomotivemtl/charcoal-factory": "~0.4",
Expand Down
28 changes: 14 additions & 14 deletions src/Charcoal/User/Acl/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

// From 'zendframework/zend-permissions'
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Role\GenericRole;
// From 'laminas/laminas-permissions-acl'
use Laminas\Permissions\Acl\Acl;
use Laminas\Permissions\Acl\Role\GenericRole;

/**
* Manage ACL roles and permissions from config (arrays) or database.
Expand All @@ -32,9 +32,9 @@ public function __construct(array $data)
}

/**
* @param Acl $acl The Zend Acl instant to load permissions to.
* @param array $permissions The array of permissions, in [role=>details] array.
* @param string $resource The Acl resource (string identifier) to load roles and permissions into.
* @param Acl $acl The Laminas Acl instant to load permissions to.
* @param array $permissions The array of permissions, in [role=>details] array.
* @param string $resource The Acl resource (string identifier) to load roles and permissions into.
* @return void
*/
public function loadPermissions(Acl &$acl, array $permissions, $resource = '')
Expand All @@ -45,10 +45,10 @@ public function loadPermissions(Acl &$acl, array $permissions, $resource = '')
}

/**
* @param Acl $acl The Zend Acl instance to load permissions to.
* @param PDO $dbh The PDO database instance.
* @param string $table The table where to fetch the roles and permissions.
* @param string $resource The Acl resource (string identifier) to load roles and permissions into.
* @param Acl $acl The Laminas Acl instance to load permissions to.
* @param PDO $dbh The PDO database instance.
* @param string $table The table where to fetch the roles and permissions.
* @param string $resource The Acl resource (string identifier) to load roles and permissions into.
* @return void
*/
public function loadDatabasePermissions(Acl &$acl, PDO $dbh, $table, $resource = '')
Expand All @@ -75,10 +75,10 @@ public function loadDatabasePermissions(Acl &$acl, PDO $dbh, $table, $resource =
}

/**
* @param Acl $acl The Zend Acl instant to add permissions to.
* @param string $role The role (string identifier) to add.
* @param array $permissions The permissions details (array) to add.
* @param string $resource The Acl resource (string identifier) to add roles and permissions into.
* @param Acl $acl The Laminas Acl instant to add permissions to.
* @param string $role The role (string identifier) to add.
* @param array $permissions The permissions details (array) to add.
* @param string $resource The Acl resource (string identifier) to add roles and permissions into.
* @return void
*/
private function addRoleAndPermissions(Acl &$acl, $role, array $permissions, $resource)
Expand Down
4 changes: 2 additions & 2 deletions src/Charcoal/User/AclAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use RuntimeException;

// From 'zendframework/zend-permissions-acl'
use Zend\Permissions\Acl\Acl;
// From 'laminas/laminas-permissions-acl'
use Laminas\Permissions\Acl\Acl;

/**
* Provides access control list.
Expand Down
6 changes: 3 additions & 3 deletions src/Charcoal/User/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

// From 'zendframework/zend-permissions'
use Zend\Permissions\Acl\Acl;
// From 'laminas/laminas-permissions-acl'
use Laminas\Permissions\Acl\Acl;

// From 'charcoal-user'
use Charcoal\User\UserInterface;
Expand All @@ -23,7 +23,7 @@
* The required dependencies are:
*
* - `logger` A PSR3 logger instance.
* - `acl` A Zend ACL (Access-Control-List) instance.
* - `acl` A Laminas ACL (Access-Control-List) instance.
* - `resource` The ACL resource identifier (string).
*
* ## Checking permissions
Expand Down
4 changes: 2 additions & 2 deletions src/Charcoal/User/ServiceProvider/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Pimple\Container;
use Pimple\ServiceProviderInterface;

// From 'zendframework/zend-permissions-acl'
use Zend\Permissions\Acl\Acl;
// From 'laminas/laminas-permissions-acl'
use Laminas\Permissions\Acl\Acl;

// From 'charcoal-user'
use Charcoal\User\Authenticator;
Expand Down
6 changes: 3 additions & 3 deletions tests/Charcoal/User/Acl/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// From Pimple
use Pimple\Container;

// From 'zendframework/zend-permissions'
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Resource\GenericResource as Resource;
// From 'laminas/laminas-permissions-acl'
use Laminas\Permissions\Acl\Acl;
use Laminas\Permissions\Acl\Resource\GenericResource as Resource;

// From 'charcoal-user'
use Charcoal\User\Acl\Manager;
Expand Down
8 changes: 4 additions & 4 deletions tests/Charcoal/User/AuthorizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// From Pimple
use Pimple\Container;

// From 'zendframework/zend-permissions'
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Role\GenericRole as Role;
use Zend\Permissions\Acl\Resource\GenericResource as Resource;
// From 'laminas/laminas-permissions-acl'
use Laminas\Permissions\Acl\Acl;
use Laminas\Permissions\Acl\Role\GenericRole as Role;
use Laminas\Permissions\Acl\Resource\GenericResource as Resource;

// From 'charcoal-user'
use Charcoal\User\Authorizer;
Expand Down

0 comments on commit 1f9581d

Please sign in to comment.