From 0a856dff37bc84d56c2095f7351c23a2b1a3fbf8 Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Wed, 5 Aug 2015 16:51:07 +0200 Subject: [PATCH] Remove duplicated code. --- lib/SimpleSAML/XHTML/IdPDisco.php | 21 +++++++++++------ modules/discopower/lib/PowerIdPDisco.php | 29 +----------------------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/lib/SimpleSAML/XHTML/IdPDisco.php b/lib/SimpleSAML/XHTML/IdPDisco.php index f01e7f4d8..065e2e50d 100644 --- a/lib/SimpleSAML/XHTML/IdPDisco.php +++ b/lib/SimpleSAML/XHTML/IdPDisco.php @@ -505,15 +505,14 @@ class SimpleSAML_XHTML_IdPDisco /** - * Handles a request to this discovery service. + * Check if an IdP is set or if the request is passive, and redirect accordingly. * - * The IdP disco parameters should be set before calling this function. + * @return void If there is no IdP targeted and this is not a passive request. */ - public function handleRequest() + protected function start() { $idp = $this->getTargetIdp(); if ($idp !== null) { - $extDiscoveryStorage = $this->config->getString('idpdisco.extDiscoveryStorage', null); if ($extDiscoveryStorage !== null) { $this->log('Choice made ['.$idp.'] (Forwarding to external discovery storage)'); @@ -530,15 +529,23 @@ class SimpleSAML_XHTML_IdPDisco ); \SimpleSAML\Utils\HTTP::redirectTrustedURL($this->returnURL, array($this->returnIdParam => $idp)); } - - return; } if ($this->isPassive) { $this->log('Choice not made. (Redirecting the user back without answer)'); \SimpleSAML\Utils\HTTP::redirectTrustedURL($this->returnURL); - return; } + } + + + /** + * Handles a request to this discovery service. + * + * The IdP disco parameters should be set before calling this function. + */ + public function handleRequest() + { + $this->start(); // no choice made. Show discovery service page $idpList = $this->getIdPList(); diff --git a/modules/discopower/lib/PowerIdPDisco.php b/modules/discopower/lib/PowerIdPDisco.php index 26c4efd49..57581494c 100644 --- a/modules/discopower/lib/PowerIdPDisco.php +++ b/modules/discopower/lib/PowerIdPDisco.php @@ -185,34 +185,7 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco { * The IdP disco parameters should be set before calling this function. */ public function handleRequest() { - - $idp = $this->getTargetIdp(); - if($idp !== NULL) { - - $extDiscoveryStorage = $this->config->getString('idpdisco.extDiscoveryStorage',NULL); - if ($extDiscoveryStorage !== NULL) { - $this->log('Choice made [' . $idp . '] (Forwarding to external discovery storage)'); - \SimpleSAML\Utils\HTTP::redirectTrustedURL($extDiscoveryStorage, array( - 'entityID' => $this->spEntityId, - 'IdPentityID' => $idp, - 'returnIDParam' => $this->returnIdParam, - 'isPassive' => 'true', - 'return' => $this->returnURL - )); - - } else { - $this->log('Choice made [' . $idp . '] (Redirecting the user back. returnIDParam=' . $this->returnIdParam . ')'); - \SimpleSAML\Utils\HTTP::redirectTrustedURL($this->returnURL, array($this->returnIdParam => $idp)); - } - - return; - } - - if ($this->isPassive) { - $this->log('Choice not made. (Redirecting the user back without answer)'); - \SimpleSAML\Utils\HTTP::redirectTrustedURL($this->returnURL); - return; - } + $this->start(); /* No choice made. Show discovery service page. */ $idpList = $this->getIdPList(); -- GitLab