From 45b0af55780069738343ca42a0f4cd16be3f1acf Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Wed, 4 Nov 2009 13:51:34 +0000 Subject: [PATCH] SimpleSAML_Configuration: Add getEndpoints()-function. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1943 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Configuration.php | 105 +++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php index 7643ecae0..3bca636a7 100644 --- a/lib/SimpleSAML/Configuration.php +++ b/lib/SimpleSAML/Configuration.php @@ -839,6 +839,111 @@ class SimpleSAML_Configuration { return $this->configuration; } + + /** + * Retrieve the default binding for the given endpoint type. + * + * This function combines the current metadata type (saml 2 / saml 1.1) + * with the endpoint type to determine which binding is the default. + * + * @param string $endpointType The endpoint type. + * @return string The default binding. + */ + private function getDefaultBinding($endpointType) { + assert('is_string($endpointType)'); + + $set = $this->getString('metadata-set'); + switch ($set.':'.$endpointType) { + case 'saml20-idp-remote:SingleSignOnService': + case 'saml20-idp-remote:SingleLogoutService': + case 'saml20-sp-remote:SingleLogoutService': + return SAML2_Const::BINDING_HTTP_REDIRECT; + case 'saml20-sp-remote:AssertionConsumerService': + return SAML2_Const::BINDING_HTTP_POST; + case 'shib13-idp-remote:SingleSignOnService': + return 'urn:mace:shibboleth:1.0:profiles:AuthnRequest'; + case 'shib13-sp-remote:AssertionConsumerService': + return 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post'; + default: + throw new Exception('Missing default binding for ' . $endpointType . ' in ' . $set); + } + } + + + /** + * Helper function for dealing with metadata endpoints. + * + * @param string $endpointType The endpoint type. + * @return array Array of endpoints of the given type. + */ + public function getEndpoints($endpointType) { + assert('is_string($endpointType)'); + + $loc = $this->location . '[' . var_export($endpointType, TRUE) . ']:'; + + if (!array_key_exists($endpointType, $this->configuration)) { + /* No endpoints of the given type. */ + return array(); + } + + + $eps = $this->configuration[$endpointType]; + if (is_string($eps)) { + /* For backwards-compatibility. */ + $eps = array($eps); + } elseif (!is_array($eps)) { + throw new Exception($loc . ': Expected array or string.'); + } + + + foreach ($eps as $i => &$ep) { + $iloc = $loc . '[' . var_export($i, TRUE) . ']'; + + if (is_string($ep)) { + /* For backwards-compatibility. */ + $ep = array( + 'Location' => $ep, + 'Binding' => $this->getDefaultBinding($endpointType), + ); + $responseLocation = $this->getString($endpointType . 'Response', NULL); + if ($responseLocation !== NULL) { + $ep['ResponseLocation'] = $responseLocation; + } + } elseif (!is_array($ep)) { + throw new Exception($iloc . ': Expected a string or an array.'); + } + + if (!array_key_exists('Location', $ep)) { + throw new Exception($iloc . ': Missing Location.'); + } + if (!is_string($ep['Location'])) { + throw new Exception($iloc . ': Location must be a string.'); + } + + if (!array_key_exists('Binding', $ep)) { + throw new Exception($iloc . ': Missing Binding.'); + } + if (!is_string($ep['Binding'])) { + throw new Exception($iloc . ': Binding must be a string.'); + } + + if (array_key_exists('ResponseLocation', $ep)) { + if (!is_string($ep['ResponseLocation'])) { + throw new Exception($iloc . ': ResponseLocation must be a string.'); + } + } + + if (array_key_exists('index', $ep)) { + if (!is_int($ep['index'])) { + throw new Exception($iloc . ': index must be an integer.'); + } + } + + } + + return $eps; + } + } ?> \ No newline at end of file -- GitLab