@@ -16,10 +16,12 @@ class OneLogin_Saml2_IdPMetadataParser
1616 * metadata contains more than one
1717 * IDPSSODescriptor, the first is returned
1818 * @param string $desiredNameIdFormat If available on IdP metadata, use that nameIdFormat
19+ * @param string $desiredSSOBinding Parse specific binding SSO endpoint.
20+ * @param string $desiredSLOBinding Parse specific binding SLO endpoint.
1921 *
2022 * @return array metadata info in php-saml settings format
2123 */
22- public static function parseRemoteXML ($ url , $ entityId = null , $ desiredNameIdFormat = null )
24+ public static function parseRemoteXML ($ url , $ entityId = null , $ desiredNameIdFormat = null , $ desiredSSOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT , $ desiredSLOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT )
2325 {
2426 $ metadataInfo = array ();
2527
@@ -33,7 +35,7 @@ public static function parseRemoteXML($url, $entityId = null, $desiredNameIdForm
3335
3436 $ xml = curl_exec ($ ch );
3537 if ($ xml !== false ) {
36- $ metadataInfo = self ::parseXML ($ xml , $ entityId );
38+ $ metadataInfo = self ::parseXML ($ xml , $ entityId, $ desiredNameIdFormat , $ desiredSSOBinding , $ desiredSLOBinding );
3739 } else {
3840 throw new Exception (curl_error ($ ch ), curl_errno ($ ch ));
3941 }
@@ -51,17 +53,19 @@ public static function parseRemoteXML($url, $entityId = null, $desiredNameIdForm
5153 * metadata contains more than one
5254 * IDPSSODescriptor, the first is returned
5355 * @param string $desiredNameIdFormat If available on IdP metadata, use that nameIdFormat
56+ * @param string $desiredSSOBinding Parse specific binding SSO endpoint.
57+ * @param string $desiredSLOBinding Parse specific binding SLO endpoint.
5458 *
5559 * @return array metadata info in php-saml settings format
5660 */
57- public static function parseFileXML ($ filepath , $ entityId = null , $ desiredNameIdFormat = null )
61+ public static function parseFileXML ($ filepath , $ entityId = null , $ desiredNameIdFormat = null , $ desiredSSOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT , $ desiredSLOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT )
5862 {
5963 $ metadataInfo = array ();
6064
6165 try {
6266 if (file_exists ($ filepath )) {
6367 $ data = file_get_contents ($ filepath );
64- $ metadataInfo = self ::parseXML ($ data , $ entityId );
68+ $ metadataInfo = self ::parseXML ($ data , $ entityId, $ desiredNameIdFormat , $ desiredSSOBinding , $ desiredSLOBinding );
6569 }
6670 } catch (Exception $ e ) {
6771 }
@@ -77,10 +81,13 @@ public static function parseFileXML($filepath, $entityId = null, $desiredNameIdF
7781 * metadata contains more than one
7882 * IDPSSODescriptor, the first is returned
7983 * @param string $desiredNameIdFormat If available on IdP metadata, use that nameIdFormat
84+ * @param string $desiredSSOBinding Parse specific binding SSO endpoint.
85+ * @param string $desiredSLOBinding Parse specific binding SLO endpoint.
8086 *
8187 * @return array metadata info in php-saml settings format
88+ * @throws \Exception
8289 */
83- public static function parseXML ($ xml , $ entityId = null , $ desiredNameIdFormat = null )
90+ public static function parseXML ($ xml , $ entityId = null , $ desiredNameIdFormat = null , $ desiredSSOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT , $ desiredSLOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT )
8491 {
8592 $ metadataInfo = array ();
8693
@@ -114,7 +121,7 @@ public static function parseXML($xml, $entityId = null, $desiredNameIdFormat = n
114121 $ metadataInfo ['idp ' ]['entityId ' ] = $ entityId ;
115122 }
116123
117- $ ssoNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleSignOnService[@Binding=" ' .OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT .'"] ' , $ idpDescriptor );
124+ $ ssoNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleSignOnService[@Binding=" ' .$ desiredSSOBinding .'"] ' , $ idpDescriptor );
118125 if ($ ssoNodes ->length < 1 ) {
119126 $ ssoNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleSignOnService ' , $ idpDescriptor );
120127 }
@@ -125,7 +132,7 @@ public static function parseXML($xml, $entityId = null, $desiredNameIdFormat = n
125132 );
126133 }
127134
128- $ sloNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleLogoutService[@Binding=" ' .OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT .'"] ' , $ idpDescriptor );
135+ $ sloNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleLogoutService[@Binding=" ' .$ desiredSLOBinding .'"] ' , $ idpDescriptor );
129136 if ($ sloNodes ->length < 1 ) {
130137 $ sloNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleLogoutService ' , $ idpDescriptor );
131138 }
@@ -143,20 +150,20 @@ public static function parseXML($xml, $entityId = null, $desiredNameIdFormat = n
143150 if (!empty ($ keyDescriptorCertSigningNodes ) || !empty ($ keyDescriptorCertEncryptionNodes )) {
144151 $ metadataInfo ['idp ' ]['x509certMulti ' ] = array ();
145152 if (!empty ($ keyDescriptorCertSigningNodes )) {
146- $ idpInfo ['x509certMulti ' ]['signing ' ] = array ();
147153 foreach ($ keyDescriptorCertSigningNodes as $ keyDescriptorCertSigningNode ) {
148154 $ metadataInfo ['idp ' ]['x509certMulti ' ]['signing ' ][] = OneLogin_Saml2_Utils::formatCert ($ keyDescriptorCertSigningNode ->nodeValue , false );
149155 }
150156 }
151157 if (!empty ($ keyDescriptorCertEncryptionNodes )) {
152- $ idpInfo ['x509certMulti ' ]['encryption ' ] = array ();
153158 foreach ($ keyDescriptorCertEncryptionNodes as $ keyDescriptorCertEncryptionNode ) {
154159 $ metadataInfo ['idp ' ]['x509certMulti ' ]['encryption ' ][] = OneLogin_Saml2_Utils::formatCert ($ keyDescriptorCertEncryptionNode ->nodeValue , false );
155160 }
156161 }
157162
158163 $ idpCertdata = $ metadataInfo ['idp ' ]['x509certMulti ' ];
159- if (count ($ idpCertdata ) == 1 || ((isset ($ idpCertdata ['signing ' ]) && count ($ idpCertdata ['signing ' ]) == 1 ) && isset ($ idpCertdata ['encryption ' ]) && count ($ idpCertdata ['encryption ' ]) == 1 && strcmp ($ idpCertdata ['signing ' ][0 ], $ idpCertdata ['encryption ' ][0 ]) == 0 )) {
164+ if ((count ($ idpCertdata ) == 1 and
165+ ((isset ($ idpCertdata ['signing ' ]) and count ($ idpCertdata ['signing ' ]) == 1 ) or (isset ($ idpCertdata ['encryption ' ]) and count ($ idpCertdata ['encryption ' ]) == 1 ))) or
166+ ((isset ($ idpCertdata ['signing ' ]) && count ($ idpCertdata ['signing ' ]) == 1 ) && isset ($ idpCertdata ['encryption ' ]) && count ($ idpCertdata ['encryption ' ]) == 1 && strcmp ($ idpCertdata ['signing ' ][0 ], $ idpCertdata ['encryption ' ][0 ]) == 0 )) {
160167 if (isset ($ metadataInfo ['idp ' ]['x509certMulti ' ]['signing ' ][0 ])) {
161168 $ metadataInfo ['idp ' ]['x509cert ' ] = $ metadataInfo ['idp ' ]['x509certMulti ' ]['signing ' ][0 ];
162169 } else {
@@ -189,8 +196,8 @@ public static function parseXML($xml, $entityId = null, $desiredNameIdFormat = n
189196 /**
190197 * Inject metadata info into php-saml settings array
191198 *
192- * @param string $settings php-saml settings array
193- * @param string $metadataInfo array metadata info
199+ * @param array $settings php-saml settings array
200+ * @param array $metadataInfo array metadata info
194201 *
195202 * @return array settings
196203 */
0 commit comments