2017 © Pedro Peláez
 

library secure

Ssa secure module for ssa framework.

image

ssa/secure

Ssa secure module for ssa framework.

  • Sunday, March 22, 2015
  • by deblockt
  • Repository
  • 1 Watchers
  • 0 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

SSA Secure

Ssa secure is an extention of SSA[https://github.com/deblockt/ssa]., (*1)

This provide a service for manager login., (*2)

Installation

you need to add :, (*3)

``` json "ssa/secure": "dev-master", (*4)


on your composer dependencies. ## Configuration For use this module you need add service on your serviceManager. *config.php* ``` php ServiceManager::getInstance()->registerAllServices(array( 'authenticateService' => array('class' => 'ssa\secure\services\AuthenticateService') ));

On this exemple the service name is authenticateService, but you can choose an other service name., (*5)

After you must configure the module :, (*6)

  • Add security provider : Class used for logon users
  • Change tokenCryptKey : This is the key used to encrypt user id. Change default token key for better security.

config.php ``` php use ssa\secure\SecureConfiguration;, (*7)

// SecurityProvider is your own class who implement ISecurityProvider SecureConfiguration::getInstance()->setSecurityProvider(new SecurityProvider()); SecureConfiguration::getInstance()->setTokenCryptKey('yourCryptKey');, (*8)


*SecurityProvider.php* ``` php <?php use ssa\secure\ISecurityProvider; use ssa\secure\SecureConfiguration; /** * class used for login users */ class SecurityProvider implements ISecurityProvider { /** * method used to authenticate user * * @param string $login the connection login * @param string $mdp the connection password * * @return the userd id. It is is used for generate unique token for this user. null is user not exists. * or array if you need get specifique data on javascript, array need have a id key (it'is a unique if for identifiate user) */ public function authenticate($login, $password) { // here just check the user passord // surely that you need to do an database access if ($password == 'admin') { return array('id' => $login, 'name' => $login); } return null; // user is not recognized } }

Usage

Javascript

You need to add authenticate service on your page :, (*9)

``` html , (*10)


To login user, you just need to do : ``` js authenticateService.login('username', 'password');

To logout user, you just need to do :, (*11)

``` js authenticateService.logout();, (*12)


To get your authenticate info (if your authenticate method return an array) : ``` js authenticateService.getUserInfos()();

Javascript secure listener

Three listeners are available :, (*13)

  • DisconnectListener : Listener called when a service return an error
  • ConnectedListener : Listener called when the login is succefully do
  • BadUserOrPasswordListener : Listener called when the login is badly do. Bad username or password

``` js authenticateService.addDisconnectListener(function(){ $('span.result').html('You are not logged'); });, (*14)

// token is the crypted user id // userInfos is array return by the authenticate method. The is index is not available on client side. authenticateService.addConnectedListener(function(token, userInfos){ $('span.result').html('You are logged, you can call service.'); });, (*15)

authenticateService.addBadUserOrPasswordListener(function(){ $('span.result').html('Bad loggin or password'); });, (*16)


### php If you want secure a service (the user need to be logged to call service), just add @Secure annotation on your service method. ``` php use ssa\secure\annotations\Secure; /** * @author thomas */ class HelloWorld { /** * @Secure * * @param string $userId the userId is automatically add by secure module. It's the id returned by authenticate method * @return string */ public function helloYou($userId) { return 'hello ' .$userId.'!!!'; } }

All Secure service can need userId parameter, this is automatically add by secure module. Warning : this parameter must be the last parameter or nexts parameters must have default value., (*17)

The Versions

22/03 2015

dev-master

9999999-dev

Ssa secure module for ssa framework.

  Sources   Download

The Requires