diff --git a/VERSIONS_WIP/155214 b/VERSIONS_WIP/155214 new file mode 100644 index 0000000000000000000000000000000000000000..ac45bd17c33b1edd261dc0708dd0bac3bb57b50c --- /dev/null +++ b/VERSIONS_WIP/155214 @@ -0,0 +1 @@ + - fonctionnalité #155214 : seveur CAS : prise en compte du paramètre 'gateway' qui permet de rediriger l'utilisateur sans demander l'authentification \ No newline at end of file diff --git a/library/Class/Auth/Cas.php b/library/Class/Auth/Cas.php index c74b6f18b7a4eb15bcef187628b6c68b37bf4c5c..1084f58e2a238772686c2ad3446f8f72d396b765 100644 --- a/library/Class/Auth/Cas.php +++ b/library/Class/Auth/Cas.php @@ -117,6 +117,16 @@ class Class_Auth_CasLogged extends Class_Auth_Logged { class Class_Auth_CasNotLogged extends Class_Auth_NotLogged { use Trait_Auth_CasAware; + public function processLogin() { + if ($this->_getParam('gateway')) { + $this->redirect_url = $this->_getServerUrl(); + return $this->_handleRedirect(); + } + + return parent::processLogin(); + } + + protected function _doOnLoginSuccess() { if (!$this->_hasPermission()) { $this->controller->notify($this->_('Vous n\'avez pas les droits d\'accès à la ressource')); diff --git a/library/digital_resources/OmekaS/controllers/IndexController.php b/library/digital_resources/OmekaS/controllers/IndexController.php index 3e347458c584d8e3b5906cc58706f36cbb9e014a..0a4ba21bd19a2f52fb6dc738bd4aecf5c2eaa90e 100644 --- a/library/digital_resources/OmekaS/controllers/IndexController.php +++ b/library/digital_resources/OmekaS/controllers/IndexController.php @@ -43,10 +43,11 @@ class OmekaS_Plugin_IndexController extends Class_DigitalResource_Controller { if ($profile_serializer->isSsoMandatory($sso_type) || Class_Users::hasIdentity()) { $url = ($base_url = $data_profile->getItemBaseUrl()) - ? $base_url . 'cas/login?redirect_url=' . urlencode($url) + ? $base_url . 'cas/login?' . http_build_query(['gateway' => 'true', + 'redirect_url' => $url]) : $url_404; } $this->_javascriptRedirectTo($url); } -} \ No newline at end of file +} diff --git a/tests/application/modules/opac/controllers/CasServerControllerTest.php b/tests/application/modules/opac/controllers/CasServerControllerTest.php index de7c2dc5ca20d51194df68b9733af3766269a703..d8d9e4721001038f9d7c5b88b93b09c4655da254 100644 --- a/tests/application/modules/opac/controllers/CasServerControllerTest.php +++ b/tests/application/modules/opac/controllers/CasServerControllerTest.php @@ -135,6 +135,25 @@ class CasServerControllerValidateActionTest extends AbstractControllerTestCase { } + /** @test */ + public function loginOnCasOneZeroWithGatewayTrueShouldRedirectToServiceWithoutTicket() { + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch(sprintf('/opac/cas-server-v10/login?service=%s&gateway=true', + urlencode('http://test.com?ressource_id=1234&message=go'))); + $this->assertRedirectTo('http://test.com?ressource_id=1234&message=go', + $this->getResponseLocation()); + } + + + /** @test */ + public function loginOnCasOneZeroWithGatewayTagadaShouldRedirectToServiceWithoutTicket() { + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/opac/cas-server-v10/login?service=http://test.com&gateway=tagada'); + $this->assertRedirectTo('http://test.com', + $this->getResponseLocation()); + } + + /** @test */ public function loginOnCasOneZeroWithoutOpenedSessionShouldDisplayLoginForm() { ZendAfi_Auth::getInstance()->clearIdentity(); diff --git a/tests/scenarios/OmekaS/OmekaSViewNoticeTest.php b/tests/scenarios/OmekaS/OmekaSViewNoticeTest.php index 6b879513745fa957ded5ba7344db8e1895ed75ec..0197ba99421dd1d912a1bc7ef26f4efd5b7c5edb 100644 --- a/tests/scenarios/OmekaS/OmekaSViewNoticeTest.php +++ b/tests/scenarios/OmekaS/OmekaSViewNoticeTest.php @@ -99,7 +99,7 @@ class OmekaSViewNoticeLoggedTest extends OmekaSViewNoticeTestCase { /** @test */ public function moduleSsoActionShouldRedirectToOmekaServerWithCasWhenMandatory() { $this->dispatch('/modules/sso/id/1288'); - $this->assertContains('document.location.href="https://omekas.myserver.com/cas/login?redirect_url=https%3A%2F%2Fomekas.myserver.com%2Fs%2Fslug%2Fitem%2F88398"', + $this->assertContains('document.location.href="https://omekas.myserver.com/cas/login?gateway=true&redirect_url=https%3A%2F%2Fomekas.myserver.com%2Fs%2Fslug%2Fitem%2F88398"', $this->_response->getBody()); } @@ -108,7 +108,7 @@ class OmekaSViewNoticeLoggedTest extends OmekaSViewNoticeTestCase { public function moduleSsoActionShouldRedirectToOmekaServerWithCasWhenOptional() { $this->_setItemCasSso(2); $this->dispatch('/modules/sso/id/1288'); - $this->assertContains('document.location.href="https://omekas.myserver.com/cas/login?redirect_url=https%3A%2F%2Fomekas.myserver.com%2Fs%2Fslug%2Fitem%2F88398"', + $this->assertContains('document.location.href="https://omekas.myserver.com/cas/login?gateway=true&redirect_url=https%3A%2F%2Fomekas.myserver.com%2Fs%2Fslug%2Fitem%2F88398"', $this->_response->getBody()); } @@ -150,7 +150,7 @@ class OmekaSViewNoticeNotLoggedTest extends OmekaSViewNoticeTestCase { /** @test */ public function moduleSsoActionShouldRedirectToOmekaServerWithCasWhenMandatory() { $this->dispatch('/modules/sso/id/1288'); - $this->assertContains('document.location.href="https://omekas.myserver.com/cas/login?redirect_url=https%3A%2F%2Fomekas.myserver.com%2Fs%2Fslug%2Fitem%2F88398"', + $this->assertContains('document.location.href="https://omekas.myserver.com/cas/login?gateway=true&redirect_url=https%3A%2F%2Fomekas.myserver.com%2Fs%2Fslug%2Fitem%2F88398"', $this->_response->getBody()); }