New Auth method with SSO

This commit is contained in:
Michael RICOIS 2014-12-09 11:28:12 +00:00
parent 5cee230b74
commit 44566343c7
9 changed files with 524 additions and 3 deletions

40
TODELETE Normal file
View File

@ -0,0 +1,40 @@
table => actes_files
library\Application\Model\ActesFiles.php
table commandes
table commandes_erreur
table commandes_kbis
table commandes_pieces
table commandes_statut
table commandes_tarifs => Needed dans GenCourrier
filesGreffes.php
getActes.php
greffeCmdMois.php
greffeCmdTelechargement
Controller/Dashboard
Dashboard
Client => Gestion client, forcer l'ADV a utiliser le nouveau backoffice
Actes et Bilans
Kbis
GenCourrier => dans backoffice
table aide
Cron OK
=============
sendBilanClient
getAltiScore

View File

@ -23,22 +23,31 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$router = $front->getRouter();
$localauthRoute = new Zend_Controller_Router_Route('localauth/', array(
'controller' => 'user',
'action' => 'login'
));
$router->addRoute('localauth', $localauthRoute);
$fichierRoute = new Zend_Controller_Router_Route('fichier/:action/:fichier', array(
'controller' => 'fichier',
'fichier' => '',
));
$router->addRoute('fichier', $fichierRoute);
$printRoute = new Zend_Controller_Router_Route('editer/:action/:fichier', array(
'controller' => 'print',
'fichier' => '',
));
$router->addRoute('localauth', $localauthRoute);
$router->addRoute('fichier', $fichierRoute);
$router->addRoute('print', $printRoute);
$ssoRoute = new Zend_Controller_Router_Route('sso/:partner', array(
'controller' => 'auth',
'action' => 'index',
));
$router->addRoute('sso', $ssoRoute);
return $router;
}

View File

@ -0,0 +1,118 @@
<?php
class AuthController extends Zend_Controller_Action
{
protected $partnerConfig = array(
'inextenso' => array(
'clientId' => 0,
'serviceCode' => 'SSO',
'authType' => 'userSSO',
'login' => 'MAIL',
'token' => 'token',
)
);
/**
* Point d'entrée pour les connexions partenaires.
* L'utilisateur s'identifie sur son portail habituel.
*/
public function indexAction()
{
//Désactiver le layout
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
/**
* Get partner name - see route in bootstrap
*/
$partner = $request->getParam('partner');
if ( array_key_exists($partner, $partnerConfig) ) {
$config = $partnerConfig[$partner];
$params = $request->getParams();
$objectParams = array();
foreach ($params as $label => $value) {
$object = new stdClass();
$object->label = $label;
$object->value = $value;
$objectParams[] = $object;
}
$login = $params[$partnerConfig['login']];
$part = strstr($login, '@', true);
if ($part !== false) {
$login = $part;
}
$token = $params[$partnerConfig['token']];
$ws = new Scores_Ws_Client('gestion', '0.4');
try {
$hash = $ws->ssoAuthenticate($config['clientId'], $login, $token, $objectParams);
//Utilisateur inexistant
if ($hash === false ) {
$this->view->NoUser = true;
//Set form value
$this->view->FormIdentifiant = $login;
$this->view->FormCourriel = $request->getParam('MAIL');
$this->view->FormSiret = $request->getParam('SIRET');
$this->view->FormNom = $request->getParam('LASTNAME');
$this->view->FormPrenom = $request->getParam('FIRSTNAME');
}
//Redirection
else {
$auth = Zend_Auth::getInstance();
//First set partial identity
$identity = new stdClass();
$identity->username = $login;
$identity->password = $hash;
$auth->getStorage()->write($identity);
$adressIp = $_SERVER['REMOTE_ADDR'];
$ws = new Scores_Ws_Client('gestion', '0.3');
$InfosLogin = $ws->getInfosLogin($login, $adressIp);
if ( is_string($InfosLogin) || $InfosLogin->error->errnum != 0 ) {
$this->view->Error = true;
} else {
$identity = $user->updateProfil($InfosLogin);
$auth->getStorage()->write($identity);
//Redirect
$this->redirect('/');
}
}
} catch ( Exception $e ) {
switch ( $e->getCode() ) {
case 'MSG':
$this->view->Message = $e->getMessage();
break;
default:
$this->view->Error = true;
break;
}
}
} else {
$this->view->Message = "Erreur dans les paramètres.";
}
}
public function userssocreateAction()
{
$this->_helper->layout()->disableLayout();
}
/**
* Lien de validation depuis email
* Paramètres
* - login ou email
* - key
* L'action renvoi sur un affichage spécifique suivant le type de client
*/
public function validateAction()
{
$request = $this->getRequest();
//Validation en erreur
//Validation invalide
//Validation Ok => Comment afficher les particularités
}
}

