Last active
August 29, 2015 14:04
-
-
Save Ellrion/ca66b6ef159237ae8c3d to your computer and use it in GitHub Desktop.
SimpleSecurity integration with Laravel (https://github.com/Ellrion/SimpleSecurity)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// access to routes. access allow for admin or manager users | |
Route::group(['prefix' => 'adminka', 'before' => 'acl:admin+manager'], function() { | |
Route::controller('/', 'TestController'); | |
}); | |
//in code. views some only for ussers who is admin and manager together | |
if (Security::isGranted('admin*manager')) { | |
echo '...'; | |
} | |
//... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* application & route filters | |
*/ | |
//... | |
Route::filter('acl', function($route, $request, $value) { | |
if (!Security::isGranted($value)) { | |
App::abort(403, 'Access deny'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* file in config dir | |
* example acl list | |
*/ | |
return array( | |
'user:' => function ($user, $params) { | |
return !empty($user->id) && !empty($params['user']) | |
&& (int)$params['user']===(int)$user->id; | |
} | |
, 'rand' => function ($user, $params) { | |
return rand(0,1) ? 'user:18' : 'user:21'; | |
} | |
, 'admin' => function ($user, $params) { | |
return !empty($user->type) && User::ADMIN_TYPE === (int)$user->type; | |
} | |
, 'manager' => function ($user, $params) { | |
return !empty($user->type) && User::MANAGER_TYPE === (int)$user->type; | |
} | |
, 'advertiser' => function ($user, $params) { | |
return !empty($user->type) && User::ADVERTISER_TYPE === (int)$user->type; | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Facade; | |
/** | |
* @see \Ellrion\SimpleSecurity\Security | |
*/ | |
class SecurityFacade extends Facade { | |
/** | |
* Get the registered name of the component. | |
* | |
* @return string | |
*/ | |
protected static function getFacadeAccessor() { return 'security'; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\ServiceProvider; | |
use Ellrion\SimpleSecurity\Security; | |
class SecurityServiceProvider | |
extends ServiceProvider | |
{ | |
public function register() | |
{ | |
$this->app->singleton('security', function($app) { | |
return new Security($app['config']['security'], $app['auth']->user()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment