Revision: 1989
Author: olavmrk
Date: Fri Nov 13 01:17:03 2009
Log: SAML2_AuthnRequest: Support for RequestedAuthnContext.

Merged into 1.5 branch from r1983.
http://code.google.com/p/simplesamlphp/source/detail?r=1989

Modified:
  /branches/simplesamlphp-1.5/lib/SAML2/AuthnRequest.php

=======================================
--- /branches/simplesamlphp-1.5/lib/SAML2/AuthnRequest.php      Fri Nov 13  
01:16:53 2009
+++ /branches/simplesamlphp-1.5/lib/SAML2/AuthnRequest.php      Fri Nov 13  
01:17:03 2009
@@ -53,6 +53,18 @@
        private $protocolBinding;


+       /**
+        * What authentication context was requested.
+        *
+        * Array with the following elements.
+        * - AuthnContextClassRef (required)
+        * - Comparison (optinal)
+        *
+        * @var array
+        */
+       private $requestedAuthnContext;
+
+
        /**
         * Constructor for SAML 2 authentication request messages.
         *
@@ -94,7 +106,28 @@
                                $this->nameIdPolicy['AllowCreate'] =  
SAML2_Utils::parseBoolean($nameIdPolicy, 'AllowCreate', FALSE);
                        }
                }
-
+
+               $requestedAuthnContext =  
SAML2_Utils::xpQuery($xml, './saml_protocol:RequestedAuthnContext');
+               if (!empty($requestedAuthnContext)) {
+                       $requestedAuthnContext = $requestedAuthnContext[0];
+
+                       $rac = array(
+                               'AuthnContextClassRef' => array(),
+                               'Comparison' => 'exact',
+                       );
+
+                       $accr =  
SAML2_Utils::xpQuery($requestedAuthnContext, 
'./saml_assertion:AuthnContextClassRef');
+                       foreach ($accr as $i) {
+                               $rac['AuthnContextClassRef'][] = 
trim($i->textContent);
+                       }
+
+                       if ($requestedAuthnContext->hasAttribute('Comparison')) 
{
+                               $rac['Comparison'] =  
$requestedAuthnContext->getAttribute('Comparison');
+                       }
+
+                       $this->requestedAuthnContext = $rac;
+               }
+
                $idpEntries =  
SAML2_Utils::xpQuery($xml, 
'./saml_protocol:Scoping/saml_protocol:IDPList/saml_protocol:IDPEntry');

                foreach($idpEntries as $idpEntry) {
@@ -244,6 +277,28 @@

                $this->protocolBinding = $protocolBinding;
        }
+
+
+       /**
+        * Retrieve the RequestedAuthnContext.
+        *
+        * @return array|NULL  The RequestedAuthnContext.
+        */
+       public function getRequestedAuthnContext() {
+               return $this->requestedAuthnContext;
+       }
+
+
+       /**
+        * Set the RequestedAuthnContext.
+        *
+        * @param array|NULL $requestedAuthnContext  The RequestedAuthnContext.
+        */
+       public function setRequestedAuthnContext($requestedAuthnContext) {
+               assert('is_array($requestedAuthnContext) ||  
is_null($requestedAuthnContext)');
+
+               $this->requestedAuthnContext = $requestedAuthnContext;
+       }


        /**
@@ -284,6 +339,20 @@
                        }
                        $root->appendChild($nameIdPolicy);
                }
+
+               $rac = $this->requestedAuthnContext;
+               if (!empty($rac) && !empty($rac['AuthnContextClassRef'])) {
+                       $e =  
$this->document->createElementNS(SAML2_Const::NS_SAMLP, 
'RequestedAuthnContext');
+                       $root->appendChild($e);
+                       if (isset($rac['Comparison']) && $rac['Comparison'] !== 
'exact') {
+                               $e->setAttribute('Comparison', 
$rac['Comparison']);
+                       }
+                       foreach ($rac['AuthnContextClassRef'] as $accr) {
+                               $i =  
$this->document->createElementNS(SAML2_Const::NS_SAML, 'AuthnContextClassRef');
+                               
$i->appendChild($this->document->createTextNode($accr));
+                               $e->appendChild($i);
+                       }
+               }

                if (count($this->IDPList) > 0) {
                        $scoping =  
$this->document->createElementNS(SAML2_Const::NS_SAMLP, 'Scoping');

--~--~---------~--~----~------------~-------~--~----~
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