90 assert(
'is_array($config)');
91 assert(
'is_string($location)');
111 assert(
'is_string($filename)');
112 assert(
'is_bool($required)');
114 if (array_key_exists(
$filename, self::$loadedConfigs)) {
123 if (interface_exists(
'Throwable')) {
126 }
catch (ParseError $e) {
127 self::$loadedConfigs[
$filename] = self::loadFromArray(
array(),
'[ARRAY]',
'simplesaml');
134 $spurious_output = ob_get_length() > 0;
139 throw new \SimpleSAML\Error\ConfigurationError(
140 '$config is not defined in the configuration file.',
147 throw new \SimpleSAML\Error\ConfigurationError(
148 '$config is not an array.',
155 throw new \SimpleSAML\Error\ConfigurationError(
160 } elseif ($required) {
162 throw new \SimpleSAML\Error\ConfigurationError(
'Missing configuration file',
$filename);
175 if ($spurious_output) {
177 "The configuration file '$filename' generates output. Please review your configuration." 193 assert(
'is_string($path)');
194 assert(
'is_string($configSet)');
196 self::$configDirs[$configSet] =
$path;
211 assert(
'is_string($filename)');
212 assert(
'is_string($configSet)');
214 if (!array_key_exists($configSet, self::$configDirs)) {
215 if ($configSet !==
'simplesaml') {
216 throw new Exception(
'Configuration set \''.$configSet.
'\' not initialized.
'); 218 self::$configDirs['simplesaml
'] = SimpleSAML\Utils\Config::getConfigDir(); 222 $dir = self::$configDirs[$configSet]; 223 $filePath = $dir.'/
'.$filename; 224 return self::loadFromFile($filePath, true); 239 public static function getOptionalConfig($filename = 'config.php
', $configSet = 'simplesaml
') 242 assert('is_string($configSet)
'); 244 if (!array_key_exists($configSet, self::$configDirs)) { 245 if ($configSet !== 'simplesaml
') { 246 throw new Exception('Configuration set \
''.$configSet.
'\' not initialized.
'); 248 self::$configDirs['simplesaml
'] = SimpleSAML\Utils\Config::getConfigDir(); 252 $dir = self::$configDirs[$configSet]; 253 $filePath = $dir.'/
'.$filename; 254 return self::loadFromFile($filePath, false); 269 public static function loadFromArray($config, $location = '[ARRAY]
', $instance = null) 274 $c = new SimpleSAML_Configuration($config, $location); 275 if ($instance !== null) { 276 self::$instance[$instance] = $c; 297 public static function getInstance($instancename = 'simplesaml
') 299 assert('is_string($instancename)
'); 301 // check if the instance exists already 302 if (array_key_exists($instancename, self::$instance)) { 303 return self::$instance[$instancename]; 306 if ($instancename === 'simplesaml
') { 308 return self::getConfig(); 309 } catch (SimpleSAML\Error\ConfigurationError $e) { 310 throw \SimpleSAML\Error\CriticalConfigurationError::fromException($e); 314 throw new \SimpleSAML\Error\CriticalConfigurationError( 332 public static function init($path, $instancename = 'simplesaml
', $configfilename = 'config.php
') 334 assert('is_string(
$path)
'); 335 assert('is_string($instancename)
'); 336 assert('is_string($configfilename)
'); 338 if ($instancename === 'simplesaml
') { 339 // for backwards compatibility 340 self::setConfigDir($path, 'simplesaml
'); 343 // check if we already have loaded the given config - return the existing instance if we have 344 if (array_key_exists($instancename, self::$instance)) { 345 return self::$instance[$instancename]; 348 self::$instance[$instancename] = self::loadFromFile($path.'/
'.$configfilename, true); 349 return self::$instance[$instancename]; 364 public function copyFromBase($instancename, $filename) 366 assert('is_string($instancename)
'); 368 assert('$this->filename !== NULL
'); 370 // check if we already have loaded the given config - return the existing instance if we have 371 if (array_key_exists($instancename, self::$instance)) { 372 return self::$instance[$instancename]; 375 $dir = dirname($this->filename); 377 self::$instance[$instancename] = self::loadFromFile($dir.'/
'.$filename, true); 378 return self::$instance[$instancename]; 387 public function getVersion() 405 public function getValue($name, $default = null) 407 // return the default value if the option is unset 408 if (!array_key_exists($name, $this->configuration)) { 409 if ($default === self::REQUIRED_OPTION) { 411 $this->location.': Could not retrieve the required option
'. 412 var_export($name, true) 418 return $this->configuration[$name]; 429 public function hasValue($name) 431 return array_key_exists($name, $this->configuration); 442 public function hasValueOneOf($names) 444 foreach ($names as $name) { 445 if ($this->hasValue($name)) { 466 public function getBaseURL() 468 if (!$this->deprecated_base_url_used) { 469 $this->deprecated_base_url_used = true; 470 SimpleSAML\Logger::warning( 471 "SimpleSAML_Configuration::getBaseURL() is deprecated, please use getBasePath() instead." 474 if (preg_match('/^\*(.*)$/
D', $this->getString('baseurlpath
', 'simplesaml/
'), $matches)) { 475 // deprecated behaviour, will be removed in the future 476 return \SimpleSAML\Utils\HTTP::getFirstPathElement(false).$matches[1]; 478 return ltrim($this->getBasePath(), '/
'); 491 public function getBasePath() 493 $baseURL = $this->getString('baseurlpath
', 'simplesaml/
'); 495 if (preg_match('#^
https?:
497 if (!array_key_exists(1, $matches)) {
501 return '/'.rtrim($matches[1],
'/').
"/";
502 } elseif ($baseURL ===
'' || $baseURL ===
'/') {
505 } elseif (preg_match(
'#^/?((?:[^/\s]+/?)+)#', $baseURL, $matches)) {
507 return '/'.rtrim($matches[1],
'/').
'/';
516 'Incorrect format for option \'baseurlpath\'. Value is: "'.
517 $this->
getString(
'baseurlpath',
'simplesaml/').
'". Valid format is in the form'.
518 ' [(http|https)://(hostname|fqdn)[:port]]/[path/to/simplesaml/].',
538 if (
$path === null) {
542 assert(
'is_string($path)');
547 if (
$path[0] !==
'/' &&
548 !(preg_match(
'@^[a-z]:[\\\\/]@i',
$path, $matches) && is_dir($matches[0]))
577 if (!array_key_exists(
$name, $this->configuration)) {
583 if (
$path === null) {
603 $dir = $this->
getString(
'basedir', null);
606 if (substr($dir, -1) !== DIRECTORY_SEPARATOR) {
607 $dir .= DIRECTORY_SEPARATOR;
615 assert(
'basename($dir) === "Configuration.php"');
617 $dir = dirname($dir);
618 assert(
'basename($dir) === "SimpleSAML"');
620 $dir = dirname($dir);
621 assert(
'basename($dir) === "lib"');
623 $dir = dirname($dir);
626 $dir .= DIRECTORY_SEPARATOR;
650 assert(
'is_string($name)');
654 if (
$ret === $default) {
659 if (!is_bool(
$ret)) {
661 $this->location.
': The option '.var_export(
$name,
true).
662 ' is not a valid boolean value.' 688 assert(
'is_string($name)');
692 if (
$ret === $default) {
697 if (!is_string(
$ret)) {
699 $this->location.
': The option '.var_export(
$name,
true).
700 ' is not a valid string value.' 726 assert(
'is_string($name)');
730 if (
$ret === $default) {
737 $this->location.
': The option '.var_export(
$name,
true).
738 ' is not a valid integer value.' 768 assert(
'is_string($name)');
769 assert(
'is_int($minimum)');
770 assert(
'is_int($maximum)');
774 if (
$ret === $default) {
779 if ($ret < $minimum || $ret > $maximum) {
781 $this->location.
': Value of option '.var_export(
$name,
true).
782 ' is out of range. Value is '.
$ret.
', allowed range is [' 783 .$minimum.
' - '.$maximum.
']' 814 assert(
'is_string($name)');
815 assert(
'is_array($allowedValues)');
818 if (
$ret === $default) {
823 if (!in_array(
$ret, $allowedValues,
true)) {
824 $strValues =
array();
825 foreach ($allowedValues as $av) {
826 $strValues[] = var_export($av,
true);
828 $strValues = implode(
', ', $strValues);
831 $this->location.
': Invalid value given for the option '.
832 var_export(
$name,
true).
'. It should have one of the following values: '.
833 $strValues.
'; but it had the following value: '.var_export(
$ret,
true)
859 assert(
'is_string($name)');
863 if (
$ret === $default) {
868 if (!is_array(
$ret)) {
869 throw new Exception($this->location.
': The option '.var_export(
$name,
true).
' is not an array.');
890 assert(
'is_string($name)');
894 if (
$ret === $default) {
899 if (!is_array(
$ret)) {
923 assert(
'is_string($name)');
927 if (
$ret === $default) {
932 foreach (
$ret as $value) {
933 if (!is_string($value)) {
935 $this->location.
': The option '.var_export(
$name,
true).
936 ' must be a string or an array of strings.' 965 assert(
'is_string($name)');
969 if (
$ret === $default) {
974 if (!is_array(
$ret)) {
976 $this->location.
': The option '.var_export(
$name,
true).
981 return self::loadFromArray(
$ret, $this->location.
'['.var_export(
$name,
true).
']');
1006 assert(
'is_string($name)');
1010 if (
$ret === $default) {
1015 if (!is_array(
$ret)) {
1017 $this->location.
': The option '.var_export(
$name,
true).
1024 $newLoc = $this->location.
'['.var_export(
$name,
true).
']['.
1025 var_export(
$index,
true).
']';
1027 throw new Exception($newLoc.
': The value of this element was expected to be an array.');
1046 return array_keys($this->configuration);
1075 assert(
'is_string($endpointType)');
1077 $set = $this->
getString(
'metadata-set');
1078 switch ($set.
':'.$endpointType) {
1079 case 'saml20-idp-remote:SingleSignOnService':
1080 case 'saml20-idp-remote:SingleLogoutService':
1081 case 'saml20-sp-remote:SingleLogoutService':
1082 return \SAML2\Constants::BINDING_HTTP_REDIRECT;
1083 case 'saml20-sp-remote:AssertionConsumerService':
1084 return \SAML2\Constants::BINDING_HTTP_POST;
1085 case 'saml20-idp-remote:ArtifactResolutionService':
1086 return \SAML2\Constants::BINDING_SOAP;
1087 case 'shib13-idp-remote:SingleSignOnService':
1088 return 'urn:mace:shibboleth:1.0:profiles:AuthnRequest';
1089 case 'shib13-sp-remote:AssertionConsumerService':
1090 return 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post';
1092 throw new Exception(
'Missing default binding for '.$endpointType.
' in '.$set);
1108 assert(
'is_string($endpointType)');
1110 $loc = $this->location.
'['.var_export($endpointType,
true).
']:';
1112 if (!array_key_exists($endpointType, $this->configuration)) {
1118 $eps = $this->configuration[$endpointType];
1119 if (is_string(
$eps)) {
1122 } elseif (!is_array(
$eps)) {
1123 throw new Exception($loc.
': Expected array or string.');
1127 foreach (
$eps as
$i => &$ep) {
1128 $iloc = $loc.
'['.var_export(
$i,
true).
']';
1130 if (is_string($ep)) {
1136 $responseLocation = $this->
getString($endpointType.
'Response', null);
1137 if ($responseLocation !== null) {
1138 $ep[
'ResponseLocation'] = $responseLocation;
1140 } elseif (!is_array($ep)) {
1141 throw new Exception($iloc.
': Expected a string or an array.');
1144 if (!array_key_exists(
'Location', $ep)) {
1145 throw new Exception($iloc.
': Missing Location.');
1147 if (!is_string($ep[
'Location'])) {
1148 throw new Exception($iloc.
': Location must be a string.');
1151 if (!array_key_exists(
'Binding', $ep)) {
1152 throw new Exception($iloc.
': Missing Binding.');
1154 if (!is_string($ep[
'Binding'])) {
1155 throw new Exception($iloc.
': Binding must be a string.');
1158 if (array_key_exists(
'ResponseLocation', $ep)) {
1159 if (!is_string($ep[
'ResponseLocation'])) {
1160 throw new Exception($iloc.
': ResponseLocation must be a string.');
1164 if (array_key_exists(
'index', $ep)) {
1165 if (!is_int($ep[
'index'])) {
1166 throw new Exception($iloc.
': index must be an integer.');
1189 assert(
'is_string($endpointType)');
1194 foreach ($endpoints as $ep) {
1195 if ($ep[
'Binding'] === $binding) {
1201 if ($default === self::REQUIRED_OPTION) {
1202 $loc = $this->location.
'['.var_export($endpointType,
true).
']:';
1203 throw new Exception($loc.
'Could not find a supported '.$endpointType.
' endpoint.');
1224 assert(
'is_string($endpointType)');
1228 $defaultEndpoint = \SimpleSAML\Utils\Config\Metadata::getDefaultEndpoint($endpoints,
$bindings);
1229 if ($defaultEndpoint !== null) {
1230 return $defaultEndpoint;
1233 if ($default === self::REQUIRED_OPTION) {
1234 $loc = $this->location.
'['.var_export($endpointType,
true).
']:';
1235 throw new Exception($loc.
'Could not find a supported '.$endpointType.
' endpoint.');
1257 assert(
'is_string($name)');
1260 if (
$ret === $default) {
1265 $loc = $this->location.
'['.var_export(
$name,
true).
']';
1267 if (is_string(
$ret)) {
1271 if (!is_array(
$ret)) {
1272 throw new Exception($loc.
': Must be an array or a string.');
1275 foreach (
$ret as $k => $v) {
1276 if (!is_string($k)) {
1277 throw new Exception($loc.
': Invalid language code: '.var_export($k,
true));
1279 if (!is_string($v)) {
1280 throw new Exception($loc.
'['.var_export($v,
true).
']: Must be a string.');
1305 assert(
'is_bool($required)');
1306 assert(
'is_string($prefix)');
1308 if ($this->
hasValue($prefix.
'keys')) {
1311 if ($use !== null && isset($key[$use]) && !$key[$use]) {
1314 if (isset($key[
'X509Certificate'])) {
1316 $key[
'X509Certificate'] = preg_replace(
'/\s+/',
'', $key[
'X509Certificate']);
1323 } elseif ($this->
hasValue($prefix.
'certData')) {
1324 $certData = $this->
getString($prefix.
'certData');
1325 $certData = preg_replace(
'/\s+/',
'', $certData);
1328 'encryption' =>
true,
1330 'type' =>
'X509Certificate',
1331 'X509Certificate' => $certData,
1334 } elseif ($this->
hasValue($prefix.
'certificate')) {
1339 if (
$data ===
false) {
1340 throw new Exception($this->location.
': Unable to load certificate/public key from file "'.
$file.
'".');
1344 $pattern =
'/^-----BEGIN CERTIFICATE-----([^-]*)^-----END CERTIFICATE-----/m';
1345 if (!preg_match($pattern,
$data, $matches)) {
1347 $this->location.
': Could not find PEM encoded certificate in "'.
$file.
'".' 1350 $certData = preg_replace(
'/\s+/',
'', $matches[1]);
1354 'encryption' =>
true,
1356 'type' =>
'X509Certificate',
1357 'X509Certificate' => $certData,
1376 self::$configDirs =
array();
1377 self::$instance =
array();
1378 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.
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...
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.
static getConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
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.
Create styles array
The data for the language used.
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.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static clearInternalState()
Clear any configuration information cached.
getConfigItem($name, $default=self::REQUIRED_OPTION)
Retrieve an array as a SimpleSAML_Configuration object.