dev-master
9999999-devSsa secure module for ssa framework.
The Requires
Ssa secure module for ssa framework.
Ssa secure is an extention of SSA[https://github.com/deblockt/ssa]., (*1)
This provide a service for manager login., (*2)
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)
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 } }
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()();
Three listeners are available :, (*13)
``` 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)
Ssa secure module for ssa framework.