diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index 4ffceaefbfb996ce21fe865c2af097aa1f3e59c9..c358f9ed8837e7cd8165711677bf0f56c06c8556 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -30,6 +30,11 @@ class AuthController extends ZendAfi_Controller_Action { } + public function isLectura() { + return $this->_getParam('lectura', false); + } + + public function isCasRequest() { return strlen($this->getCasServerUrl())>0; } @@ -388,6 +393,10 @@ abstract class Auth_Strategy_Abstract { if ($controller->isCasRequest() && !static::isLogged()) return new Auth_Strategy_Cas_NotLogged($controller); + if ($controller->isLectura()) + return new Auth_Strategy_Lectura($controller); + + if (static::isLogged()) return new Auth_Strategy_Logged($controller); @@ -518,4 +527,32 @@ class Auth_Strategy_Cas_NotLogged extends Auth_Strategy_Cas_Abstract{ } } + +class Auth_Strategy_Lectura extends Auth_Strategy_Abstract { + + + public function handlePost() { + $this->controller->getHelper('ViewRenderer')->setNoRender(); + $response= $this->controller->getResponse(); + $view = $this->controller->view; + $request = $this->controller->getRequest(); + $response->setHeader('Content-Type', 'application/xml;charset=utf-8'); + $login = $request->getPost('CAB'); + $password = $request->getPost('PWD'); + $response->setBody($this->getXmlResponse($view, + ZendAfi_Auth::getInstance()->authenticateLoginPassword($login, $password))); + } + + + protected function getXmlResponse($view,$is_success=true) { + return '<?xml version="1.0" encoding="UTF-8"?>'."\n". + $view->tag('libraryuserauth', + $view->tag('returncode',$is_success? 'success':'error'), + ['timestamp' => date('Ymd-his')]); + + } +} + + + ?> \ No newline at end of file diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index 19da2d6a2cc1707d9ca94db9e037cb90a3ced2b0..bc26d1bf1b310fc70b78701078313e87d762c747 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -127,6 +127,11 @@ class Class_AdminVar extends Storm_Model_Abstract { } + public static function isLecturaEnabled() { + return '' != self::get('LECTURA_DOMAIN'); + } + + public static function beModuleEnabled($module) { self::set($module,1); } diff --git a/library/ZendAfi/Controller/Plugin/Lectura.php b/library/ZendAfi/Controller/Plugin/Lectura.php new file mode 100644 index 0000000000000000000000000000000000000000..6191cf9fdb1b30cf14789fe89c5336cee9dc8ce9 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Lectura.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_Controller_Plugin_Lectura extends Zend_Controller_Plugin_Abstract { + public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) { + if (!Class_AdminVar::isLecturaEnabled('LECTURA_DOMAIN') + || $request->getHttpHost() != Class_AdminVar::get('LECTURA_DOMAIN') + || $request->getScheme() != 'https') + return; + $request->setActionName('login') + ->setControllerName('auth') + ->setParam('lectura', true); + + } +} + +?> \ No newline at end of file diff --git a/library/startup.php b/library/startup.php index 9506d0bb253dc84e01aa626b103c251dc8aeafe6..ba565258361dcc3c2162e80da04b6926c53bd131 100644 --- a/library/startup.php +++ b/library/startup.php @@ -277,6 +277,7 @@ function setupFrontController($cfg) { ->registerPlugin(new ZendAfi_Controller_Plugin_Popup()) ->registerPlugin(new ZendAfi_Controller_Plugin_TogetherJS()) ->registerPlugin(new ZendAfi_Controller_Plugin_CustomFields()) + ->registerPlugin(new ZendAfi_Controller_Plugin_Lectura()) ->setParam('useDefaultControllerAlways', true); diff --git a/tests/application/modules/opac/controllers/AuthControllerTest.php b/tests/application/modules/opac/controllers/AuthControllerTest.php index 1df649a30cc3ff973ad99ca93d768e9e43d54417..cb3d461467383b62fc97745cd7657a6768dc35ae 100644 --- a/tests/application/modules/opac/controllers/AuthControllerTest.php +++ b/tests/application/modules/opac/controllers/AuthControllerTest.php @@ -921,28 +921,69 @@ class AuthControllerPostSimpleSuccessfulWithRedirectTest extends AuthControllerP } +class AuthControllerPostWrongUserFromLecturaClientTest extends AbstractControllerTestCase { - -class AuthControllerPostSuccessfulFromCASClientTest extends AuthControllerPostSimpleSuccessfulTestCase { public function setUp() { parent::setUp(); + $_SERVER['HTTPS']='on'; + $_SERVER['HTTP_HOST'] = 'test.webuser.lectura.fr'; + + $this->fixture('Class_AdminVar', ['id' => 'LECTURA_DOMAIN', + 'valeur' => 'test.webuser.lectura.fr']); + Class_Users::beVolatile(); + $this->postDispatch('/', + ['CAB' => '0007', + 'PWD' => 'toto' ]); - $this->postDispatch('/opac/auth/login', - ['username' => 'foo', - 'password' => 'bar', - 'service' => 'http://www.numilog.com/view?book=bilbo']); } + /** @test */ + public function responseShouldContainsError() { + $this->assertContains('error', $this->_response->getBody()); + } + +} + + +class AuthControllerPostSuccessfulFromLecturaClientTest extends AuthControllerPostSimpleTestCase { + public function setUp() { + parent::setUp(); + $_SERVER['HTTPS']='on'; + $_SERVER['HTTP_HOST'] = 'test.webuser.lectura.fr'; + + $this->fixture('Class_AdminVar', ['id' => 'LECTURA_DOMAIN', + 'valeur' => 'test.webuser.lectura.fr']); + + + $this->fixture('Class_Users', ['id' => 5 , + 'login' => '0007', + 'idabon' => '0007', + 'password' => 'toto']); + + $this->_auth->whenCalled('authenticateLoginPassword') + ->with('0007', 'toto') + ->answers(true); + $this->postDispatch('/', + ['CAB' => '0007', + 'PWD' => 'toto' ]); + + } /** @test */ - public function responseShouldRedirectToCasClientWithTicket() { - $this->assertRedirectTo('http://www.numilog.com/view?book=bilbo&ticket=ST-'.md5(Zend_Session::getId().'2')); + public function controllerShouldBeAuth() { + $this->assertEquals('auth',$this->_request->getControllerName()); } /** @test */ - public function userFooShouldBeLogged() { - $this->assertEquals('foo', Class_Users::getIdentity()->getLogin()); + public function actionShouldBeLogin() { + $this->assertEquals('login',$this->_request->getActionName()); + } + + /** @test */ + public function responseShouldContainsSuccess() { + $this->assertContains('success',$this->_response->getBody()); } + } @@ -971,8 +1012,6 @@ class AuthControllerPostSuccessfulFromMusicMeCASClientTest extends AuthControlle } - - class AuthControllerFromCASClientUserConnectedTest extends AuthControllerNobodyLoggedTestCase { public function setUp() { parent::setUp(); diff --git a/tests/bootstrap_frontcontroller.php b/tests/bootstrap_frontcontroller.php index d4eb60250a4f6427dc8f022767ac7f391c1c8357..4846a3aa3fce0fe63e619cbe6cb9683ecb068831 100644 --- a/tests/bootstrap_frontcontroller.php +++ b/tests/bootstrap_frontcontroller.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Regénère un nouveau front controller pour chaque test, @@ -37,7 +37,8 @@ $controller = Zend_Controller_Front::getInstance() ->registerPlugin(new ZendAfi_Controller_Plugin_SelectionBib()) ->registerPlugin(new ZendAfi_Controller_Plugin_System()) ->registerPlugin(new ZendAfi_Controller_Plugin_TogetherJS()) - ->registerPlugin(new ZendAfi_Controller_Plugin_CustomFields()); + ->registerPlugin(new ZendAfi_Controller_Plugin_CustomFields()) + ->registerPlugin(new ZendAfi_Controller_Plugin_Lectura()); $_SESSION["selection_bib"]=array("message" => 'selection bib sucks', "nb_notices" => 12345,