Commit 94901a93 authored by haemmer's avatar haemmer
Browse files

Implemented changes for #3123

Processing of a 5.5MB SWITCHaai metadata file is not only twice as fast but also consumes considerably less memory
parent 6d689f4d
......@@ -209,8 +209,8 @@ function parseMetadata($metadataFile, $defaultLanguage){
return Array(false, false);
}
$doc = new DOMDocument();
if(!$doc->load( $metadataFile )){
$CurrentXMLReaderNode = new XMLReader();
if(!$CurrentXMLReaderNode->open($metadataFile, null, LIBXML_PARSEHUGE | LIBXML_NOERROR | LIBXML_NOWARNING | 1)){
$errorMsg = 'Could not parse metadata file '.$metadataFile;
if (isRunViaCLI()){
echo $errorMsg."\n";
......@@ -220,41 +220,43 @@ function parseMetadata($metadataFile, $defaultLanguage){
return Array(false, false);
}
$EntityDescriptors = $doc->getElementsByTagNameNS( 'urn:oasis:names:tc:SAML:2.0:metadata', 'EntityDescriptor' );
$metadataIDProviders = Array();
$metadataSProviders = Array();
foreach( $EntityDescriptors as $EntityDescriptor ){
$entityID = $EntityDescriptor->getAttribute('entityID');
foreach($EntityDescriptor->childNodes as $RoleDescriptor) {
$nodeName = $RoleDescriptor->localName;
switch($nodeName){
case 'IDPSSODescriptor':
$IDP = processIDPRoleDescriptor($RoleDescriptor);
if ($IDP){
$metadataIDProviders[$entityID] = $IDP;
}
break;
case 'SPSSODescriptor':
$SP = processSPRoleDescriptor($RoleDescriptor);
if ($SP){
$metadataSProviders[$entityID] = $SP;
} else {
$errorMsg = "Failed to load SP with entityID $entityID from metadata file $metadataFile";
if (isRunViaCLI()){
echo $errorMsg."\n";
// Process individual EntityDescriptors
while( $CurrentXMLReaderNode->read() ) {
if($CurrentXMLReaderNode->nodeType == XMLReader::ELEMENT && $CurrentXMLReaderNode->localName === 'EntityDescriptor') {
$entityID = $CurrentXMLReaderNode->getAttribute('entityID');
$EntityDescriptorXML = $CurrentXMLReaderNode->readOuterXML();
$EntityDescriptorDOM = new DOMDocument();
$EntityDescriptorDOM->loadXML($EntityDescriptorXML);
// Check role descriptors
foreach($EntityDescriptorDOM->documentElement->childNodes as $RoleDescriptor) {
$nodeName = $RoleDescriptor->localName;
switch($nodeName){
case 'IDPSSODescriptor':
$IDP = processIDPRoleDescriptor($RoleDescriptor);
if ($IDP){
$metadataIDProviders[$entityID] = $IDP;
}
break;
case 'SPSSODescriptor':
$SP = processSPRoleDescriptor($RoleDescriptor);
if ($SP){
$metadataSProviders[$entityID] = $SP;
} else {
logWarning($errorMsg);
$errorMsg = "Failed to load SP with entityID $entityID from metadata file $metadataFile";
if (isRunViaCLI()){
echo $errorMsg."\n";
} else {
logWarning($errorMsg);
}
}
}
break;
default:
break;
default:
}
}
}
}
// Output result
$infoMsg = "Successfully parsed metadata file ".$metadataFile. ". Found ".count($metadataIDProviders)." IdPs and ".count($metadataSProviders)." SPs";
if (isRunViaCLI()){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment