diff --git a/application/modules/opac/controllers/CasServerController.php b/application/modules/opac/controllers/CasServerController.php index b29566885402c5112b4372607827cf5b3f20fd83..2662ce7e0295760e195bf4cd8cba234b9bbc2fb3 100644 --- a/application/modules/opac/controllers/CasServerController.php +++ b/application/modules/opac/controllers/CasServerController.php @@ -62,15 +62,7 @@ class CasServerController extends ZendAfi_Controller_Action { public function returnFailureTicketResponse($error,$ticket=null) { - $this->getResponse()->setHeader('Content-Type', 'application/xml;charset=utf-8'); - $xml='<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">'; - $xml.='<cas:authenticationFailure code="'.$error.'">'; - if (isset($ticket)) - $xml.=' Ticket '.$ticket.' not recognized'; - - $xml.='</cas:authenticationFailure>'; - $xml.='</cas:serviceResponse>'; - $this->getResponse()->setBody($xml); + $this->_helper->casFailureResponse($error,$ticket); } diff --git a/library/ZendAfi/Controller/Action/Helper/CasFailureResponse.php b/library/ZendAfi/Controller/Action/Helper/CasFailureResponse.php new file mode 100644 index 0000000000000000000000000000000000000000..45b6eeb76ea50bcab118b1a759a32071be37b2e3 --- /dev/null +++ b/library/ZendAfi/Controller/Action/Helper/CasFailureResponse.php @@ -0,0 +1,39 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Controller_Action_Helper_CasFailureResponse extends Zend_Controller_Action_Helper_Abstract { + + public function direct($error,$ticket=null) { + $this->getActionController()->getHelper('ViewRenderer')->setNoRender(); + $this->getResponse()->setHeader('Content-Type', 'application/xml;charset=utf-8'); + $xml='<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">'; + $xml.='<cas:authenticationFailure code="'.$error.'">'; + if (isset($ticket)) + $xml.=' Ticket '.$ticket.' not recognized'; + + $xml.='</cas:authenticationFailure>'; + $xml.='</cas:serviceResponse>'; + $this->getResponse()->setBody($xml); + } + +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/CasValidResponse.php b/library/ZendAfi/Controller/Action/Helper/CasValidResponse.php new file mode 100644 index 0000000000000000000000000000000000000000..032902a7ca826a0c03f1497ef02abf3843a8d920 --- /dev/null +++ b/library/ZendAfi/Controller/Action/Helper/CasValidResponse.php @@ -0,0 +1,51 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Controller_Action_Helper_CasValidResponse extends Zend_Controller_Action_Helper_Abstract { + + + public function direct($user, $ticket, $attributes = []) { + $this->getActionController()->getHelper('ViewRenderer')->setNoRender(); + $this->getResponse()->setHeader('Content-Type', 'application/xml;charset=utf-8'); + + $this->getResponse()->setBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> + <cas:authenticationSuccess> + <cas:user>".$user->getId()."</cas:user> + <cas:proxyGrantingTicket>".$ticket." + </cas:proxyGrantingTicket>". + $this->renderAttributes($attributes). + "</cas:authenticationSuccess> + </cas:serviceResponse>"); + } + + public function renderAttributes($attributes) { + if (!$attributes) + return ''; + $xml = ''; + foreach($attributes as $key => $value) { + $xml .= '<cas:'.$key.'>'.$value.'</cas:'.$key.'>'; + } + return '<cas:attributes>'.$xml.'</cas:attributes>'; + } + +} +?> \ No newline at end of file diff --git a/library/digital_resources/Skilleos/controllers/AuthController.php b/library/digital_resources/Skilleos/controllers/AuthController.php new file mode 100644 index 0000000000000000000000000000000000000000..71f26d2c7bceeb4d1119bb66033ce11fc8d87f43 --- /dev/null +++ b/library/digital_resources/Skilleos/controllers/AuthController.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Skilleos_Plugin_AuthController extends Class_DigitalResource_Controller { + + + + public function servicevalidateAction() { + + $service=$this->_request->getParam('service'); + $ticket=$this->_request->getParam('ticket'); + if (strlen($ticket)<1 || strlen($service)<1) { + return $this->_helper->casFailureResponse('INVALID_REQUEST'); + } + xdebug_break(); + if (!$user = (new Class_CasTicket())->userForTicket($ticket)) + return $this->_helper->casFailureResponse('INVALID_TICKET',$ticket); + + $attributes = ['sn' => $user->getNom(), + 'mail' => $user->getMail(), + 'givenName' => $user->getPrenom()]; + return $this->_helper->casValidResponse($user, $ticket, $attributes); + + + + + } +} +?> \ No newline at end of file diff --git a/library/digital_resources/Skilleos/tests/SkilleosTest.php b/library/digital_resources/Skilleos/tests/SkilleosTest.php index 555ca7ed7e439a4f3e37eb6cb8abeacdb95bdb3a..26037964396ef0ed5a1a6c4fcaeb3158bab41b1b 100644 --- a/library/digital_resources/Skilleos/tests/SkilleosTest.php +++ b/library/digital_resources/Skilleos/tests/SkilleosTest.php @@ -63,9 +63,6 @@ abstract class SkilleosLinkModeLinkTestCase extends ModelTestCase { - - - class SkilleosModulesControllerUserWithGroupWithRightTest extends AbstractControllerTestCase { @@ -73,9 +70,11 @@ class SkilleosModulesControllerUserWithGroupWithRightTest public function setUp() { parent::setUp(); + Storm_Cache::beVolatile(); SkilleosAdminVars::activate(); $user = Class_Users::getIdentity()->beAbonneSIGB(); + $user->setNom('jumper')->setPrenom('jolly')->setMail('jolly@jumper.com'); $group = $this->fixture('Class_UserGroup', ['id' => 1]); @@ -91,6 +90,7 @@ class SkilleosModulesControllerUserWithGroupWithRightTest ]); $user->setUserGroups([$group]); + ZendAfi_Auth::getInstance()->logUser($user); } @@ -103,6 +103,31 @@ class SkilleosModulesControllerUserWithGroupWithRightTest } + /** @test */ + public function validateAuthWithoutTicketShouldAnswerError() { + $this->dispatch('/Skilleos_Plugin/auth/servicevalidate', true); + $this->assertContains('<cas:authenticationFailure code="INVALID_REQUEST">',$this->_response->getBody()); + } + + + /** @test */ + public function validateAuthWithInvalidTicketShouldAnswerError() { + $this->dispatch('/Skilleos_Plugin/auth/servicevalidate/service/blabla/ticket/666', true); + $this->assertContains('<cas:authenticationFailure code="INVALID_TICKET"> Ticket 666 not recognized</cas:authenticationFailure>',$this->_response->getBody()); + } + + + /** @test */ + public function validateWithValidUserTicketShouldAnswerSuccessAndLibraryName() { + + $ticket = (new Class_CasTicket())->getTicketForCurrentUser(); + $this->dispatch('/Skilleos_Plugin/auth/servicevalidate/service/skilleos/ticket/' . $ticket, + true); + $this->assertContains('<cas:user>666</cas:user>',$this->_response->getBody()); + $this->assertContains('<cas:sn>jumper</cas:sn><cas:mail>jolly@jumper.com</cas:mail><cas:givenName>jolly</cas:givenName>',$this->_response->getBody()); + + } + } @@ -142,9 +167,9 @@ class SkilleosModulesControllerTest extends AbstractControllerTestCase { /** @test */ public function withNoGroupShouldDisplayNoAccessMessage() { $no_skilleos = $this->fixture('Class_Users', - ['id' => 56, - 'login' => 'no skilleos', - 'password' => 'no']); + ['id' => 56, + 'login' => 'no skilleos', + 'password' => 'no']); ZendAfi_Auth::getInstance()->logUser($no_skilleos); @@ -188,7 +213,7 @@ abstract class SkilleosServiceTestCase extends AbstractControllerTestCase { ->answers($token_json) ->whenCalled('open_url') ->with('http://moncompte.skilleos.com/rest/api/trainings', - ['Authorization' => "Bearer YTEzMDA1M2Q1ZGRmYmE0YjJkNWQ3MGY3ZGUyYTI3ZWJkMjBjOGI2NzIzMDIzMDc0MDAyYTE0NGJjMTRmMzkzMg"]) + ['Authorization' => "Bearer YTEzMDA1M2Q1ZGRmYmE0YjJkNWQ3MGY3ZGUyYTI3ZWJkMjBjOGI2NzIzMDIzMDc0MDAyYTE0NGJjMTRmMzkzMg"]) ->answers($results_json) ->whenCalled('open_url') ->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/10/thumb_9636_default_big.png') @@ -204,7 +229,7 @@ abstract class SkilleosServiceTestCase extends AbstractControllerTestCase { Skilleos_Service::setDefaultHttpClient($http_client); - $this->_service->setTimeSource(new TimeSourceForTest('2017-02-06 10:00:00')); + $this->_service->setTimeSource(new TimeSourceForTest('2017-02-06 10:00:00')); $this->_service->harvest(); Class_Album::clearCache(); @@ -242,9 +267,9 @@ class SkilleosServiceHarvestTest extends SkilleosServiceTestCase { /** @test */ public function matiereSportEtBienEtreShouldBeCreated() { - $id = Class_Album::find(1)->getMatiere(); - $labels= Class_CodifMatiere::find($id)->getLibelle(); - $this->assertEquals('Sport & Bien-être', $labels); + $id = Class_Album::find(1)->getMatiere(); + $labels= Class_CodifMatiere::find($id)->getLibelle(); + $this->assertEquals('Sport & Bien-être', $labels); }