Download the PHP package gburtini/acl without Composer
On this page you can find all versions of the php package gburtini/acl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package acl
Short Description Dependency free, simple access control lists for PHP.
License GPL
Homepage http://github.com/gburtini/PHP-ACL
Informations about the package acl
PHP-ACL: Simple Access Control Lists
A simple, dependency-free (in use) user/login/cookie management, role and user-level access control system.
This is a very straightforward, simple and easy to use user system, ready to be extended for any purpose.
The ACL component is based on Nette\Security which was itself based on Zend_Acl.
Installation
You can clone the repository and work with the files directly, but everything is set up for composer, which makes it simple:
composer require gburtini/acl
Usage
There are three parts to using this package.
- Implementing an Authenticator for your use-case
- Developing the access control lists.
- Integrating the User class.
Each can be complex or simple depending on your use case.
An Authenticator is a class that implements the method ->authenticate($username, $password[, $roles])
, verifies the users name and password (and if specified, requested roles), and returns a unique identifier for the user and a set of roles that belong to him in the format ['id' => 123, 'roles' => ['administrator']]. Some notes are provided in Authenticator.php on some but not all the considerations necessary to write a good authentication system. A SimpleAuthenticator is provided in SimpleAuthenticator.php for demonstration purposes
``
This is not a good authenticator, as it gives users any roles they request (note that requesting roles is optional, you can ignore that parameter and simply return the list of valid roles for this user) and stores usernames and passwords in totality and in plain text. A better Authenticator will interact with your users table or other datastore.
Developing the access control list, requires using the class ACL. An example follows.
Note that you can call
serialize()on the
$acl`` object and will get a version you can store in your database. For more information in how inheritance and role/resources work, the Nette\Security and Zend_Acl documentation applies almost directly to this code.
Finally, to integrate a User class to tie it all together. We can use the built in User or we can extend it to provide some of our own functionality (in particular, storing information other than the identifier about the user). For this demonstration, we'll use the provided User class (in User.php)
``
You're done. That's the whole system.
Note: strong key selection is important. My website provides some code which generates keys for you if you trust me and my server to not be compromised (note: you shouldn't, you should inspect and run the code yourself in the ideal case), fundamentally it is not a lot more sophisicated than a call to openssl_random_pseudo_bytes:
`
Future Work
There is much that can be done, but nothing that I need immediately. Pull requests are invited.
- Change all exceptions to throw different classes so that reasons can be caught cleanly.
- Implement some other authenticators, user classes.
- Document how to extend the user class for your own implementation.
- Verify and extract the crypto required for User.php in to its own dependent package.
- Integrate with gburtini/Hooks to allow events to occur on user instances.
- Document every method in this file (README.md).
- Add "token authentication" system that allows temporary (regular expression or role based?) authentication to be generated. For example, for changing passwords in a recovery your password system.
There is further work that I would prefer to keep out of this package for simplicity, but would be of value to many users of the package:
- User storage functionality (users, including their permissions, written to the database).
- Further user identity functionality (right now, the User class is intended to be extended to provide this).
License
As parts of the code are derived from New BSD licensed code, we have followed in the spirit and this package itself is released under the New BSD.
Novel contributions. Copyright (c) 2015 Giuseppe Burtini.
Zend_Acl original code. Copyright (c) 2005-2015, Zend Technologies USA, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Zend Technologies USA, Inc. or Giuseppe Burtini nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.