summaryrefslogtreecommitdiffstats
path: root/lib/SimpleSAML/Metadata/SAMLParser.php
diff options
context:
space:
mode:
authorJaime Pérez <jaime.perez@uninett.no>2016-07-26 10:13:13 +0200
committerJaime Pérez <jaime.perez@uninett.no>2016-07-26 10:13:13 +0200
commitb02c5432cb1ffa3c91f7a38169bbcaf1790324bd (patch)
treeca6a15b8f8725a4a404c034b48fd136dbfa7eb51 /lib/SimpleSAML/Metadata/SAMLParser.php
parent09b30417136de9fdc8a80f7dd7f3e27d7f9a4b31 (diff)
downloadsimplesamlphp-b02c5432cb1ffa3c91f7a38169bbcaf1790324bd.zip
simplesamlphp-b02c5432cb1ffa3c91f7a38169bbcaf1790324bd.tar.gz
simplesamlphp-b02c5432cb1ffa3c91f7a38169bbcaf1790324bd.tar.bz2
Bump the version of the SAML2 library.
Now we are finally using the 2.x branch of the SAML2 library, which was also migrated to use namespaces. Even though the library provides an autoloader that allows loading the classes with the old names using class aliasing, we need to do the migration in one commit (at least for most part of it). This is due to the way SimpleSAMLphp checks data types, using inheritance to check objects agains abstract or more general classes. Even though class aliasing works, there's no way to replicate those relationships, and type checks that use the old class names will fail because the aliases are virtually new classes that don't inherit from others.
Diffstat (limited to 'lib/SimpleSAML/Metadata/SAMLParser.php')
-rw-r--r--lib/SimpleSAML/Metadata/SAMLParser.php124
1 files changed, 62 insertions, 62 deletions
diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php
index 02e6e91..edb3909 100644
--- a/lib/SimpleSAML/Metadata/SAMLParser.php
+++ b/lib/SimpleSAML/Metadata/SAMLParser.php
@@ -139,7 +139,7 @@ class SimpleSAML_Metadata_SAMLParser
/**
* This is an array of elements that may be used to validate this element.
*
- * @var SAML2_SignedElementHelper[]
+ * @var \SAML2\SignedElementHelper[]
*/
private $validators = array();
@@ -155,14 +155,14 @@ class SimpleSAML_Metadata_SAMLParser
/**
* This is the constructor for the SAMLParser class.
*
- * @param SAML2_XML_md_EntityDescriptor $entityElement The EntityDescriptor.
+ * @param \SAML2\XML\md\EntityDescriptor $entityElement The EntityDescriptor.
* @param int|NULL $maxExpireTime The unix timestamp for when this entity should expire, or
* NULL if unknown.
* @param array $validators An array of parent elements that may validate this element.
* @param array $parentExtensions An optional array of extensions from the parent element.
*/
private function __construct(
- SAML2_XML_md_EntityDescriptor $entityElement,
+ \SAML2\XML\md\EntityDescriptor $entityElement,
$maxExpireTime,
array $validators = array(),
array $parentExtensions = null
@@ -192,11 +192,11 @@ class SimpleSAML_Metadata_SAMLParser
// look over the RoleDescriptors
foreach ($entityElement->RoleDescriptor as $child) {
- if ($child instanceof SAML2_XML_md_SPSSODescriptor) {
+ if ($child instanceof \SAML2\XML\md\SPSSODescriptor) {
$this->processSPSSODescriptor($child, $expireTime);
- } elseif ($child instanceof SAML2_XML_md_IDPSSODescriptor) {
+ } elseif ($child instanceof \SAML2\XML\md\IDPSSODescriptor) {
$this->processIDPSSODescriptor($child, $expireTime);
- } elseif ($child instanceof SAML2_XML_md_AttributeAuthorityDescriptor) {
+ } elseif ($child instanceof \SAML2\XML\md\AttributeAuthorityDescriptor) {
$this->processAttributeAuthorityDescriptor($child, $expireTime);
}
}
@@ -226,7 +226,7 @@ class SimpleSAML_Metadata_SAMLParser
$data = \SimpleSAML\Utils\HTTP::fetch($file);
try {
- $doc = SAML2_DOMDocumentFactory::fromString($data);
+ $doc = \SAML2\DOMDocumentFactory::fromString($data);
} catch(\Exception $e) {
throw new Exception('Failed to read XML from file: '.$file);
}
@@ -246,7 +246,7 @@ class SimpleSAML_Metadata_SAMLParser
public static function parseString($metadata)
{
try {
- $doc = SAML2_DOMDocumentFactory::fromString($metadata);
+ $doc = \SAML2\DOMDocumentFactory::fromString($metadata);
} catch(\Exception $e) {
throw new Exception('Failed to parse XML string.');
}
@@ -273,16 +273,16 @@ class SimpleSAML_Metadata_SAMLParser
/**
- * This function parses a SAML2_XML_md_EntityDescriptor object which represents a EntityDescriptor element.
+ * This function parses a \SAML2\XML\md\EntityDescriptor object which represents a EntityDescriptor element.
*
- * @param SAML2_XML_md_EntityDescriptor $entityElement A SAML2_XML_md_EntityDescriptor object which represents a
+ * @param \SAML2\XML\md\EntityDescriptor $entityElement A \SAML2\XML\md\EntityDescriptor object which represents a
* EntityDescriptor element.
*
* @return SimpleSAML_Metadata_SAMLParser An instance of this class with the metadata loaded.
*/
public static function parseElement($entityElement)
{
- assert('$entityElement instanceof SAML2_XML_md_EntityDescriptor');
+ assert('$entityElement instanceof \SAML2\XML\md\EntityDescriptor');
return new SimpleSAML_Metadata_SAMLParser($entityElement, null);
}
@@ -309,7 +309,7 @@ class SimpleSAML_Metadata_SAMLParser
$data = \SimpleSAML\Utils\HTTP::fetch($file);
try {
- $doc = SAML2_DOMDocumentFactory::fromString($data);
+ $doc = \SAML2\DOMDocumentFactory::fromString($data);
} catch(\Exception $e) {
throw new Exception('Failed to read XML from file: '.$file);
}
@@ -336,7 +336,7 @@ class SimpleSAML_Metadata_SAMLParser
public static function parseDescriptorsString($string)
{
try {
- $doc = SAML2_DOMDocumentFactory::fromString($string);
+ $doc = \SAML2\DOMDocumentFactory::fromString($string);
} catch(\Exception $e) {
throw new Exception('Failed to parse XML string.');
}
@@ -365,9 +365,9 @@ class SimpleSAML_Metadata_SAMLParser
assert('$element instanceof DOMElement');
if (SimpleSAML\Utils\XML::isDOMElementOfType($element, 'EntityDescriptor', '@md') === true) {
- return self::processDescriptorsElement(new SAML2_XML_md_EntityDescriptor($element));
+ return self::processDescriptorsElement(new \SAML2\XML\md\EntityDescriptor($element));
} elseif (SimpleSAML\Utils\XML::isDOMElementOfType($element, 'EntitiesDescriptor', '@md') === true) {
- return self::processDescriptorsElement(new SAML2_XML_md_EntitiesDescriptor($element));
+ return self::processDescriptorsElement(new \SAML2\XML\md\EntitiesDescriptor($element));
} else {
throw new Exception('Unexpected root node: ['.$element->namespaceURI.']:'.$element->localName);
}
@@ -376,7 +376,7 @@ class SimpleSAML_Metadata_SAMLParser
/**
*
- * @param SAML2_XML_md_EntityDescriptor|SAML2_XML_md_EntitiesDescriptor $element The element we should process.
+ * @param \SAML2\XML\md\EntityDescriptor|\SAML2\XML\md\EntitiesDescriptor $element The element we should process.
* @param int|NULL $maxExpireTime The maximum expiration time
* of the entities.
* @param array $validators The parent-elements that may be
@@ -394,14 +394,14 @@ class SimpleSAML_Metadata_SAMLParser
) {
assert('is_null($maxExpireTime) || is_int($maxExpireTime)');
- if ($element instanceof SAML2_XML_md_EntityDescriptor) {
+ if ($element instanceof \SAML2\XML\md\EntityDescriptor) {
$ret = new SimpleSAML_Metadata_SAMLParser($element, $maxExpireTime, $validators, $parentExtensions);
$ret = array($ret->getEntityId() => $ret);
/** @var SimpleSAML_Metadata_SAMLParser[] $ret */
return $ret;
}
- assert('$element instanceof SAML2_XML_md_EntitiesDescriptor');
+ assert('$element instanceof \SAML2\XML\md\EntitiesDescriptor');
$extensions = self::processExtensions($element, $parentExtensions);
$expTime = self::getExpireTime($element, $maxExpireTime);
@@ -836,13 +836,13 @@ class SimpleSAML_Metadata_SAMLParser
* - 'expire': Timestamp for when this descriptor expires.
* - 'keys': Array of associative arrays with the elements from parseKeyDescriptor.
*
- * @param SAML2_XML_md_RoleDescriptor $element The element we should extract metadata from.
+ * @param \SAML2\XML\md\RoleDescriptor $element The element we should extract metadata from.
* @param int|NULL $expireTime The unix timestamp for when this element should expire, or
* NULL if unknown.
*
* @return array An associative array with metadata we have extracted from this element.
*/
- private static function parseRoleDescriptorType(SAML2_XML_md_RoleDescriptor $element, $expireTime)
+ private static function parseRoleDescriptorType(\SAML2\XML\md\RoleDescriptor $element, $expireTime)
{
assert('is_null($expireTime) || is_int($expireTime)');
@@ -887,13 +887,13 @@ class SimpleSAML_Metadata_SAMLParser
* - 'nameIDFormats': The NameIDFormats supported by this SSODescriptor. This may be an empty array.
* - 'keys': Array of associative arrays with the elements from parseKeyDescriptor:
*
- * @param SAML2_XML_md_SSODescriptorType $element The element we should extract metadata from.
+ * @param \SAML2\XML\md\SSODescriptorType $element The element we should extract metadata from.
* @param int|NULL $expireTime The unix timestamp for when this element should expire, or
* NULL if unknown.
*
* @return array An associative array with metadata we have extracted from this element.
*/
- private static function parseSSODescriptor(SAML2_XML_md_SSODescriptorType $element, $expireTime)
+ private static function parseSSODescriptor(\SAML2\XML\md\SSODescriptorType $element, $expireTime)
{
assert('is_null($expireTime) || is_int($expireTime)');
@@ -916,11 +916,11 @@ class SimpleSAML_Metadata_SAMLParser
/**
* This function extracts metadata from a SPSSODescriptor element.
*
- * @param SAML2_XML_md_SPSSODescriptor $element The element which should be parsed.
+ * @param \SAML2\XML\md\SPSSODescriptor $element The element which should be parsed.
* @param int|NULL $expireTime The unix timestamp for when this element should expire, or
* NULL if unknown.
*/
- private function processSPSSODescriptor(SAML2_XML_md_SPSSODescriptor $element, $expireTime)
+ private function processSPSSODescriptor(\SAML2\XML\md\SPSSODescriptor $element, $expireTime)
{
assert('is_null($expireTime) || is_int($expireTime)');
@@ -952,11 +952,11 @@ class SimpleSAML_Metadata_SAMLParser
/**
* This function extracts metadata from a IDPSSODescriptor element.
*
- * @param SAML2_XML_md_IDPSSODescriptor $element The element which should be parsed.
+ * @param \SAML2\XML\md\IDPSSODescriptor $element The element which should be parsed.
* @param int|NULL $expireTime The unix timestamp for when this element should expire, or
* NULL if unknown.
*/
- private function processIDPSSODescriptor(SAML2_XML_md_IDPSSODescriptor $element, $expireTime)
+ private function processIDPSSODescriptor(\SAML2\XML\md\IDPSSODescriptor $element, $expireTime)
{
assert('is_null($expireTime) || is_int($expireTime)');
@@ -978,12 +978,12 @@ class SimpleSAML_Metadata_SAMLParser
/**
* This function extracts metadata from a AttributeAuthorityDescriptor element.
*
- * @param SAML2_XML_md_AttributeAuthorityDescriptor $element The element which should be parsed.
+ * @param \SAML2\XML\md\AttributeAuthorityDescriptor $element The element which should be parsed.
* @param int|NULL $expireTime The unix timestamp for when this element should
* expire, or NULL if unknown.
*/
private function processAttributeAuthorityDescriptor(
- SAML2_XML_md_AttributeAuthorityDescriptor $element,
+ \SAML2\XML\md\AttributeAuthorityDescriptor $element,
$expireTime
) {
assert('is_null($expireTime) || is_int($expireTime)');
@@ -1021,24 +1021,24 @@ class SimpleSAML_Metadata_SAMLParser
);
// Some extensions may get inherited from a parent element
- if (($element instanceof SAML2_XML_md_EntityDescriptor || $element instanceof SAML2_XML_md_EntitiesDescriptor)
+ if (($element instanceof \SAML2\XML\md\EntityDescriptor || $element instanceof \SAML2\XML\md\EntitiesDescriptor)
&& !empty($parentExtensions['RegistrationInfo'])) {
$ret['RegistrationInfo'] = $parentExtensions['RegistrationInfo'];
}
foreach ($element->Extensions as $e) {
- if ($e instanceof SAML2_XML_shibmd_Scope) {
+ if ($e instanceof \SAML2\XML\shibmd\Scope) {
$ret['scope'][] = $e->scope;
continue;
}
// Entity Attributes are only allowed at entity level extensions and not at RoleDescriptor level
- if ($element instanceof SAML2_XML_md_EntityDescriptor ||
- $element instanceof SAML2_XML_md_EntitiesDescriptor) {
+ if ($element instanceof \SAML2\XML\md\EntityDescriptor ||
+ $element instanceof \SAML2\XML\md\EntitiesDescriptor) {
- if ($e instanceof SAML2_XML_mdrpi_RegistrationInfo) {
+ if ($e instanceof \SAML2\XML\mdrpi\RegistrationInfo) {
// Registration Authority cannot be overridden (warn only if override attempts to change the value)
if (isset($ret['RegistrationInfo']['registrationAuthority'])
&& $ret['RegistrationInfo']['registrationAuthority'] !== $e->registrationAuthority) {
@@ -1048,11 +1048,11 @@ class SimpleSAML_Metadata_SAMLParser
$ret['RegistrationInfo']['registrationAuthority'] = $e->registrationAuthority;
}
}
- if ($e instanceof SAML2_XML_mdattr_EntityAttributes && !empty($e->children)) {
+ if ($e instanceof \SAML2\XML\mdattr\EntityAttributes && !empty($e->children)) {
foreach ($e->children as $attr) {
// only saml:Attribute are currently supported here. The specifications also allows
// saml:Assertions, which more complex processing
- if ($attr instanceof SAML2_XML_saml_Attribute) {
+ if ($attr instanceof \SAML2\XML\saml\Attribute) {
if (empty($attr->Name) || empty($attr->AttributeValue)) {
continue;
}
@@ -1060,7 +1060,7 @@ class SimpleSAML_Metadata_SAMLParser
// attribute names that is not URI is prefixed as this: '{nameformat}name'
$name = $attr->Name;
if (empty($attr->NameFormat)) {
- $name = '{'.SAML2_Const::NAMEFORMAT_UNSPECIFIED.'}'.$attr->Name;
+ $name = '{'.\SAML2\Constants::NAMEFORMAT_UNSPECIFIED.'}'.$attr->Name;
} elseif ($attr->NameFormat !== 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri') {
$name = '{'.$attr->NameFormat.'}'.$attr->Name;
}
@@ -1077,8 +1077,8 @@ class SimpleSAML_Metadata_SAMLParser
}
// UIInfo elements are only allowed at RoleDescriptor level extensions
- if ($element instanceof SAML2_XML_md_RoleDescriptor) {
- if ($e instanceof SAML2_XML_mdui_UIInfo) {
+ if ($element instanceof \SAML2\XML\md\RoleDescriptor) {
+ if ($e instanceof \SAML2\XML\mdui\UIInfo) {
$ret['UIInfo']['DisplayName'] = $e->DisplayName;
$ret['UIInfo']['Description'] = $e->Description;
@@ -1086,7 +1086,7 @@ class SimpleSAML_Metadata_SAMLParser
$ret['UIInfo']['PrivacyStatementURL'] = $e->PrivacyStatementURL;
foreach ($e->Keywords as $uiItem) {
- if (!($uiItem instanceof SAML2_XML_mdui_Keywords)
+ if (!($uiItem instanceof \SAML2\XML\mdui\Keywords)
|| empty($uiItem->Keywords)
|| empty($uiItem->lang)
) {
@@ -1095,7 +1095,7 @@ class SimpleSAML_Metadata_SAMLParser
$ret['UIInfo']['Keywords'][$uiItem->lang] = $uiItem->Keywords;
}
foreach ($e->Logo as $uiItem) {
- if (!($uiItem instanceof SAML2_XML_mdui_Logo)
+ if (!($uiItem instanceof \SAML2\XML\mdui\Logo)
|| empty($uiItem->url)
|| empty($uiItem->height)
|| empty($uiItem->width)
@@ -1116,20 +1116,20 @@ class SimpleSAML_Metadata_SAMLParser
}
// DiscoHints elements are only allowed at IDPSSODescriptor level extensions
- if ($element instanceof SAML2_XML_md_IDPSSODescriptor) {
+ if ($element instanceof \SAML2\XML\md\IDPSSODescriptor) {
- if ($e instanceof SAML2_XML_mdui_DiscoHints) {
+ if ($e instanceof \SAML2\XML\mdui\DiscoHints) {
$ret['DiscoHints']['IPHint'] = $e->IPHint;
$ret['DiscoHints']['DomainHint'] = $e->DomainHint;
$ret['DiscoHints']['GeolocationHint'] = $e->GeolocationHint;
}
}
- if (!($e instanceof SAML2_XML_Chunk)) {
+ if (!($e instanceof \SAML2\XML\Chunk)) {
continue;
}
- if ($e->localName === 'Attribute' && $e->namespaceURI === SAML2_Const::NS_SAML) {
+ if ($e->localName === 'Attribute' && $e->namespaceURI === \SAML2\Constants::NS_SAML) {
$attribute = $e->getXML();
$name = $attribute->getAttribute('Name');
@@ -1154,9 +1154,9 @@ class SimpleSAML_Metadata_SAMLParser
/**
* Parse and process a Organization element.
*
- * @param SAML2_XML_md_Organization $element The Organization element.
+ * @param \SAML2\XML\md\Organization $element The Organization element.
*/
- private function processOrganization(SAML2_XML_md_Organization $element)
+ private function processOrganization(\SAML2\XML\md\Organization $element)
{
$this->organizationName = $element->OrganizationName;
$this->organizationDisplayName = $element->OrganizationDisplayName;
@@ -1167,10 +1167,10 @@ class SimpleSAML_Metadata_SAMLParser
/**
* Parse and process a ContactPerson element.
*
- * @param SAML2_XML_md_ContactPerson $element The ContactPerson element.
+ * @param \SAML2\XML\md\ContactPerson $element The ContactPerson element.
*/
- private function processContactPerson(SAML2_XML_md_ContactPerson $element)
+ private function processContactPerson(\SAML2\XML\md\ContactPerson $element)
{
$contactPerson = array();
if (!empty($element->contactType)) {
@@ -1200,10 +1200,10 @@ class SimpleSAML_Metadata_SAMLParser
/**
* This function parses AttributeConsumerService elements.
*
- * @param SAML2_XML_md_AttributeConsumingService $element The AttributeConsumingService to parse.
+ * @param \SAML2\XML\md\AttributeConsumingService $element The AttributeConsumingService to parse.
* @param array $sp The array with the SP's metadata.
*/
- private static function parseAttributeConsumerService(SAML2_XML_md_AttributeConsumingService $element, &$sp)
+ private static function parseAttributeConsumerService(\SAML2\XML\md\AttributeConsumingService $element, &$sp)
{
assert('is_array($sp)');
@@ -1228,13 +1228,13 @@ class SimpleSAML_Metadata_SAMLParser
if ($child->NameFormat !== null) {
$attrformat = $child->NameFormat;
} else {
- $attrformat = SAML2_Const::NAMEFORMAT_UNSPECIFIED;
+ $attrformat = \SAML2\Constants::NAMEFORMAT_UNSPECIFIED;
}
if ($format === null) {
$format = $attrformat;
} elseif ($format !== $attrformat) {
- $format = SAML2_Const::NAMEFORMAT_UNSPECIFIED;
+ $format = \SAML2\Constants::NAMEFORMAT_UNSPECIFIED;
}
}
@@ -1246,7 +1246,7 @@ class SimpleSAML_Metadata_SAMLParser
unset($sp['attributes.required']);
}
- if ($format !== SAML2_Const::NAMEFORMAT_UNSPECIFIED && $format !== null) {
+ if ($format !== \SAML2\Constants::NAMEFORMAT_UNSPECIFIED && $format !== null) {
$sp['attributes.NameFormat'] = $format;
}
}
@@ -1262,11 +1262,11 @@ class SimpleSAML_Metadata_SAMLParser
* - 'index': The index of this endpoint. This attribute is only for indexed endpoints.
* - 'isDefault': Whether this endpoint is the default endpoint for this type. This attribute may not exist.
*
- * @param SAML2_XML_md_EndpointType $element The element which should be parsed.
+ * @param \SAML2\XML\md\EndpointType $element The element which should be parsed.
*
* @return array An associative array with the data we have extracted from the element.
*/
- private static function parseGenericEndpoint(SAML2_XML_md_EndpointType $element)
+ private static function parseGenericEndpoint(\SAML2\XML\md\EndpointType $element)
{
$ep = array();
@@ -1277,7 +1277,7 @@ class SimpleSAML_Metadata_SAMLParser
$ep['ResponseLocation'] = $element->ResponseLocation;
}
- if ($element instanceof SAML2_XML_md_IndexedEndpointType) {
+ if ($element instanceof \SAML2\XML\md\IndexedEndpointType) {
$ep['index'] = $element->index;
if ($element->isDefault !== null) {
@@ -1317,11 +1317,11 @@ class SimpleSAML_Metadata_SAMLParser
* - 'type: The type of the key. 'X509Certificate' is the only key type we support.
* - 'X509Certificate': The contents of the first X509Certificate element (if the type is 'X509Certificate ').
*
- * @param SAML2_XML_md_KeyDescriptor $kd The KeyDescriptor element.
+ * @param \SAML2\XML\md\KeyDescriptor $kd The KeyDescriptor element.
*
* @return array|null An associative array describing the key, or null if this is an unsupported key.
*/
- private static function parseKeyDescriptor(SAML2_XML_md_KeyDescriptor $kd)
+ private static function parseKeyDescriptor(\SAML2\XML\md\KeyDescriptor $kd)
{
$r = array();
@@ -1339,9 +1339,9 @@ class SimpleSAML_Metadata_SAMLParser
$keyInfo = $kd->KeyInfo;
foreach ($keyInfo->info as $i) {
- if ($i instanceof SAML2_XML_ds_X509Data) {
+ if ($i instanceof \SAML2\XML\ds\X509Data) {
foreach ($i->data as $d) {
- if ($d instanceof SAML2_XML_ds_X509Certificate) {
+ if ($d instanceof \SAML2\XML\ds\X509Certificate) {
$r['type'] = 'X509Certificate';
$r['X509Certificate'] = $d->certificate;
return $r;
@@ -1410,7 +1410,7 @@ class SimpleSAML_Metadata_SAMLParser
*
* @param DOMDocument $doc The DOMDocument where we should find the EntityDescriptor node.
*
- * @return SAML2_XML_md_EntityDescriptor The DOMEntity which represents the EntityDescriptor.
+ * @return \SAML2\XML\md\EntityDescriptor The DOMEntity which represents the EntityDescriptor.
* @throws Exception If the document is empty or the first element is not an EntityDescriptor element.
*/
private static function findEntityDescriptor($doc)
@@ -1428,7 +1428,7 @@ class SimpleSAML_Metadata_SAMLParser
throw new Exception('Expected first element in the metadata document to be an EntityDescriptor element.');
}
- return new SAML2_XML_md_EntityDescriptor($ed);
+ return new \SAML2\XML\md\EntityDescriptor($ed);
}