Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change getString to getOptionalString where a default is provided #245

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions modules/silauth/src/Auth/Source/system/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use SimpleSAML\Module\silauth\Auth\Source\auth\IdBroker;
use SimpleSAML\Module\silauth\Auth\Source\config\ConfigManager;
use SimpleSAML\Configuration;
use SimpleSAML\Module\silauth\Auth\Source\models\FailedLoginIpAddress;
use \SimpleSAML\Configuration;
use Throwable;

class System
Expand Down Expand Up @@ -46,7 +44,7 @@ protected function isRequiredConfigPresent(): bool
* HTTP_HOST value (provided by the user's request) is used to
* build a trusted URL (see SimpleSaml\Module::authenticate()).
*/
$baseURL = $globalConfig->getString('baseurlpath', '');
$baseURL = $globalConfig->getOptionalString('baseurlpath', '');
$avoidsSecurityHole = (preg_match('#^https?://.*/$#D', $baseURL) === 1);
if (!$avoidsSecurityHole) {
$this->logError('isRequiredConfigPresent failed: baseurlpath (' . $baseURL . ') does not meet requirements');
Expand Down
19 changes: 9 additions & 10 deletions modules/sildisco/public/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
require_once('../public/_include.php');

use SAML2\Constants;
use SimpleSAML\Utils\Auth as Auth;
use SimpleSAML\Utils\Config\Metadata as Metadata;
use SimpleSAML\Utils\Crypto as Crypto;
use SimpleSAML\Utils\HTTP as HTTP;
use SimpleSAML\Utils\Config\Metadata as Metadata;

// load SimpleSAMLphp, configuration and metadata
$config = \SimpleSAML\Configuration::getInstance();
$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();

if (!$config->getBoolean('enable.saml20-idp', false)) {
if (!$config->getOptionalBoolean('enable.saml20-idp', false)) {
throw new \SimpleSAML\Error\Error('NOACCESS');
}

// check if valid local session exists
//$authUtils = new Auth();
//if ($config->getBoolean('admin.protectmetadata', false)) {
//if ($config->getOptionalBoolean('admin.protectmetadata', false)) {
// $authUtils->requireAdmin();
//}

Expand Down Expand Up @@ -117,7 +116,7 @@

$httpUtils = new HTTP();

if ($idpmeta->getBoolean('saml20.sendartifact', false)) {
if ($idpmeta->getOptionalBoolean('saml20.sendartifact', false)) {
// Artifact sending enabled
$metaArray['ArtifactResolutionService'][] = array(
'index' => 0,
Expand All @@ -126,7 +125,7 @@
);
}

if ($idpmeta->getBoolean('saml20.hok.assertion', false)) {
if ($idpmeta->getOptionalBoolean('saml20.hok.assertion', false)) {
// Prepend HoK SSO Service endpoint.
array_unshift($metaArray['SingleSignOnService'], array(
'hoksso:ProtocolBinding' => Constants::BINDING_HTTP_REDIRECT,
Expand All @@ -135,7 +134,7 @@
));
}

$metaArray['NameIDFormat'] = $idpmeta->getString(
$metaArray['NameIDFormat'] = $idpmeta->getOptionalString(
'NameIDFormat',
'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'
);
Expand Down Expand Up @@ -193,10 +192,10 @@
}
}

$technicalContactEmail = $config->getString('technicalcontact_email', false);
if ($technicalContactEmail && $technicalContactEmail !== '[email protected]') {
$technicalContactEmail = $config->getOptionalString('technicalcontact_email', null);
if (!empty($technicalContactEmail) && $technicalContactEmail !== '[email protected]') {
$techcontact['emailAddress'] = $technicalContactEmail;
$techcontact['name'] = $config->getString('technicalcontact_name', null);
$techcontact['name'] = $config->getOptionalString('technicalcontact_name', null);
$techcontact['contactType'] = 'technical';
$metaArray['contacts'][] = Metadata::getContact($techcontact);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/sildisco/src/IdPDisco.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function handleRequest(): void
$t->data['spName'] = $spName;
$t->data['urlpattern'] = htmlspecialchars($httpUtils->getSelfURLNoQuery());
$t->data['announcement'] = AnnouncementUtils::getAnnouncement();
$t->data['helpCenterUrl'] = $this->config->getValue('helpCenterUrl', '');
$t->data['helpCenterUrl'] = $this->config->getOptionalString('helpCenterUrl', '');

$t->show();
}
Expand Down Expand Up @@ -181,7 +181,7 @@ protected function validateIdP(?string $idp): ?string
if ($idp === null) {
return null;
}
if (!$this->config->getBoolean('idpdisco.validate', true)) {
if (!$this->config->getOptionalBoolean('idpdisco.validate', true)) {
return $idp;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/sildisco/src/SSOService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

try {
// If in hub mode, then use the sildisco entry script
if ($config->getValue($hubModeKey, false)) {
if ($config->getOptionalBoolean($hubModeKey, false)) {
\SimpleSAML\Module\sildisco\IdP\SAML2::receiveAuthnRequest($idp);
} else {
\SimpleSAML\Module\saml\IdP\SAML2::receiveAuthnRequest($idp);
Expand Down