Revision: 2174
Author: olavmrk
Date: Fri Feb 12 00:35:08 2010
Log: SAMLBuilder: Add AttributeConsumingService to SAML 1.1 metadata.
http://code.google.com/p/simplesamlphp/source/detail?r=2174

Modified:
 /trunk/lib/SimpleSAML/Metadata/SAMLBuilder.php

=======================================
--- /trunk/lib/SimpleSAML/Metadata/SAMLBuilder.php      Wed Feb 10 03:32:00 2010
+++ /trunk/lib/SimpleSAML/Metadata/SAMLBuilder.php      Fri Feb 12 00:35:08 2010
@@ -259,6 +259,56 @@
                }

        }
+
+
+       /**
+        * Add an AttributeConsumingService element to the metadata.
+        *
+        * @param DOMElement $spDesc  The SPSSODescriptor element.
+        * @param SimpleSAML_Configuration $metadata  The metadata.
+        */
+ private function addAttributeConsumingService(DOMElement $spDesc, SimpleSAML_Configuration $metadata) {
+               $attributes = $metadata->getArray('attributes', array());
+               $name = $metadata->getLocalizedString('name', NULL);
+
+               if ($name === NULL || count($attributes) == 0) {
+ /* We cannot add an AttributeConsumingService without name and attributes. */
+                       return;
+               }
+
+               /*
+ * Add an AttributeConsumingService element with information as name and description and list
+                * of requested attributes
+                */
+               $attributeconsumer = 
$this->createElement('AttributeConsumingService');
+               $attributeconsumer->setAttribute('index', '0');
+
+               foreach($name AS $lang => $localname) {
+                       $t = $this->createTextElement('ServiceName', 
$localname);
+                       $t->setAttribute('xml:lang', $lang);
+                       $attributeconsumer->appendChild($t);
+               }
+
+               $description = $metadata->getLocalizedString('description', 
array());
+               foreach ($description as $lang => $localname) {
+                       $t = $this->createTextElement('ServiceDescription', 
$localname);
+                       $t->setAttribute('xml:lang', $lang);
+                       $attributeconsumer->appendChild($t);
+               }
+
+ $nameFormat = $metadata->getString('attributes.NameFormat', SAML2_Const::NAMEFORMAT_UNSPECIFIED);
+
+               foreach ($attributes as $attribute) {
+                       $t = $this->createElement('RequestedAttribute');
+                       $t->setAttribute('Name', $attribute);
+                       if ($nameFormat !== 
SAML2_Const::NAMEFORMAT_UNSPECIFIED) {
+                               $t->setAttribute('NameFormat', $nameFormat);
+                       }
+                       $attributeconsumer->appendChild($t);
+               }
+
+               $spDesc->appendChild($attributeconsumer);
+       }


        /**
@@ -334,42 +384,7 @@
                }
                $this->addEndpoints($e, 'AssertionConsumerService', $endpoints);

-               $attributes = $metadata->getArray('attributes', array());
-               if ( $metadata->hasValue('name') && count($attributes) > 0 ) {
-                       /*
- * Add an AttributeConsumingService element with information as name and description and list
-                        * of requested attributes
-                        */
-                       $attributeconsumer = 
$this->createElement('AttributeConsumingService');
-                       $attributeconsumer->setAttribute('index', '0');
-
-                       $name = $metadata->getLocalizedString('name');
-                       foreach($name AS $lang => $localname) {
-                               $t = $this->createTextElement('ServiceName', 
$localname);
-                               $t->setAttribute('xml:lang', $lang);
-                               $attributeconsumer->appendChild($t);
-                       }
-
-                       $description = 
$metadata->getLocalizedString('description', array());
-                       foreach ($description as $lang => $localname) {
-                               $t = 
$this->createTextElement('ServiceDescription', $localname);
-                               $t->setAttribute('xml:lang', $lang);
-                               $attributeconsumer->appendChild($t);
-                       }
-
- $nameFormat = $metadata->getString('attributes.NameFormat', SAML2_Const::NAMEFORMAT_UNSPECIFIED);
-
-                       foreach ($attributes as $attribute) {
-                               $t = $this->createElement('RequestedAttribute');
-                               $t->setAttribute('Name', $attribute);
-                               if ($nameFormat !== 
SAML2_Const::NAMEFORMAT_UNSPECIFIED) {
-                                       $t->setAttribute('NameFormat', 
$nameFormat);
-                               }
-                               $attributeconsumer->appendChild($t);
-                       }
-
-                       $e->appendChild($attributeconsumer);
-               }
+               $this->addAttributeConsumingService($e, $metadata);

                $this->entityDescriptor->appendChild($e);

@@ -462,6 +477,8 @@
                }
                $this->addEndpoints($e, 'AssertionConsumerService', $endpoints);

+               $this->addAttributeConsumingService($e, $metadata);
+
                $this->entityDescriptor->appendChild($e);
        }

--
You received this message because you are subscribed to the Google Groups 
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simplesamlphp-commits?hl=en.

Reply via email to