View File

@ -0,0 +1,68 @@
<?php echo $this->doctype(); ?>
<html>
<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headTitle(); ?>
<?php echo $this->headStyle(); ?>
<?php echo $this->headLink(); ?>
<?php echo $this->headScript(); ?>
</head>
<body>
<div id="wrap">
<div class="container">
<h2 class="form-signin-heading">Extranet <small>Scores & Décisions</small></h2>
<?php
//Error
if ($this->Error) {?>
<div><p class="text-danger"><span>Une erreur est survenue</span></p></div>
<?php
}
//Message
else if ($this->Message) {?>
<div style="text-align:center;"><p class="text-danger"><span><?=$this->Message?></span></p></div>
<?php
}
//NoUser
else if ($this->NoUSer) {?>
<p>Votre compte n'existe pas encore. Compléter le formulaire puis valider pour créer votre compte.</p>
<form action="<?=$this->url(array('controller'=>'auth', 'action'=>'userssocreate'))?>" method="post">
<div><label>Identifiant : </label><span><?=$this->FormIdentifiant?></span></div>
<input type="hidden" name="login" value="<?=$this->FormIdentifiant?>"/>
<div><label>Courriel : </label><span><?=$this->FormCourriel?></span></div>
<input type="hidden" name="email" value="<?=$this->FormCourriel?>"/>
<div><label>SIRET : </label><span><?=$this->FormSiret?></span></div>
<input type="hidden" name="siret" value="<?=$this->FormSiret?>"/>
<div><label>Nom : </label><span><?=$this->FormNom?></span></div>
<input type="hidden" name="nom" value="<?=$this->FormNom?>"/>
<div><label>Prenom :</label><span><?=$this->FormPrenom?></span></div>
<input type="hidden" name="prenom" value="<?=$this->FormPrenom?>"/>
<input name="submit" value="Valider" type="submit"/>
</form>
<?php
}
?>
</div>
</div>
<div id="footer">
<div class="container">
<p class="text-muted credit"> &copy; <?=date('Y')?> <a href="http://www.scores-decisions.com">Scores & Décisions SAS</a>.</p>
</div>
</div>
<?php echo $this->inlineScript(); ?>
</body>
</html>

View File

@ -0,0 +1 @@
<?php

View File

@ -12,6 +12,10 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
$checkAuth = false;
}
if ($request->getControllerName()=='auth') {
$checkAuth = false;
}
if ($request->getControllerName()=='fichier'
&& $request->getClientIp(false)=='78.31.45.206') {
$checkAuth = false;

View File

@ -72,6 +72,10 @@ class Application_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstrac
$UserLogin = true;
}
if ( $controller == 'auth' ) {
$UserLogin = true;
}
/**
* Detect IE
*/

View File

