2017 © Pedro Peláez
 

library security

image

xervice/security

  • Wednesday, July 25, 2018
  • by mibexx
  • Repository
  • 1 Watchers
  • 0 Stars
  • 64 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Scrutinizer Code Quality Code Coverage, (*1)

Implement security service to xervice., (*2)

Installation

composer require xervice/security

Configuration

The security module is only to provide your own authentication methods. You can define them by extending the SecurityDataProvider::getAuthenticatorList., (*3)

<?php

namespace App\Security;

use Xervice\Security\SecurityDependencyProvider as XerviceSecurityDependencyProvider;

class SecurityDependencyProvider extends XerviceSecurityDependencyProvider
{
    /**
     * Give a list of valid authenticator (string => AuthenticatorInterface::class)
     * e.g.
     * token => tokenAuthenticator::class
     *
     * @return array
     */
    protected function getAuthenticatorList(): array
    {
        return [
            'myauth' => MyAuthenticator::class
        ];
    }

}

Authenticator

To define own authenticator, you have to implement the interface \Xervice\Security\Business\Authenticator\AuthenticatorInterface., (*4)

Example, (*5)

<?php

namespace App\MyModule\Business\Authenticator;

use DataProvider\AuthenticatorDataProvider;
use DataProvider\SimpleCredentialsDataProvider;
use Xervice\Security\Business\Dependency\Authenticator\AuthenticatorInterface;
use Xervice\Security\Business\Exception\SecurityException;

class MyAuthenticator implements AuthenticatorInterface
{
    /**
     * @param \DataProvider\AuthenticatorDataProvider $dataProvider
     *
     * @throws \Xervice\Security\Business\Exception\SecurityException
     */
    public function authenticate(AuthenticatorDataProvider $dataProvider): void
    {
        if (!($dataProvider->getAuthData() instanceof SimpleCredentialsDataProvider)) {
            throw new SecurityException('Incorrect DataProvider for authenticator');
        }

        if (
            $dataProvider->getAuthData()->getUsername() !== 'staticusername'
            && $dataProvider->getAuthData()->getPassword() !== 'staticpassword'
        ) {
            throw new SecurityException('Authorization failed');
        }
    }
}

Usage

To use the security module, you can authorize with the facade:, (*6)

$credentials = new SimpleCredentialsDataProvider();
$credentials
    ->setUsername('staticusername')
    ->setPassword('staticpassword');

$auth = new AuthenticatorDataProvider();
$auth->setAuthData($credentials);

$securityFacade = Locator::getInstance()->security()->facade()->authenticate(
    'myauthenticator',
    $auth
);

The Versions

25/07 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Bertram

25/07 2018

2.0.2

2.0.2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Bertram

25/07 2018

2.0.1

2.0.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Bertram

25/07 2018

2.0.0

2.0.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Bertram

23/07 2018

1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Bertram