Skip to content

Commit

Permalink
Prevented saml2 autodiscovery on metadata load
Browse files Browse the repository at this point in the history
Fixes issue where metadata cannot be viewed if autload is active and
entityid url is not active.
For #2480
  • Loading branch information
ssddanbrown committed Oct 16, 2022
1 parent 0269f51 commit f0ac454
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
19 changes: 8 additions & 11 deletions app/Auth/Access/Saml2Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
*/
class Saml2Service
{
protected $config;
protected $registrationService;
protected $loginService;
protected $groupSyncService;
protected array $config;
protected RegistrationService $registrationService;
protected LoginService $loginService;
protected GroupSyncService $groupSyncService;

/**
* Saml2Service constructor.
*/
public function __construct(
RegistrationService $registrationService,
LoginService $loginService,
Expand Down Expand Up @@ -169,7 +166,7 @@ protected function actionLogout()
*/
public function metadata(): string
{
$toolKit = $this->getToolkit();
$toolKit = $this->getToolkit(true);
$settings = $toolKit->getSettings();
$metadata = $settings->getSPMetadata();
$errors = $settings->validateMetadata($metadata);
Expand All @@ -190,7 +187,7 @@ public function metadata(): string
* @throws Error
* @throws Exception
*/
protected function getToolkit(): Auth
protected function getToolkit(bool $spOnly = false): Auth
{
$settings = $this->config['onelogin'];
$overrides = $this->config['onelogin_overrides'] ?? [];
Expand All @@ -200,14 +197,14 @@ protected function getToolkit(): Auth
}

$metaDataSettings = [];
if ($this->config['autoload_from_metadata']) {
if (!$spOnly && $this->config['autoload_from_metadata']) {
$metaDataSettings = IdPMetadataParser::parseRemoteXML($settings['idp']['entityId']);
}

$spSettings = $this->loadOneloginServiceProviderDetails();
$settings = array_replace_recursive($settings, $spSettings, $metaDataSettings, $overrides);

return new Auth($settings);
return new Auth($settings, $spOnly);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/Auth/Saml2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ public function test_metadata_endpoint_displays_xml_as_expected()
$req->assertSee(url('/saml2/acs'));
}

public function test_metadata_endpoint_loads_when_autoloading_with_bad_url_set()
{
config()->set([
'saml2.autoload_from_metadata' => true,
'saml2.onelogin.idp.entityId' => 'http://192.168.1.1:9292',
'saml2.onelogin.idp.singleSignOnService.url' => null,
]);

$req = $this->get('/saml2/metadata');
$req->assertOk();
$req->assertHeader('Content-Type', 'text/xml; charset=UTF-8');
$req->assertSee('md:EntityDescriptor');
}

public function test_onelogin_overrides_functions_as_expected()
{
$json = '{"sp": {"assertionConsumerService": {"url": "https://example.com/super-cats"}}, "contactPerson": {"technical": {"givenName": "Barry Scott", "emailAddress": "barry@example.com"}}}';
Expand Down

0 comments on commit f0ac454

Please sign in to comment.