@ -0,0 +1,221 @@
<?php
/**
* Configuration
* URL : http://wse.scores-decisions.com
* ServiceName : entreprise
* ServiceVersion : 0.8
*
* SoapClient wsdl = URL + ServiceName + ServiceVersion + ?wsdl
*
* Configuration des paramètres de l'appel
* Appel Soap
* Gestion des erreurs
* Mise en cache
*
* Client ( name, version ) extends Zend_Soap_Client
*
*
* Client/Entreprise08
* Client/Gestion03
* Client/Gestion04
*
* Config ServiceName-Version
* methode
* parametres
* cache
* log => firebug, file, email
* error [
* code error => return (message, false), stop (true, false)
* ]
* arguments
* name => null, defaultvalue
*
*
* Interface qui déclare les méthodes d'appel
*
* Méthodes protégés pour les opérations webservice
* Paramètres de l'opération
* Paramètres spécifique - Mise en cache
* Gestion des erreurs
*/
class Scores_Ws_Client extends Zend_Soap_Client
{
/**
* Configuration des méthodes du service
* @var array
*/
protected $config;
/**
* WebService Url - Add a configuration key in application.ini
* @var string
*/
protected $url = null;
protected $cache;
/**
* Créer l'environnement nécessaire pour le chargement du webservice
* @param string $name
* Nom du service
* @param string $version
* Représente la version du service
* @param string $user
* @throws Exception
*/
public function __construct($name, $version, $user = null)
{
//Configuration de l'application
if (Zend_Registry::isRegistered('config')) {
$c = Zend_Registry::get('config');
$this->url = $c->profil->webservice->url;
} else {
$c = new Zend_Config_Ini(APPLICATION_PATH.'/configs/application.ini');
$this->url = $c->profil->webservice->url;
}
//Configuration du service
$config = include __DIR__ . '/Client/' . ucfirst($name) . '.php';
if ($config === false) {
throw new Exception('Impossible de charger la configuration du service');
}
if (!array_key_exists($version, $config)) {
throw new Exception('Version du service inexistante');
}
$this->config = $config[$version];
// Create WSDL url
$wsdl = $this->url . '/' . $name . '/v' . $version;
if (APPLICATION_ENV == 'development') {
$wsdl.= '?wsdl-auto';
$this->setWsdlCache(WSDL_CACHE_NONE);
} else {
$wsdl.= '?wsdl';
}
$this->setWsdl($wsdl);
if (PHP_SAPI != 'cli' && $user == null) {
$user = new Scores_Utilisateur();
}
if ($user !== null) {
$this->setHttpLogin($user->getLogin());
$this->setHttpPassword($user->getPassword());
}
//Add default options
$options = array(
'features' => SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE,
//'trace' => true,
'encoding' => 'utf-8',
);
$this->setOptions($options);
// Create Cache
$frontend = array(
'lifetime' => 28800,
'automatic_seralization' => true
);
$backend = array(
'cache_dir' => APPLICATION_PATH . '/../data/cache',
);
$this->cache = Zend_Cache::factory('Core', 'File', $frontend, $backend);
}
/**
* (non-PHPdoc)
* @see Zend_Soap_Client::__call()
*/
public function __call($name, $arguments)
{
if ( !array_key_exists($name, $this->config) ) {
throw new Exception("Method $name not exist");
}
//@todo : gestion des paramètres envoyés sous forme d'array
if( is_array($arguments) ) {
}
$methodConfig = $this->config[$name];
//Cache
$cacheEnable = false;
if ( array_key_exists('cache', $methodConfig) ) {
if ( $methodConfig['cache'] === true ) {
$cacheEnable = true;
$cacheId = $name;
if ( count($arguments) > 0 ){
foreach ($arguments as $item) {
$cacheId.= $item;
}
}
}
}
//Cache
if ( $cacheEnable === true ) {
$response = $this->cache->load($cacheId);
if ( $response !== false ) {
return $response;
}
}
//Debug
if ( array_key_exists('debug', $methodConfig) ) {
Zend_Registry::get('firebug')->info(__CLASS__.'->'.$name);
}
try {
$response = parent::__call($name, $arguments);
//Debug
if ( array_key_exists('debug', $methodConfig) ) {
Zend_Registry::get('firebug')->info($response);
}
//Cache
if ( $cacheEnable === true ) {
$this->cache->save($response->{$name.'Result'}, $cacheId);
}
return $response->{$name.'Result'};
} catch ( SoapFault $fault ) {
//Debug
if ( array_key_exists('debug', $methodConfig) ) {
Zend_Registry::get('firebug')->info($fault->faultcode.' - '.$fault->faultstring);
}
//Gestion des SOAP fault
if ( array_key_exists('errorMsg', $methodConfig) ) {
if ( array_key_exists($fault->getCode(), $methodConfig['error']) ) {
throw new Exception($fault->getMessage(), 'MSG');
}
}
//Logging
if ( array_key_exists('log', $methodConfig) ) {
}
return false;
}
}
/**
*
* @param unknown $url
*/
protected function setUrl($url)
{
$this->url = $url;
}
}

View File

@ -0,0 +1,56 @@
<?php
return array(
'0.3' => array(
'getCategory' => null,
'getClientTarif' => null,
'getClientTarifs' => null,
'getEmail' => null,
'getInfosLogin' => null,
'getListeClients' => null,
'getListeDroits' => null,
'getListePrefs' => null,
'getListeUtilisateurs' => null,
'getLogs' => null,
'getLogsClients' => null,
'getNextLogin' => null,
'getPrestation' => null,
'getPrestations' => null,
'getService' => null,
'getServiceUsers' => null,
'getServices' => null,
'getUser' => null,
'searchLogin' => null,
'setCGU' => null,
'setClient' => null,
'setClientTarif' => null,
'setEmail' => null,
'setInfosLogin' => null,
'setParam' => null,
'setPrestation' => null,
'setService' => null,
'setSurveillancesMail' => null,
'setUserService' => null,
),
'0.4' => array(
'getCategory' => null,
'getClient' => null,
'getClientServices' => null,
'getClients' => null,
'getService' => null,
'getServices' => null,
'getUser' => null,
'getUserEmail' => null,
'getUsers' => null,
'loginAuthenticate' => null,
'setCGU' => null,
'setService' => null,
'setServiceParam' => null,
'setUser' => null,
'setUserEmail' => null,
'setUserPassword' => null,
'setUserSSO' => null,
'ssoAuthenticate' => array(
'errorMsg' => array('SSO'),
),
),
);