111 assert(is_bool($required));
113 if (array_key_exists(
$filename, self::$loadedConfigs)) {
122 if (interface_exists(
'Throwable',
false)) {
125 }
catch (ParseError $e) {
126 self::$loadedConfigs[
$filename] = self::loadFromArray(array(),
'[ARRAY]',
'simplesaml');
133 $spurious_output = ob_get_length() > 0;
138 throw new \SimpleSAML\Error\ConfigurationError(
139 '$config is not defined in the configuration file.',
146 throw new \SimpleSAML\Error\ConfigurationError(
147 '$config is not an array.',
154 throw new \SimpleSAML\Error\ConfigurationError(
159 } elseif ($required) {
161 throw new \SimpleSAML\Error\ConfigurationError(
'Missing configuration file',
$filename);
174 if ($spurious_output) {
176 "The configuration file '$filename' generates output. Please review your configuration." 192 assert(is_string(
$path));
193 assert(is_string($configSet));
195 self::$configDirs[$configSet] =
$path;
211 assert(is_string($configSet));
213 if (!array_key_exists($configSet, self::$configDirs)) {
214 if ($configSet !==
'simplesaml') {
215 throw new Exception(
'Configuration set \'' . $configSet .
'\' not initialized.
'); 217 self::$configDirs['simplesaml
'] = dirname(dirname(dirname(__FILE__))) . '/config
'; 221 $dir = self::$configDirs[$configSet]; 222 $filePath = $dir . '/
' . $filename; 224 self::$loadedConfigs[$filePath] = $config; 237 public static function getConfig($filename = 'config.php
', $configSet = 'simplesaml
') 239 assert(is_string($filename)); 240 assert(is_string($configSet)); 242 if (!array_key_exists($configSet, self::$configDirs)) { 243 if ($configSet !== 'simplesaml
') { 244 throw new Exception('Configuration set \
''.$configSet.
'\' not initialized.
'); 246 self::$configDirs['simplesaml
'] = SimpleSAML\Utils\Config::getConfigDir(); 250 $dir = self::$configDirs[$configSet]; 251 $filePath = $dir.'/
'.$filename; 252 return self::loadFromFile($filePath, true); 267 public static function getOptionalConfig($filename = 'config.php
', $configSet = 'simplesaml
') 269 assert(is_string($filename)); 270 assert(is_string($configSet)); 272 if (!array_key_exists($configSet, self::$configDirs)) { 273 if ($configSet !== 'simplesaml
') { 274 throw new Exception('Configuration set \
''.$configSet.
'\' not initialized.
'); 276 self::$configDirs['simplesaml
'] = SimpleSAML\Utils\Config::getConfigDir(); 280 $dir = self::$configDirs[$configSet]; 281 $filePath = $dir.'/
'.$filename; 282 return self::loadFromFile($filePath, false); 297 public static function loadFromArray($config, $location = '[ARRAY]
', $instance = null) 299 assert(is_array($config)); 300 assert(is_string($location)); 302 $c = new SimpleSAML_Configuration($config, $location); 303 if ($instance !== null) { 304 self::$instance[$instance] = $c; 325 public static function getInstance($instancename = 'simplesaml
') 327 assert(is_string($instancename)); 329 // check if the instance exists already 330 if (array_key_exists($instancename, self::$instance)) { 331 return self::$instance[$instancename]; 334 if ($instancename === 'simplesaml
') { 336 return self::getConfig(); 337 } catch (SimpleSAML\Error\ConfigurationError $e) { 338 throw \SimpleSAML\Error\CriticalConfigurationError::fromException($e); 342 throw new \SimpleSAML\Error\CriticalConfigurationError( 360 public static function init($path, $instancename = 'simplesaml
', $configfilename = 'config.php
') 362 assert(is_string($path)); 363 assert(is_string($instancename)); 364 assert(is_string($configfilename)); 366 if ($instancename === 'simplesaml
') { 367 // for backwards compatibility 368 self::setConfigDir($path, 'simplesaml
'); 371 // check if we already have loaded the given config - return the existing instance if we have 372 if (array_key_exists($instancename, self::$instance)) { 373 return self::$instance[$instancename]; 376 self::$instance[$instancename] = self::loadFromFile($path.'/
'.$configfilename, true); 377 return self::$instance[$instancename]; 392 public function copyFromBase($instancename, $filename) 394 assert(is_string($instancename)); 395 assert(is_string($filename)); 396 assert($this->filename !== null); 398 // check if we already have loaded the given config - return the existing instance if we have 399 if (array_key_exists($instancename, self::$instance)) { 400 return self::$instance[$instancename]; 403 $dir = dirname($this->filename); 405 self::$instance[$instancename] = self::loadFromFile($dir.'/
'.$filename, true); 406 return self::$instance[$instancename]; 415 public function getVersion() 433 public function getValue($name, $default = null) 435 // return the default value if the option is unset 436 if (!array_key_exists($name, $this->configuration)) { 437 if ($default === self::REQUIRED_OPTION) { 439 $this->location.': Could not retrieve
the required option
'. 440 var_export($name, true) 446 return $this->configuration[$name]; 457 public function hasValue($name) 459 return array_key_exists($name, $this->configuration); 470 public function hasValueOneOf($names) 472 foreach ($names as $name) { 473 if ($this->hasValue($name)) { 494 public function getBaseURL() 496 if (!$this->deprecated_base_url_used) { 497 $this->deprecated_base_url_used = true; 498 SimpleSAML\Logger::warning( 499 "SimpleSAML_Configuration::getBaseURL() is deprecated, please use getBasePath() instead." 502 if (preg_match('/^\*(.*)$/
D', $this->getString('baseurlpath
', 'simplesaml/
'), $matches)) { 503 // deprecated behaviour, will be removed in the future 504 return \SimpleSAML\Utils\HTTP::getFirstPathElement(false).$matches[1]; 506 return ltrim($this->getBasePath(), '/
'); 519 public function getBasePath() 521 $baseURL = $this->getString('baseurlpath
', 'simplesaml/
'); 523 if (preg_match('#^
https?:
525 if (!array_key_exists(1, $matches)) {
529 return '/'.rtrim($matches[1],
'/').
"/";
530 } elseif ($baseURL ===
'' || $baseURL ===
'/') {
533 } elseif (preg_match(
'#^/?((?:[^/\s]+/?)+)#', $baseURL, $matches)) {
535 return '/'.rtrim($matches[1],
'/').
'/';
544 'Incorrect format for option \'baseurlpath\'. Value is: "'.
545 $this->
getString(
'baseurlpath',
'simplesaml/').
'". Valid format is in the form'.
546 ' [(http|https)://(hostname|fqdn)[:port]]/[path/to/simplesaml/].',
566 if (
$path === null) {
570 assert(is_string(
$path));
593 if (!array_key_exists(
$name, $this->configuration)) {
599 if (
$path === null) {
619 $dir = $this->
getString(
'basedir', null);
622 if (substr($dir, -1) !== DIRECTORY_SEPARATOR) {
623 $dir .= DIRECTORY_SEPARATOR;
631 assert(basename($dir) ===
'Configuration.php');
633 $dir = dirname($dir);
634 assert(basename($dir) ===
'SimpleSAML');
636 $dir = dirname($dir);
637 assert(basename($dir) ===
'lib');
639 $dir = dirname($dir);
642 $dir .= DIRECTORY_SEPARATOR;
666 assert(is_string(
$name));
675 if (!is_bool(
$ret)) {
677 $this->location.
': The option '.var_export(
$name,
true).
678 ' is not a valid boolean value.' 704 assert(is_string(
$name));
713 if (!is_string(
$ret)) {
715 $this->location.
': The option '.var_export(
$name,
true).
716 ' is not a valid string value.' 742 assert(is_string(
$name));
753 $this->location.
': The option '.var_export(
$name,
true).
754 ' is not a valid integer value.' 784 assert(is_string(
$name));
785 assert(is_int($minimum));
786 assert(is_int($maximum));
795 if ($ret < $minimum || $ret > $maximum) {
797 $this->location.
': Value of option '.var_export(
$name,
true).
798 ' is out of range. Value is '.
$ret.
', allowed range is [' 799 .$minimum.
' - '.$maximum.
']' 830 assert(is_string(
$name));
831 assert(is_array($allowedValues));
839 if (!in_array(
$ret, $allowedValues,
true)) {
840 $strValues = array();
841 foreach ($allowedValues as $av) {
842 $strValues[] = var_export($av,
true);
844 $strValues = implode(
', ', $strValues);
847 $this->location.
': Invalid value given for the option '.
848 var_export(
$name,
true).
'. It should have one of the following values: '.
849 $strValues.
'; but it had the following value: '.var_export(
$ret,
true)
875 assert(is_string(
$name));
884 if (!is_array(
$ret)) {
885 throw new Exception($this->location.
': The option '.var_export(
$name,
true).
' is not an array.');
906 assert(is_string(
$name));
915 if (!is_array(
$ret)) {
939 assert(is_string(
$name));
948 foreach (
$ret as $value) {
949 if (!is_string($value)) {
951 $this->location.
': The option '.var_export(
$name,
true).
952 ' must be a string or an array of strings.' 981 assert(is_string(
$name));
990 if (!is_array(
$ret)) {
992 $this->location.
': The option '.var_export(
$name,
true).
997 return self::loadFromArray(
$ret, $this->location.
'['.var_export(
$name,
true).
']');
1022 assert(is_string(
$name));
1031 if (!is_array(
$ret)) {
1033 $this->location.
': The option '.var_export(
$name,
true).
1040 $newLoc = $this->location.
'['.var_export(
$name,
true).
']['.
1041 var_export(
$index,
true).
']';
1042 if (!is_array($config)) {
1043 throw new Exception($newLoc.
': The value of this element was expected to be an array.');
1045 $out[
$index] = self::loadFromArray($config, $newLoc);
1062 return array_keys($this->configuration);
1091 assert(is_string($endpointType));
1093 $set = $this->
getString(
'metadata-set');
1094 switch ($set.
':'.$endpointType) {
1095 case 'saml20-idp-remote:SingleSignOnService':
1096 case 'saml20-idp-remote:SingleLogoutService':
1097 case 'saml20-sp-remote:SingleLogoutService':
1098 return \SAML2\Constants::BINDING_HTTP_REDIRECT;
1099 case 'saml20-sp-remote:AssertionConsumerService':
1100 return \SAML2\Constants::BINDING_HTTP_POST;
1101 case 'saml20-idp-remote:ArtifactResolutionService':
1102 return \SAML2\Constants::BINDING_SOAP;
1103 case 'shib13-idp-remote:SingleSignOnService':
1104 return 'urn:mace:shibboleth:1.0:profiles:AuthnRequest';
1105 case 'shib13-sp-remote:AssertionConsumerService':
1106 return 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post';
1108 throw new Exception(
'Missing default binding for '.$endpointType.
' in '.$set);
1124 assert(is_string($endpointType));
1126 $loc = $this->location.
'['.var_export($endpointType,
true).
']:';
1128 if (!array_key_exists($endpointType, $this->configuration)) {
1134 $eps = $this->configuration[$endpointType];
1135 if (is_string(
$eps)) {
1138 } elseif (!is_array(
$eps)) {
1139 throw new Exception($loc.
': Expected array or string.');
1143 foreach (
$eps as
$i => &$ep) {
1144 $iloc = $loc.
'['.var_export(
$i,
true).
']';
1146 if (is_string($ep)) {
1152 $responseLocation = $this->
getString($endpointType.
'Response', null);
1153 if ($responseLocation !== null) {
1154 $ep[
'ResponseLocation'] = $responseLocation;
1156 } elseif (!is_array($ep)) {
1157 throw new Exception($iloc.
': Expected a string or an array.');
1160 if (!array_key_exists(
'Location', $ep)) {
1161 throw new Exception($iloc.
': Missing Location.');
1163 if (!is_string($ep[
'Location'])) {
1164 throw new Exception($iloc.
': Location must be a string.');
1167 if (!array_key_exists(
'Binding', $ep)) {
1168 throw new Exception($iloc.
': Missing Binding.');
1170 if (!is_string($ep[
'Binding'])) {
1171 throw new Exception($iloc.
': Binding must be a string.');
1174 if (array_key_exists(
'ResponseLocation', $ep)) {
1175 if (!is_string($ep[
'ResponseLocation'])) {
1176 throw new Exception($iloc.
': ResponseLocation must be a string.');
1180 if (array_key_exists(
'index', $ep)) {
1181 if (!is_int($ep[
'index'])) {
1182 throw new Exception($iloc.
': index must be an integer.');
1205 assert(is_string($endpointType));
1210 foreach ($endpoints as $ep) {
1211 if ($ep[
'Binding'] === $binding) {
1217 if (
$default === self::REQUIRED_OPTION) {
1218 $loc = $this->location.
'['.var_export($endpointType,
true).
']:';
1219 throw new Exception($loc.
'Could not find a supported '.$endpointType.
' endpoint.');
1240 assert(is_string($endpointType));
1244 $defaultEndpoint = \SimpleSAML\Utils\Config\Metadata::getDefaultEndpoint($endpoints,
$bindings);
1245 if ($defaultEndpoint !== null) {
1246 return $defaultEndpoint;
1249 if (
$default === self::REQUIRED_OPTION) {
1250 $loc = $this->location.
'['.var_export($endpointType,
true).
']:';
1251 throw new Exception($loc.
'Could not find a supported '.$endpointType.
' endpoint.');
1273 assert(is_string(
$name));
1281 $loc = $this->location.
'['.var_export(
$name,
true).
']';
1283 if (is_string(
$ret)) {
1287 if (!is_array(
$ret)) {
1288 throw new Exception($loc.
': Must be an array or a string.');
1291 foreach (
$ret as $k => $v) {
1292 if (!is_string($k)) {
1293 throw new Exception($loc.
': Invalid language code: '.var_export($k,
true));
1295 if (!is_string($v)) {
1296 throw new Exception($loc.
'['.var_export($v,
true).
']: Must be a string.');
1321 assert(is_bool($required));
1322 assert(is_string($prefix));
1324 if ($this->
hasValue($prefix.
'keys')) {
1327 if ($use !== null && isset($key[$use]) && !$key[$use]) {
1330 if (isset($key[
'X509Certificate'])) {
1332 $key[
'X509Certificate'] = preg_replace(
'/\s+/',
'', $key[
'X509Certificate']);
1337 } elseif ($this->
hasValue($prefix.
'certData')) {
1338 $certData = $this->
getString($prefix.
'certData');
1339 $certData = preg_replace(
'/\s+/',
'', $certData);
1342 'encryption' =>
true,
1344 'type' =>
'X509Certificate',
1345 'X509Certificate' => $certData,
1348 } elseif ($this->
hasValue($prefix.
'certificate')) {
1349 $file = $this->
getString($prefix.
'certificate');
1351 $data = @file_get_contents($file);
1353 if (
$data ===
false) {
1354 throw new Exception($this->location.
': Unable to load certificate/public key from file "'.$file.
'".');
1358 $pattern =
'/^-----BEGIN CERTIFICATE-----([^-]*)^-----END CERTIFICATE-----/m';
1359 if (!preg_match($pattern,
$data, $matches)) {
1361 $this->location.
': Could not find PEM encoded certificate in "'.$file.
'".' 1364 $certData = preg_replace(
'/\s+/',
'', $matches[1]);
1368 'encryption' =>
true,
1370 'type' =>
'X509Certificate',
1371 'X509Certificate' => $certData,
1374 } elseif ($required ===
true) {
1388 self::$configDirs = array();
1389 self::$instance = array();
1390 self::$loadedConfigs = array();
getEndpoints($endpointType)
Helper function for dealing with metadata endpoints.
getBaseDir()
Retrieve the base directory for this SimpleSAMLphp installation.
resolvePath($path)
This function resolves a path which may be relative to the SimpleSAMLphp base directory.
getConfigList($name, $default=self::REQUIRED_OPTION)
Retrieve an array of arrays as an array of SimpleSAML_Configuration objects.
getPathValue($name, $default=null)
Retrieve a path configuration option set in config.php.
getArray($name, $default=self::REQUIRED_OPTION)
This function retrieves an array configuration option.
static loadFromFile($filename, $required)
Load the given configuration file.
hasValue($name)
Check whether a key in the configuration exists or not.
$deprecated_base_url_used
getDefaultBinding($endpointType)
Retrieve the default binding for the given endpoint type.
static setPreLoadedConfig(SimpleSAML_Configuration $config, $filename='config.php', $configSet='simplesaml')
Store a pre-initialized configuration.
toArray()
Convert this configuration object back to an array.
getValue($name, $default=null)
Retrieve a configuration option set in config.php.
getValueValidate($name, $allowedValues, $default=self::REQUIRED_OPTION)
Retrieve a configuration option with one of the given values.
getIntegerRange($name, $minimum, $maximum, $default=self::REQUIRED_OPTION)
This function retrieves an integer configuration option where the value must be in the specified rang...
static setConfigDir($path, $configSet='simplesaml')
Set the directory for configuration files for the given configuration set.
__construct($config, $location)
Initializes a configuration from the given array.
getEndpointPrioritizedByBinding($endpointType, array $bindings, $default=self::REQUIRED_OPTION)
Find an endpoint of the given type, using a list of supported bindings as a way to prioritize...
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
getDefaultEndpoint($endpointType, array $bindings=null, $default=self::REQUIRED_OPTION)
Find the default endpoint of the given type.
getArrayize($name, $default=self::REQUIRED_OPTION)
This function retrieves an array configuration option.
getOptions()
Retrieve list of options.
catch(Exception $e) if(isset($_POST['cancel'])) if(isset($_POST['continue'])) $cfg
getLocalizedString($name, $default=self::REQUIRED_OPTION)
Retrieve a string which may be localized into many languages.
getBoolean($name, $default=self::REQUIRED_OPTION)
This function retrieves a boolean configuration option.
getArrayizeString($name, $default=self::REQUIRED_OPTION)
This function retrieves a configuration option with a string or an array of strings.
getInteger($name, $default=self::REQUIRED_OPTION)
This function retrieves an integer configuration option.
getPublicKeys($use=null, $required=false, $prefix='')
Get public key from metadata.
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
static getCertPath($path)
Resolves a path that may be relative to the cert-directory.
static guessBasePath()
Try to guess the base SimpleSAMLphp path from the current request.
static clearInternalState()
Clear any configuration information cached.
getConfigItem($name, $default=self::REQUIRED_OPTION)
Retrieve an array as a SimpleSAML_Configuration object.