Development

/plugins/dcSamlPlugin/lib/saml/CustomSamlResponse.class.php

You must first sign up to be able to contribute.

root/plugins/dcSamlPlugin/lib/saml/CustomSamlResponse.class.php

Revision 33456, 2.3 kB (checked in by mbrown, 1 year ago)

se corrigen y hacen varios cambios

  • Property svn:executable set to *
Line 
1 <?php
2
3 /**
4  * PHP Custom Saml Response implementation.
5  *
6  * @package lib.saml
7  *
8  * @author Matías Brown <mbrown@cespi.unlp.edu.ar>
9  */
10 class CustomSamlResponse extends SamlResponse
11 {
12   /**
13    * Return the Dom xml xpath
14    * @return DOMXPath
15    */
16   private function get_xpath()
17   {
18     $xpath = new DOMXPath($this->xml);
19     $xpath->registerNamespace("samlp","urn:oasis:names:tc:SAML:2.0:protocol");
20     $xpath->registerNamespace("saml","urn:oasis:names:tc:SAML:2.0:assertion");
21     $xpath->registerNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
22     return $xpath;
23   }
24
25   /**
26     * Get the NameID provided by the SAML response from the IdP.
27     */
28   function get_nameid() {
29     $xpath = $this->get_xpath();
30
31     $signatureQuery = "//ds:Reference[@URI]";
32     $id = substr($xpath->query($signatureQuery)->item(0)->getAttribute('URI'), 1);
33
34     $nameQuery = "/samlp:Response/saml:Assertion[@ID='$id']/saml:Subject/saml:NameID";
35     $entries = $xpath->query($nameQuery);
36
37     return $entries->item(0)->nodeValue;
38   }
39
40   /**
41    * Return the attribute value in the xaml file
42    *
43    * @param string $attr
44    * @return string
45    */
46   public function get_attribute($attr)
47   {
48     $xpath = $this->get_xpath();
49     $signatureQuery = "//ds:Reference[@URI]";
50     $id = substr($xpath->query($signatureQuery)->item(0)->getAttribute('URI'), 1);
51     $q = "//saml:Attribute[@Name='$attr']/saml:AttributeValue";
52     $es = $xpath->query($q);
53     return $es->item(0)->nodeValue;
54   }
55  
56   private function get_attributes_names()
57   {
58     $xpath = $this->get_xpath();
59     $signatureQuery = "//saml:Attribute[@Name]";
60     $list = $xpath->query($signatureQuery);
61     $attributes_names = array();
62     for($i = 0; $i < $list->length; $i++)
63     {
64       $attributes_names[] = $list->item($i)->getAttribute('Name');
65     }
66     return $attributes_names;
67   }
68  
69   public function get_attributes()
70   {
71     $xpath = $this->get_xpath();
72     $signatureQuery = "//ds:Reference[@URI]";
73     $id = substr($xpath->query($signatureQuery)->item(0)->getAttribute('URI'), 1);
74     $attributes = array();
75     foreach($this->get_attributes_names() as $attr_name)
76     {
77       $q = "//saml:Attribute[@Name='$attr_name']/saml:AttributeValue";
78       $es = $xpath->query($q);
79       $attributes[$attr_name] = $es->item(0)->nodeValue;
80     }
81     return $attributes;
82   }
83 }
84
Note: See TracBrowser for help on using the browser.