From 28c8274cc8337b7897e9c292f1b408dd0ea9330b Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Tue, 18 Dec 2007 13:12:22 +0000 Subject: [PATCH] Change the code from redirecting by setting the location header to using the redirect helper function. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@131 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php | 4 ++-- www/auth/login-auto.php | 2 +- www/auth/login-ldapmulti.php | 3 +-- www/auth/login-radius.php | 5 ++--- www/auth/login.php | 4 +--- www/example-simple/saml2-example.php | 7 +++++-- www/example-simple/shib13-example.php | 8 +++++--- www/openid/provider/server.php | 16 ++-------------- www/saml2/idp/SSOService.php | 15 +++++++-------- www/saml2/sp/AssertionConsumerService.php | 3 +-- www/saml2/sp/SingleLogoutService.php | 2 +- www/saml2/sp/idpdisco.php | 3 +-- www/saml2/sp/initSLO.php | 2 +- www/saml2/sp/initSSO.php | 6 ++---- www/shib13/idp/SSOService.php | 3 +-- www/shib13/sp/AssertionConsumerService.php | 3 +-- www/shib13/sp/idpdisco.php | 3 +-- www/shib13/sp/initSSO.php | 10 +++------- 18 files changed, 38 insertions(+), 61 deletions(-) diff --git a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php index 3e9775ad2..8d5fc5e36 100644 --- a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php +++ b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php @@ -12,6 +12,7 @@ */ require_once('SimpleSAML/Configuration.php'); +require_once('SimpleSAML/Utilities.php'); require_once('SimpleSAML/XML/MetaDataStore.php'); require_once('SimpleSAML/XHTML/Template.php'); @@ -79,8 +80,7 @@ class SimpleSAML_Bindings_SAML20_HTTPRedirect { } else { - header("Location: " . $redirectURL); - + SimpleSAML_Utilities::redirect($redirectURL); } diff --git a/www/auth/login-auto.php b/www/auth/login-auto.php index b04566883..b2352c748 100644 --- a/www/auth/login-auto.php +++ b/www/auth/login-auto.php @@ -91,6 +91,6 @@ $session->setAttributes($attributes); /* Return the user to the page set in the RelayState parameter. */ $returnto = $_REQUEST['RelayState']; -header("Location: " . $returnto); +SimpleSAML_Utilities::redirect($returnto); ?> diff --git a/www/auth/login-ldapmulti.php b/www/auth/login-ldapmulti.php index 145de7c96..a154ec10a 100644 --- a/www/auth/login-ldapmulti.php +++ b/www/auth/login-ldapmulti.php @@ -88,8 +88,7 @@ if (isset($_POST['username'])) { $session->setNameIDFormat('urn:oasis:names:tc:SAML:2.0:nameid-format:transient'); $returnto = $_REQUEST['RelayState']; - header("Location: " . $returnto); - exit(0); + SimpleSAML_Utilities::redirect($returnto); } // ldap_close() om du vil, men frigjoeres naar skriptet slutter diff --git a/www/auth/login-radius.php b/www/auth/login-radius.php index 47dc0efff..50603545e 100644 --- a/www/auth/login-radius.php +++ b/www/auth/login-radius.php @@ -53,10 +53,9 @@ if (isset($_POST['username'])) { $session->setAuthenticated(true); $session->setAttributes($attributes); + $returnto = $_REQUEST['RelayState']; - header("Location: " . $returnto); - - exit(0); + SimpleSAML_Utilities::redirect($returnto); case RADIUS_ACCESS_REJECT: diff --git a/www/auth/login.php b/www/auth/login.php index 8e9411464..7150dee58 100644 --- a/www/auth/login.php +++ b/www/auth/login.php @@ -155,9 +155,7 @@ if (isset($_POST['username'])) { $logger->log(LOG_NOTICE, $session->getTrackID(), 'AUTH', 'ldap', 'OK', $username, $username . ' successfully authenticated'); - header("Location: " . $relaystate); - exit(0); - + SimpleSAML_Utilities::redirect($relaystate); } // ldap_close() om du vil, men frigjoeres naar skriptet slutter } diff --git a/www/example-simple/saml2-example.php b/www/example-simple/saml2-example.php index 141cd31c3..7a1caa6c5 100644 --- a/www/example-simple/saml2-example.php +++ b/www/example-simple/saml2-example.php @@ -19,8 +19,11 @@ $session = SimpleSAML_Session::getInstance(); /* Check if valid local session exists.. */ if (!isset($session) || !$session->isValid() ) { - header('Location: /' . $config->getValue('baseurlpath') . 'saml2/sp/initSSO.php?RelayState=' . urlencode(SimpleSAML_Utilities::selfURL())); - exit(0); + SimpleSAML_Utilities::redirect( + '/' . $config->getValue('baseurlpath') . + 'saml2/sp/initSSO.php', + array('RelayState' => SimpleSAML_Utilities::selfURL()) + ); } $attributes = $session->getAttributes(); diff --git a/www/example-simple/shib13-example.php b/www/example-simple/shib13-example.php index 7ff181079..bdf6fd844 100644 --- a/www/example-simple/shib13-example.php +++ b/www/example-simple/shib13-example.php @@ -15,9 +15,11 @@ $session = SimpleSAML_Session::getInstance(); if (!isset($session) || !$session->isValid() ) { - header('Location: /' . $config->getValue('baseurlpath') . 'shib13/sp/initSSO.php?RelayState=' . urlencode(SimpleSAML_Utilities::selfURL())); - // . '&idpentityid=' . $idpentityid ); - exit(0); + SimpleSAML_Utilities::redirect( + '/' . $config->getValue('baseurlpath') . + 'shib13/sp/initSSO.php', + array('RelayState' => SimpleSAML_Utilities::selfURL()) + ); } $et = new SimpleSAML_XHTML_Template($config, 'status.php'); diff --git a/www/openid/provider/server.php b/www/openid/provider/server.php index c97a32ad0..93fa87de0 100644 --- a/www/openid/provider/server.php +++ b/www/openid/provider/server.php @@ -235,9 +235,7 @@ function check_authenticated_user() { $authurl = SimpleSAML_Utilities::addURLparameter('/' . $config->getValue('baseurlpath') . $idpmeta['auth'], 'RelayState=' . urlencode($relaystate)); - - header('Location: ' . $authurl); - exit(0); + SimpleSAML_Utilities::redirect($authurl); } $attributes = $session->getAttributes(); @@ -333,17 +331,7 @@ function action_sites() */ function redirect_render($redir_url) { - /* - $headers = array(http_found, - header_content_text, - header_connection_close, - 'Location: ' . $redir_url, - ); - */ - header('Location: ' . $redir_url); - -// $body = sprintf(redirect_message, $redir_url); - // return array($headers, $body); + SimpleSAML_Utilities::redirect($redir_url); } diff --git a/www/saml2/idp/SSOService.php b/www/saml2/idp/SSOService.php index e0c25874e..a53d59b4f 100644 --- a/www/saml2/idp/SSOService.php +++ b/www/saml2/idp/SSOService.php @@ -108,16 +108,15 @@ if (isset($_GET['SAMLRequest'])) { if (!$session->isAuthenticated() ) { - $relaystate = SimpleSAML_Utilities::selfURLNoQuery() . - '?RequestID=' . urlencode($requestid); - $authurl = SimpleSAML_Utilities::addURLparameter('/' . $config->getValue('baseurlpath') . $idpmeta['auth'], - 'RelayState=' . urlencode($relaystate)); - $logger->log(LOG_NOTICE, $session->getTrackID(), 'SAML2.0', 'IdP.SSOService', 'AuthNext', $idpmeta['auth'], 'Will go to authentication module ' . $idpmeta['auth']); - - header('Location: ' . $authurl); - exit(0); + + $relaystate = SimpleSAML_Utilities::selfURLNoQuery() . + '?RequestID=' . urlencode($requestid); + $authurl = '/' . $config->getValue('baseurlpath') . $idpmeta['auth']; + + SimpleSAML_Utilities::redirect($authurl, + array('RelayState' => $relaystate)); } else { try { diff --git a/www/saml2/sp/AssertionConsumerService.php b/www/saml2/sp/AssertionConsumerService.php index a9dce52a3..cc26bb50c 100644 --- a/www/saml2/sp/AssertionConsumerService.php +++ b/www/saml2/sp/AssertionConsumerService.php @@ -39,8 +39,7 @@ try { $relayState = $authnResponse->getRelayState(); if (isset($relayState)) { - header("Location: " . $relayState); - exit(0); + SimpleSAML_Utilities::redirect($relayState); } else { echo 'Could not find RelayState parameter, you are stucked here.'; } diff --git a/www/saml2/sp/SingleLogoutService.php b/www/saml2/sp/SingleLogoutService.php index dc0f4a977..0403eaca6 100644 --- a/www/saml2/sp/SingleLogoutService.php +++ b/www/saml2/sp/SingleLogoutService.php @@ -83,7 +83,7 @@ if (isset($_GET['SAMLRequest'])) { if (isset($_GET['RelayState'])) { - header('Location: ' . $_GET['RelayState']); + SimpleSAML_Utilities::redirect($_GET['RelayState']); } else { echo 'You are now successfully logged out.'; diff --git a/www/saml2/sp/idpdisco.php b/www/saml2/sp/idpdisco.php index d95629665..a87327066 100644 --- a/www/saml2/sp/idpdisco.php +++ b/www/saml2/sp/idpdisco.php @@ -43,8 +43,7 @@ if (isset($_GET['idpentityid'])) { $idpentityid = $_GET['idpentityid']; $returnurl = SimpleSAML_Utilities::addURLparameter($return, $returnidparam . '=' . $idpentityid); - header('Location: ' . $returnurl); - exit(0); + SimpleSAML_Utilities::redirect($returnurl); } diff --git a/www/saml2/sp/initSLO.php b/www/saml2/sp/initSLO.php index 33e1a1780..4971e55ab 100644 --- a/www/saml2/sp/initSLO.php +++ b/www/saml2/sp/initSLO.php @@ -67,7 +67,7 @@ if (isset($session) ) { $logger->log(LOG_NOTICE, $session->getTrackID(), 'SAML2.0', 'SP.initSLO', 'AlreadyLoggedOut', 'N/A', 'User is already logged out. Go back to relaystate'); - header('Location: ' . $relaystate ); + SimpleSAML_Utilities::redirect($relaystate); #print_r($metadata->getMetaData('sam.feide.no')); #print_r($req); diff --git a/www/saml2/sp/initSSO.php b/www/saml2/sp/initSSO.php index ac77f5184..20ec003ad 100644 --- a/www/saml2/sp/initSSO.php +++ b/www/saml2/sp/initSSO.php @@ -48,9 +48,7 @@ if (!isset($session) || !$session->isValid() ) { $returnURL = urlencode(SimpleSAML_Utilities::selfURL()); $discservice = '/' . $config->getValue('baseurlpath') . 'saml2/sp/idpdisco.php?entityID=' . $spentityid . '&return=' . $returnURL . '&returnIDParam=idpentityid'; - header('Location: ' . $discservice); - exit(0); - + SimpleSAML_Utilities::redirect($discservice); } @@ -93,7 +91,7 @@ if (!isset($session) || !$session->isValid() ) { $logger->log(LOG_NOTICE, $session->getTrackID(), 'SAML2.0', 'SP.initSSO', 'AlreadyAuthenticated', '-', 'Go back to RelayState'); - header('Location: ' . $relaystate ); + SimpleSAML_Utilities::redirect($relaystate); } else { $et = new SimpleSAML_XHTML_Template($config, 'error.php'); diff --git a/www/shib13/idp/SSOService.php b/www/shib13/idp/SSOService.php index 14ec85a25..b032a88e5 100644 --- a/www/shib13/idp/SSOService.php +++ b/www/shib13/idp/SSOService.php @@ -100,8 +100,7 @@ if (!$session->isAuthenticated() ) { $relaystate = SimpleSAML_Utilities::selfURLNoQuery() . '?RequestID=' . urlencode($requestid); $authurl = SimpleSAML_Utilities::addURLparameter('/' . $config->getValue('baseurlpath') . $idpmeta['auth'], 'RelayState=' . urlencode($relaystate)); - header('Location: ' . $authurl); - exit(0); + SimpleSAML_Utilities::redirect($authurl); } else { try { diff --git a/www/shib13/sp/AssertionConsumerService.php b/www/shib13/sp/AssertionConsumerService.php index 789021d05..d9c01baaa 100644 --- a/www/shib13/sp/AssertionConsumerService.php +++ b/www/shib13/sp/AssertionConsumerService.php @@ -41,8 +41,7 @@ try { if (isset($session)) { $relayState = $authnResponse->getRelayState(); if (isset($relayState)) { - header("Location: " . $relayState); - exit(0); + SimpleSAML_Utilities::redirect($relayState); } else { echo 'Could not find RelayState parameter, you are stucked here.'; } diff --git a/www/shib13/sp/idpdisco.php b/www/shib13/sp/idpdisco.php index f6a2ab454..6bbd2eb9d 100644 --- a/www/shib13/sp/idpdisco.php +++ b/www/shib13/sp/idpdisco.php @@ -39,8 +39,7 @@ if (isset($_GET['idpentityid'])) { $idpentityid = $_GET['idpentityid']; $returnurl = SimpleSAML_Utilities::addURLparameter($return, $returnidparam . '=' . $idpentityid); - header('Location: ' . $returnurl); - exit(0); + SimpleSAML_Utilities::redirect($returnurl); } diff --git a/www/shib13/sp/initSSO.php b/www/shib13/sp/initSSO.php index d81f5771d..90a4b4a33 100644 --- a/www/shib13/sp/initSSO.php +++ b/www/shib13/sp/initSSO.php @@ -49,8 +49,7 @@ if (!isset($session) || !$session->isValid() ) { $returnURL = urlencode(SimpleSAML_Utilities::selfURL()); $discservice = '/' . $config->getValue('baseurlpath') . 'shib13/sp/idpdisco.php?entityID=' . $spentityid . '&return=' . $returnURL . '&returnIDParam=idpentityid'; - header('Location: ' . $discservice); - exit(0); + SimpleSAML_Utilities::redirect($discservice); } @@ -62,10 +61,7 @@ if (!isset($session) || !$session->isValid() ) { $ar->setRelayState($_GET['RelayState']); $url = $ar->createRedirect($idpentityid); - header('Location: ' . $url); -// echo 'IdP: ' . $idpentityid . ' SP: ' . $spentityid; - - exit(0); + SimpleSAML_Utilities::redirect($url); } catch(Exception $exception) { @@ -85,7 +81,7 @@ if (!isset($session) || !$session->isValid() ) { $relaystate = $session->getRelayState(); if (isset($relaystate) && !empty($relaystate)) { - header('Location: ' . $relaystate ); + SimpleSAML_Utilities::redirect($relaystate); } else { $et = new SimpleSAML_XHTML_Template($config, 'error.php'); -- GitLab