Skip to content
Snippets Groups Projects
Commit 33840c2a authored by Thijs Kinkhorst's avatar Thijs Kinkhorst
Browse files

saml idp endpoints: check early and consistently whether the SAML IdP is enabled

They are outside of the module so can be called when the module is
disabled, which gives an error somewhere deep in the call stack.
Check for all endpoints whether saml2-idp is enabled in config
and whether the module is enabled before doing anything else.
parent a22b0b78
No related branches found
No related tags found
No related merge requests found
...@@ -23,8 +23,8 @@ use SimpleSAML\Metadata; ...@@ -23,8 +23,8 @@ use SimpleSAML\Metadata;
use SimpleSAML\Store; use SimpleSAML\Store;
$config = Configuration::getInstance(); $config = Configuration::getInstance();
if (!$config->getBoolean('enable.saml20-idp', false)) { if (!$config->getBoolean('enable.saml20-idp', false) || !Module::isModuleEnabled('saml')) {
throw new Error\Error('NOACCESS'); throw new Error\Error('NOACCESS', null, 403);
} }
$metadata = Metadata\MetaDataStorageHandler::getMetadataHandler(); $metadata = Metadata\MetaDataStorageHandler::getMetadataHandler();
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
* from a SAML 2.0 SP, parses, and process it, and then authenticates the user and sends the user back * from a SAML 2.0 SP, parses, and process it, and then authenticates the user and sends the user back
* to the SP with an Authentication Response. * to the SP with an Authentication Response.
* *
* @author Andreas Åkre Solberg, UNINETT AS. <andreas.solberg@uninett.no>
* @package SimpleSAMLphp * @package SimpleSAMLphp
*/ */
...@@ -13,6 +12,7 @@ require_once('../../_include.php'); ...@@ -13,6 +12,7 @@ require_once('../../_include.php');
use Exception; use Exception;
use SimpleSAML\Assert\Assert; use SimpleSAML\Assert\Assert;
use SimpleSAML\Configuration;
use SimpleSAML\Error; use SimpleSAML\Error;
use SimpleSAML\IdP; use SimpleSAML\IdP;
use SimpleSAML\Logger; use SimpleSAML\Logger;
...@@ -21,6 +21,11 @@ use SimpleSAML\Module; ...@@ -21,6 +21,11 @@ use SimpleSAML\Module;
Logger::info('SAML2.0 - IdP.SSOService: Accessing SAML 2.0 IdP endpoint SSOService'); Logger::info('SAML2.0 - IdP.SSOService: Accessing SAML 2.0 IdP endpoint SSOService');
$config = Configuration::getInstance();
if (!$config->getBoolean('enable.saml20-idp', false) || !Module::isModuleEnabled('saml')) {
throw new Error\Error('NOACCESS', null, 403);
}
$metadata = Metadata\MetaDataStorageHandler::getMetadataHandler(); $metadata = Metadata\MetaDataStorageHandler::getMetadataHandler();
$idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
$idp = IdP::getById('saml2:' . $idpEntityId); $idp = IdP::getById('saml2:' . $idpEntityId);
......
...@@ -12,6 +12,7 @@ require_once('../../_include.php'); ...@@ -12,6 +12,7 @@ require_once('../../_include.php');
use Exception; use Exception;
use SimpleSAML\Assert\Assert; use SimpleSAML\Assert\Assert;
use SimpleSAML\Configuration;
use SimpleSAML\Error; use SimpleSAML\Error;
use SimpleSAML\IdP; use SimpleSAML\IdP;
use SimpleSAML\Logger; use SimpleSAML\Logger;
...@@ -21,6 +22,11 @@ use SimpleSAML\Utils; ...@@ -21,6 +22,11 @@ use SimpleSAML\Utils;
Logger::info('SAML2.0 - IdP.SingleLogoutService: Accessing SAML 2.0 IdP endpoint SingleLogoutService'); Logger::info('SAML2.0 - IdP.SingleLogoutService: Accessing SAML 2.0 IdP endpoint SingleLogoutService');
$config = Configuration::getInstance();
if (!$config->getBoolean('enable.saml20-idp', false) || !Module::isModuleEnabled('saml')) {
throw new Error\Error('NOACCESS', null, 403);
}
$metadata = Metadata\MetaDataStorageHandler::getMetadataHandler(); $metadata = Metadata\MetaDataStorageHandler::getMetadataHandler();
$idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
$idp = IdP::getById('saml2:' . $idpEntityId); $idp = IdP::getById('saml2:' . $idpEntityId);
......
...@@ -3,18 +3,25 @@ ...@@ -3,18 +3,25 @@
require_once('../../_include.php'); require_once('../../_include.php');
use SimpleSAML\Assert\Assert; use SimpleSAML\Assert\Assert;
use SimpleSAML\Configuration;
use SimpleSAML\Error; use SimpleSAML\Error;
use SimpleSAML\Idp; use SimpleSAML\Idp;
use SimpleSAML\Logger; use SimpleSAML\Logger;
use SimpleSAML\Metadata; use SimpleSAML\Metadata;
use SimpleSAML\Module;
use SimpleSAML\Utils; use SimpleSAML\Utils;
Logger::info('SAML2.0 - IdP.initSLO: Accessing SAML 2.0 IdP endpoint init Single Logout');
$config = Configuration::getInstance();
if (!$config->getBoolean('enable.saml20-idp', false) || !Module::isModuleEnabled('saml')) {
throw new Error\Error('NOACCESS', null, 403);
}
$metadata = Metadata\MetaDataStorageHandler::getMetadataHandler(); $metadata = Metadata\MetaDataStorageHandler::getMetadataHandler();
$idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
$idp = IdP::getById('saml2:' . $idpEntityId); $idp = IdP::getById('saml2:' . $idpEntityId);
Logger::info('SAML2.0 - IdP.initSLO: Accessing SAML 2.0 IdP endpoint init Single Logout');
if (!isset($_GET['RelayState'])) { if (!isset($_GET['RelayState'])) {
throw new Error\Error('NORELAYSTATE'); throw new Error\Error('NORELAYSTATE');
} }
......
...@@ -6,18 +6,17 @@ use Symfony\Component\VarExporter\VarExporter; ...@@ -6,18 +6,17 @@ use Symfony\Component\VarExporter\VarExporter;
use SAML2\Constants; use SAML2\Constants;
use SimpleSAML\Assert\Assert; use SimpleSAML\Assert\Assert;
use SimpleSAML\Configuration;
use SimpleSAML\Error;
use SimpleSAML\Module; use SimpleSAML\Module;
use SimpleSAML\Utils\Auth as Auth; use SimpleSAML\Utils\Auth as Auth;
use SimpleSAML\Utils\Crypto as Crypto; use SimpleSAML\Utils\Crypto as Crypto;
use SimpleSAML\Utils\HTTP as HTTP; use SimpleSAML\Utils\HTTP as HTTP;
use SimpleSAML\Utils\Config\Metadata as Metadata; use SimpleSAML\Utils\Config\Metadata as Metadata;
// load SimpleSAMLphp configuration and metadata $config = Configuration::getInstance();
$config = \SimpleSAML\Configuration::getInstance(); if (!$config->getBoolean('enable.saml20-idp', false) || !Module::isModuleEnabled('saml')) {
$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler(); throw new Error\Error('NOACCESS', null, 403);
if (!$config->getBoolean('enable.saml20-idp', false)) {
throw new \SimpleSAML\Error\Error('NOACCESS');
} }
// check if valid local session exists // check if valid local session exists
...@@ -25,6 +24,8 @@ if ($config->getBoolean('admin.protectmetadata', false)) { ...@@ -25,6 +24,8 @@ if ($config->getBoolean('admin.protectmetadata', false)) {
Auth::requireAdmin(); Auth::requireAdmin();
} }
$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
try { try {
$idpentityid = isset($_GET['idpentityid']) ? $idpentityid = isset($_GET['idpentityid']) ?
$_GET['idpentityid'] : $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); $_GET['idpentityid'] : $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
...@@ -151,7 +152,7 @@ try { ...@@ -151,7 +152,7 @@ try {
); );
if (!$idpmeta->hasValue('OrganizationURL')) { if (!$idpmeta->hasValue('OrganizationURL')) {
throw new \SimpleSAML\Error\Exception( throw new Error\Exception(
'If OrganizationName is set, OrganizationURL must also be set.' 'If OrganizationName is set, OrganizationURL must also be set.'
); );
} }
...@@ -246,5 +247,5 @@ try { ...@@ -246,5 +247,5 @@ try {
exit(0); exit(0);
} }
} catch (\Exception $exception) { } catch (\Exception $exception) {
throw new \SimpleSAML\Error\Error('METADATA', $exception); throw new Error\Error('METADATA', $exception);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment