2017 © Pedro Peláez
 

library security

Security package for Laravel 5 projects in Digbang.

image

digbang/security

Security package for Laravel 5 projects in Digbang.

  • Friday, June 22, 2018
  • by guiwoda
  • Repository
  • 20 Watchers
  • 4 Stars
  • 7,937 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 56 Versions
  • 15 % Grown

The README.md

Security

Security package for new laravel projects., (*1)

Usage

Add the SecurityServiceProvider to your config/app.php file:, (*2)

'providers' => [
    Digbang\Security\Laravel\SecurityServiceProvider::class,
];

To use this package, you need to define a Context which you need to secure. URLs inside this Context will have access to the SecurityApi configured for them. This way, you may have multiple Contexts running on a single application., (*3)

Add as many contexts as you need in a ServiceProvider :: boot() of your own:, (*4)

<?php namespace App\Providers;

use Digbang\Security\SecurityContext;
use Digbang\Security\Configurations\SecurityContextConfiguration;

class MyServiceProvider extends \Illuminate\Support\ServiceProvider
{
    public function boot(SecurityContext $securityContext)
    {
        $configuration = new SecurityContextConfiguration('ecommerce');

        // customize the configuration object as needed...

        $securityContext->add($configuration);
    }
}

And then refer to this context in your routing (as a route middleware):, (*5)

<?php
$router->group(['middleware' => 'security:ecommerce'], function(Router $router){

    // Controllers inside this routing group will be able to ask for an instance
    // of the Digbang\Security\Contracts\SecurityApi interface.

    $router->get('/', ['as' => 'foo', 'uses' => 'FooController@index']);
});

The Digbang\Security\Contracts\SecurityApi interface gives access to all of this package's functionality. In most cases, it works as a wrapper of the Cartalyst\Sentinel\Sentinel object., (*6)

Refer to the documentation in each method to understand its uses., (*7)

Users

Basic authentication functionality is accessible directly through the SecurityApi object., (*8)

To access the UserRepository object, call $securityApi->users()., (*9)

Reminders

Reminders are randomly generated codes related to a user, frequently used in reset password cycles., (*10)

To access the reminders functionality, use the ReminderRepository with $securityApi->reminders()., (*11)

Persistences

Persistences are session and cookie tokens generated to persist a logged-in session through time., (*12)

To access the persistences functionality, use the PersistenceRepository with $securityApi->persistences()., (*13)

Checkpoints

Checkpoints are custom logic to be executed every time a login attempt happens. The Security package comes with two checkpoints: Activations and Throttles., (*14)

Activations

The Activation checkpoint checks if a user has already activated his account every time he or she logs in. When this check fails, a NotActivatedException is thrown., (*15)

To access the activations functionality, use the ActivationRepository with $securityApi->activations()., (*16)

Throttling

The Throttling checkpoint monitors failed login attempts to prevent DDoS attacks. It logs three different types of attempts, and reacts to each of them differently:, (*17)

  • Global attempts: All login attempts inside the configured context will log a global attempt.
  • IP attempts: Attempts coming from the same IP will be logged to recognize possible attackers.
  • User attempts: Multiple failed logins to the same user account will be logged to identify a possible victim.

Each type of attempt has two configurations:, (*18)

  • Thresholds (int or array): Represents the amount of attempts needed before the system is blocked. An array of qty_attempts => block_time can be used to block access for a given time based on the amount of failed attempts.
  • Interval (int): Represents the time (in seconds) that the system will block further attempts on this type.

You may change this configurations through the SecurityContextConfiguration object. The defaults are:, (*19)

'global' => [
    'interval' => 900,
    'thresholds' => [
        10 => 1,
        20 => 2,
        30 => 4,
        40 => 8,
        50 => 16,
        60 => 12
    ]
],
'ip' => [
    'interval' => 900,
    'thresholds' => 5
],
'user' => [
    'interval' => 900,
    'thresholds' => 5
]

To access the throttling functionality, use the ThrottleRepository with $securityApi->throttles()., (*20)

Roles

Roles group users together and allow an administrator to give (or refuse) access to resources to a group of users., (*21)

Roles may be disabled through the SecurityContextConfiguration object if not needed., (*22)

To access the roles functionality, use the RoleRepository with $securityApi->roles()., (*23)

Permissions

Permissions are functionality identifiers that are used to grant or deny access to parts of the system to specific users or roles., (*24)

By default, a RoutePermissionRepository object will check available permissions by parsing the routes action array in search of a permission key. This strategy can be changed by implementing a different kind of Digbang\Security\Permissions\PermissionRepository, and changing the SecurityContextConfiguration accordingly., (*25)

Permissions may also be disabled through the SecurityContextConfiguration object if not needed., (*26)

To access the permissions functionality, use the PermissionRepository with $securityApi->permissions()., (*27)

Generating URLs

The PermissibleUrlGenerator is an extension of Laravel's UrlGenerator interface. The default implementation, PermissionAwareUrlGenerator, will check if the currently logged-in user has access to the requested url and throw a Digbang\Security\Permissions\PermissionException if he or she does not., (*28)

You may access this functionality through the $securityApi->url() method., (*29)

Custom objects

The Security package extends the Cartalyst\Sentinel interfaces with more functionality. By default, an implementation of each interface (eg.: Digbang\Security\Users\User) can be found in the same namespace (eg.:Digbang\Security\Users\DefaultUser.), (*30)

If you wish to use a custom implementation of any Entity, these are the steps you have to follow:, (*31)

  • you must either:
    • extend the repository implementation (eg.: Digbang\Security\Users\DoctrineUserRepository) with one of your own
    • or you may decide to implement the repository interface (eg.: Digbang\Security\Users\UserRepository) by yourself.
  • you must implement all the methods in the corresponding interface (eg.: Digbang\Security\Users\User.)
  • you must configure this in the SecurityContextConfiguration object, as shown above.
  • you may reuse the entity trait (eg.: Digbang\Security\Users\UserTrait.)
  • you may reuse the mapping trait (eg.: Digbang\Security\Users\UserMappingTrait.)

The Versions

07/10 2015

3.0.x-dev

3.0.9999999.9999999-dev

Security package for Laravel 5 projects in Digbang.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

07/10 2015

3.0.1

3.0.1.0

Security package for Laravel 5 projects in Digbang.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

06/10 2015

3.0.0

3.0.0.0

Security package for Laravel 5 projects in Digbang.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

06/10 2015

dev-sentinel

dev-sentinel

Security package for Laravel 5 projects in Digbang.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

13/07 2015

dev-laravel4

dev-laravel4

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

13/07 2015

2.1.3

2.1.3.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

10/06 2015

2.1.2

2.1.2.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

10/06 2015

2.1.1

2.1.1.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

10/06 2015

2.1.0

2.1.0.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

08/06 2015
01/06 2015

2.0.6

2.0.6.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

01/06 2015

2.0.5

2.0.5.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

22/05 2015

2.0.4

2.0.4.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

19/05 2015

2.0.3

2.0.3.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

30/04 2015

2.0.2

2.0.2.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

16/03 2015

2.0.1

2.0.1.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda

11/03 2015

2.0.0

2.0.0.0

Security package for new laravel projects.

  Sources   Download

The Requires

 

The Development Requires

by Guido Contreras Woda