Get Client Ip in the soap server constructor

This commit is contained in:
Michael RICOIS 2014-09-18 09:41:46 +00:00
parent efe13d9b24
commit 4495b356a9
2 changed files with 39 additions and 15 deletions

View File

@ -80,7 +80,7 @@ class ServiceController extends Zend_Controller_Action
} else {
$pathServiceUrl = 'clients/'.$client.'/v'.$version.'?wsdl';
}
//On redéfini le nom du service
// On redéfini le nom du service
$serviceClassName = 'Entreprise';
$fichierWsdl = $clientClassName.'-'.$serviceClassName.'-'.$version.'.wsdl';
@ -100,7 +100,7 @@ class ServiceController extends Zend_Controller_Action
}
//Get map of WSDL type to PHP Classes
// Get map of WSDL type to PHP Classes
$classmap = include $pathServiceClassIni;
//Inclusion des classes de données
@ -133,7 +133,7 @@ class ServiceController extends Zend_Controller_Action
$wsdl->dump($fichierWsdl);
echo "Le fichier $fichierWsdl a été généré";
//Génération/Fourniture du wsdl
// Génération/Fourniture du wsdl
} elseif (isset($_GET['wsdl']) && !file_exists($fichierWsdl)) {
$wsdl->dump($fichierWsdl);
if (!headers_sent()) {
@ -149,7 +149,10 @@ class ServiceController extends Zend_Controller_Action
// Fourniture du service
} else {
// Traitement
// Get Ip Connexion
$ip = $this->getRequest()->getClientIp(true);
// Start SOAP Server
if (APPLICATION_ENV == 'production' && file_exists($fichierWsdl)) {
$server = new Zend_Soap_Server($fichierWsdl);
} else {
@ -157,15 +160,19 @@ class ServiceController extends Zend_Controller_Action
$server = new Zend_Soap_Server('http://'.$hostName.'/'.$pathServiceUrl);
}
// Instantiate object to serve
$objToServe = new $serviceClassName($ip);
// Configure Server
$server->setSoapFeatures(SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS);
$server->setClassmap($classmap);
$server->setEncoding('UTF-8');
$server->registerFaultException(array('Scores_Ws_Exception'));
$server->setWsiCompliant(true);
$server->setObject(new $serviceClassName());
$server->setObject($objToServe);
$server->handle();
//Pour débuggage ultime
// Pour débuggage ultime
$debug = false;
if ($debug){
$request = $server->getLastRequest();

View File

@ -16,7 +16,7 @@ class Scores_Ws_Server
{
/**
* User information
* @var array
* @var object
*/
protected $User;
@ -56,12 +56,17 @@ class Scores_Ws_Server
*/
public $serviceVersion = null;
/**
* Ip Client
* @var string
*/
protected $ipClient = null;
/**
* List all application IPs
* @var array
*/
protected $listApplicationIp = array (
'88.190.55.221', //Extranet - sd-46528 - to migrate
'195.154.174.221', //Extranet - sd-46528
'91.121.157.194', //Extraet - ns359466
'78.31.45.206', //SDSL RAMBOUILLET
@ -345,7 +350,7 @@ class Scores_Ws_Server
'9020' => 'Requête incorrecte',
);
public function __construct()
public function __construct($ip = null)
{
defined('DATETIME')
|| define ('DATETIME', date('YmdHis'));
@ -361,6 +366,8 @@ class Scores_Ws_Server
defined('TIME_LISIBLE')
|| define ('TIME_LISIBLE', substr(DATETIME,8,2).':'.substr(DATETIME,10,2).':'.substr(DATETIME,12,2));
$this->ipClient = $ip;
}
/**
@ -512,12 +519,7 @@ class Scores_Ws_Server
$this->authMethod = 'soapheader';
}
/**
* @todo : with proxy get the original IP
* $request->getClientIp(true);
*/
$this->authenticated = $this->checkAuth($username, $password, $_SERVER['REMOTE_ADDR']);
$this->authenticated = $this->checkAuth($username, $password, $this->ipClient);
if ( $this->authenticated === false ) {
$this->sendError('0900');
} elseif ( $this->authenticated !== true ) {
@ -590,6 +592,20 @@ class Scores_Ws_Server
*/
protected function checkAuth($login, $password, $ipConnexion)
{
/**
* @todo :
* Information a retourner pour les applications
* id, idClient, login, email, civilite, nom, prenom, acceptationCGU
* droits, pref
*
* Pour la gestion des erreurs en retour
* actif
* dateDebutCompte, dateFinCompte
*
* AccesWS => Service ? ou utilisateur
*
*/
$userM = new Application_Model_Sdv1Utilisateurs();
$sql = $userM->select()
->setIntegrityCheck(false)
@ -610,6 +626,7 @@ class Scores_Ws_Server
$result = $userM->fetchRow($sql);
// Aucun résultat, l'utilisateur n'existe pas ou est inactif
if ( null === $result ) {
debugLog('W',"CheckAuth $login/$password inexistant ou inactif (IP=$ipConnexion)", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return false;