Download the PHP package barryvdh/laravel-security without Composer

On this page you can find all versions of the php package barryvdh/laravel-security. 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 laravel-security

Laravel Security Component

Version 0.2.x@dev is for Laravel 5. Use 0.1.x for Laravel 4!

This packages integrates Symfony Security Core in Laravel, mainly to use the Voters to check acces to roles/objects. See Symfony Authorization

Install

Add this package to your composer.json and run composer update

"barryvdh/laravel-security": "0.2.x@dev"

After updating, add the ServiceProvider to ServiceProvider array in config/app.php

'Barryvdh\Security\SecurityServiceProvider'

You can optionally add the Facade as well, to provide faster access to the Security component.

'Security' => 'Barryvdh\Security\Facade',

Configure

You can publish the config to change the strategy and add your own Role Hierarchy, to configure which roles inherit from each other.

 $ php artisan vendor:publish config

//config/security.php
'role_hierarchy' => array(
       'ROLE_ADMIN' => array('ROLE_USER'),
       'ROLE_SUPER_ADMIN' => array('ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH')
 )

Voters

By default, only 2 Voters are included:

To use roles, add a function getRoles() to your User model, which returns an array of Role strings (Note: roles must begin with ROLE_)

public function roles(){
    return $this->belongsToMany('Role');
}
public function getRoles(){
    return $this->roles()->lists('name');
}

You can add voters by adding them to the config.

'voters' => [
    ...
    'App\Security\MyVoter.php',
],

You can also add voters by extending $app['security.voters'] or using the facade:

Security::addVoter(new MyVoter());

Voters have to implement VoterInterface. You can define which attributes (ie. ROLE_ADMIN, IS_AUTHENTICATED, EDIT etc) and which objects the voter can handle. The voter will be called to vote on an attribute (and possibly an object) and allow, deny or abstain access. Based on the strategy, the final decision is made based on the votes. (By default, 1 allow is enough)

You can access the User object with $token->getUser(); For an example, see the Symfony Cookbook about Voters

Checking access

You can check access using to IoC Container, the facade and a helper function:

App::make('security.authorization_checker')->isGranted('ROLE_ADMIN');
Security::isGranted('edit', $post);
is_granted('AUTH');

The first argument is the attribute you want to check, the second is an optional object, on which you want to check the access. For example, you can write a Voter to check if the current user can edit a comment, based on his ownership on that object or his role.

Filters

You can use this in Laravel's Route Filters, both in the routes and in controllers.

Route::get('admin', array('before' => 'is_granted:ROLE_ADMIN', function(){..}));
Route::filter('is_granted', function($route, $request, $attribute, $parameter=null){
    if (!is_granted($attribute, $route->getParameter($parameter)))
        return Redirect::route('login');
});

If you set up Model Binding, you have easy access to the objects.

Route::model('company', 'Company');
Route::get('companies/{company}', array('uses'=> 'CompanyController@getView', 'before' => 'is_granted:view,company'));

All versions of laravel-security with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
illuminate/support Version 4.x
symfony/security-core Version *
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 barryvdh/laravel-security contains the following files

Loading the files please wait ....