diff --git a/config-templates/authmemcookie.php b/config-templates/authmemcookie.php index 537c07c8339d6f4f140f9042f72e18f5d625230f..b9f585d29f74539b1daf05fb374b85b79caf06ce 100644 --- a/config-templates/authmemcookie.php +++ b/config-templates/authmemcookie.php @@ -6,6 +6,12 @@ $config = array( + /* + * What type of login Auth MemCookie will use. Can be either 'saml2' or 'shib13'. + * The default value is 'saml2'. + */ + 'loginmethod' => 'saml2', + /* * This is the name of the cookie we should save the session id in. The value of this option must match the * Auth_memCookie_CookieName option in the Auth MemCookie configuration. The default value is 'AuthMemCookie'. diff --git a/lib/SimpleSAML/AuthMemCookie.php b/lib/SimpleSAML/AuthMemCookie.php index a316041d90de4a7eddbb0e33651e61efd3d8d122..b9ec11f8fab6ca1c376545ca7968803638878bbb 100644 --- a/lib/SimpleSAML/AuthMemCookie.php +++ b/lib/SimpleSAML/AuthMemCookie.php @@ -46,6 +46,25 @@ class SimpleSAML_AuthMemCookie { } + /** + * Retrieve the login method which should be used to authenticate the user. + * + * @return The login type which should be used for Auth MemCookie. + */ + public function getLoginMethod() { + $loginMethod = $this->amcConfig->getValue('loginmethod', 'saml2'); + $supportedLogins = array( + 'saml2', + 'shib13', + ); + if(!in_array($loginMethod, $supportedLogins, TRUE)) { + throw new Exception('Configuration option \'loginmethod\' contains an invalid value.'); + } + + return $loginMethod; + } + + /** * This function retrieves the name of the cookie from the configuration. * diff --git a/www/authmemcookie.php b/www/authmemcookie.php index 4fcb18cb7e228a6fc3d89e57348194c4b0b251e5..fa6c40e05aae425ea205c2962ccb96c969715518 100644 --- a/www/authmemcookie.php +++ b/www/authmemcookie.php @@ -26,11 +26,27 @@ try { $amc = SimpleSAML_AuthMemCookie::getInstance(); /* Check if the user is authorized. We attempt to authenticate the user if not. */ - if (!$session->isValid('saml2') ) { - SimpleSAML_Utilities::redirect( - '/' . $globalConfig->getBaseURL() . 'saml2/sp/initSSO.php', - array('RelayState' => SimpleSAML_Utilities::selfURL()) - ); + $loginMethod = $amc->getLoginMethod(); + switch($loginMethod) { + case 'saml2': + if (!$session->isValid('saml2') ) { + SimpleSAML_Utilities::redirect( + '/' . $globalConfig->getBaseURL() . 'saml2/sp/initSSO.php', + array('RelayState' => SimpleSAML_Utilities::selfURL()) + ); + } + break; + case 'shib13': + if (!$session->isValid('shib13') ) { + SimpleSAML_Utilities::redirect( + '/' . $globalConfig->getBaseURL() . 'shib13/sp/initSSO.php', + array('RelayState' => SimpleSAML_Utilities::selfURL()) + ); + } + break; + default: + /* Should never happen, as the login method is checked in the AuthMemCookie class. */ + throw new Exception('Invalid login method.'); }