Download the PHP package efficiently/authority-controller without Composer

On this page you can find all versions of the php package efficiently/authority-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package authority-controller

AuthorityController Build Status

AuthorityController is an PHP authorization library for Laravel 5.3 which restricts what resources a given user is allowed to access.

All permissions are defined in a single location:

config/authority-controller.php

and not duplicated across controllers, routes, views, and database queries.

For Laravel 5.2 supports see AuthorityController 2.2 branch

For Laravel 5.0 or 5.1 supports see AuthorityController 2.1 branch

For Laravel 4.1 or 4.2 supports see AuthorityController 1.2 branch

Demo application

You can see in action this package with this Laravel 5.3 demo application.

Origins and Inspirations

It's an extension of the authority-laravel package.

And a port of the best Ruby authorization library: CanCan.

Authority ports some features of CanCan and this package ports almost all the other features.

Installation

With Composer

  1. Add authority-controller package to your composer.json file to require AuthorityController:

  2. Add the service provider to config/app.php:

  3. Add the aliases (facades) to your Laravel app config file:

  4. This will allow you to access the Authority class through the static interface you are used to with Laravel components.

Configuration

Create Roles and Permissions Tables

We have provided a basic table structure to get you started in creating your roles and permissions.

Publish them to your migrations directory or copy them directly.

Run the migrations

This will create the following tables

To utilize these tables, you can add the following methods to your User model. You will also need to create Role and Permission Model stubs (replacing App\Authority\ with you own namespace)..

Init resource filters and controller methods

In your app/Http/Controllers/Controller.php file, add the ControllerAdditions trait and disable the use of the AuthorizesRequests trait:

NB: If you really need the default Laravel Authorization system, you can use the AuthorizesRequests trait, if you alias its authorize and authorizeResource methods, like this:

Getting Started

AuthorityController expects that auth()->user() return the current authenticated user. Now, by default Laravel 5 handles this.

Defining Authority rules

User permissions are defined in an AuthorityController configuration file.

You can publish the AuthorityController default configuration file with the command below:

This will place a copy of the configuration file at config/authority-controller.php. The config file includes an initialize function, which is a great place to setup your rules and aliases.

See Defining Authority rules for details.

Check Authority rules & Authorization

The current user's permissions can then be checked using the Authority::can() and Authority::cannot() methods in the view and controller.

See Checking Authority rules for more information

The authorize() method in the controller will throw an exception if the user is not able to perform the given action.

Setting this for every action can be tedious, therefore the loadAndAuthorizeResource() method is provided to automatically authorize all actions in a RESTful style resource controller. It will use a before filter to load the resource into an instance variable and authorize it for every action.

See Authorizing Controller Actions for more information.

Exception Handling

The Efficiently\AuthorityController\Exceptions\AccessDenied exception is thrown when calling authorize() in the controller and the user is not able to perform the given action. A message can optionally be provided.

You can catch the exception and modify its behavior in the render() method of the app/Exceptions/Handler.php file. For example here we set the error message to a flash and redirect to the home page.

See Exception Handling for more information.

Documentations

Wiki Docs
Authority Docs

Authority introduction.

Authority-Laravel general usage.

CanCan Wiki Docs

Because AuthorityController is a CanCan port, you can also read the Wiki docs of CanCan here.

Controller additions

Your controllers have now a $params property:

Changelog

 2.3.0-dev

 2.2.0

 2.1.1

 2.1.0

2.0.1

 2.0.0

1.2.4

1.2.3

1.2.2

1.2.1

1.2.0

1.1.3

1.1.2

1.1.1

1.1.0

1.0.0

0.10.0

0.9.0

Missing features

  1. In ControllerResource class, the #load_collection method, who uses in the User model #accessible_by method. Looks complicated. Instead, use specific query scopes with collectionScope option to filtering your data in your collection (e.g. index) controller actions. Because you'll allowing/denying access by roles or check user's authorizations on each record of the collection.
  2. In Ability class, the #attributes_for method. Looks useless with Authority because rules conditions are only possible by Closure not by associative array. And CanCan handles #attribute_for only for Hash (associative array) conditions.
  3. #skip_* methods in ControllerAdditions.
  4. For allow() and deny() methods of Authority, the third argument isn't an optional hash (associative array) of conditions but an anonymous function (Closure):

Good to know

Compatibility

It's only compatible with PHP >= 5.6 and Laravel >= 5.3 framework.

Differences between CanCan and AuthorityController

See Wiki page Differences between CanCan and AuthorityController

Philosophy

It's following the D.R.W.J.P.I. principle:

Don't Reinvent the Wheel, Just Port It ! -- (c) 2013 A.D.

Questions or Problems?

If you have any issues with AuthorityController, please add an issue on GitHub or fork the project and send a pull request.

To get the tests running you should install PHPUnit and run phpunit tests.

Special Thanks

AuthorityController was heavily inspired by CanCan and uses Authority-Laravel.


All versions of authority-controller with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.9
authority-php/authority-laravel Version ~2.4.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package efficiently/authority-controller contains the following files

Loading the files please wait ....