承接 ssa/secure 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ssa/secure

Composer 安装命令:

composer require ssa/secure

包简介

Ssa secure module for ssa framework.

README 文档

README

Ssa secure is an extention of SSA[https://github.com/deblockt/ssa].

This provide a service for manager login.

Installation

you need to add :

	"ssa/secure": "dev-master"

on your composer dependencies.

Configuration

For use this module you need add service on your serviceManager.

config.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.

After you must configure the module :

  • 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

use ssa\secure\SecureConfiguration;

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

SecurityProvider.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 :

<!-- Your service url, may be different -->
<script type="text/javascript" src="javascript.php?service=authenticateService"></script>

To login user, you just need to do :

authenticateService.login('username', 'password');

To logout user, you just need to do :

authenticateService.logout();

To get your authenticate info (if your authenticate method return an array) :

authenticateService.getUserInfos()();

Javascript secure listener

Three listeners are available :

  • 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
authenticateService.addDisconnectListener(function(){
	$('span.result').html('You are not logged');
});

// 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.');
});

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

php

If you want secure a service (the user need to be logged to call service), just add @Secure annotation on your service method.

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.

统计信息

  • 总下载量: 39
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-02-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固