@@ -27,10 +27,12 @@ class OneLogin_Saml2_IdPMetadataParser
2727 * metadata contains more than one
2828 * IDPSSODescriptor, the first is returned
2929 * @param string $desiredNameIdFormat If available on IdP metadata, use that nameIdFormat
30+ * @param string $desiredSSOBinding Parse specific binding SSO endpoint
31+ * @param string $desiredSLOBinding Parse specific binding SLO endpoint
3032 *
3133 * @return array metadata info in php-saml settings format
3234 */
33- public static function parseRemoteXML ($ url , $ entityId = null , $ desiredNameIdFormat = null )
35+ public static function parseRemoteXML ($ url , $ entityId = null , $ desiredNameIdFormat = null , $ desiredSSOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT , $ desiredSLOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT )
3436 {
3537 $ metadataInfo = array ();
3638
@@ -44,7 +46,7 @@ public static function parseRemoteXML($url, $entityId = null, $desiredNameIdForm
4446
4547 $ xml = curl_exec ($ ch );
4648 if ($ xml !== false ) {
47- $ metadataInfo = self ::parseXML ($ xml , $ entityId );
49+ $ metadataInfo = self ::parseXML ($ xml , $ entityId, $ desiredNameIdFormat , $ desiredSSOBinding , $ desiredSLOBinding );
4850 } else {
4951 throw new Exception (curl_error ($ ch ), curl_errno ($ ch ));
5052 }
@@ -62,17 +64,19 @@ public static function parseRemoteXML($url, $entityId = null, $desiredNameIdForm
6264 * metadata contains more than one
6365 * IDPSSODescriptor, the first is returned
6466 * @param string $desiredNameIdFormat If available on IdP metadata, use that nameIdFormat
67+ * @param string $desiredSSOBinding Parse specific binding SSO endpoint
68+ * @param string $desiredSLOBinding Parse specific binding SLO endpoint
6569 *
6670 * @return array metadata info in php-saml settings format
6771 */
68- public static function parseFileXML ($ filepath , $ entityId = null , $ desiredNameIdFormat = null )
72+ public static function parseFileXML ($ filepath , $ entityId = null , $ desiredNameIdFormat = null , $ desiredSSOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT , $ desiredSLOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT )
6973 {
7074 $ metadataInfo = array ();
7175
7276 try {
7377 if (file_exists ($ filepath )) {
7478 $ data = file_get_contents ($ filepath );
75- $ metadataInfo = self ::parseXML ($ data , $ entityId );
79+ $ metadataInfo = self ::parseXML ($ data , $ entityId, $ desiredNameIdFormat , $ desiredSSOBinding , $ desiredSLOBinding );
7680 }
7781 } catch (Exception $ e ) {
7882 }
@@ -88,11 +92,13 @@ public static function parseFileXML($filepath, $entityId = null, $desiredNameIdF
8892 * metadata contains more than one
8993 * IDPSSODescriptor, the first is returned
9094 * @param string $desiredNameIdFormat If available on IdP metadata, use that nameIdFormat
95+ * @param string $desiredSSOBinding Parse specific binding SSO endpoint
96+ * @param string $desiredSLOBinding Parse specific binding SLO endpoint
9197 *
9298 * @return array metadata info in php-saml settings format
9399 * @throws \Exception
94100 */
95- public static function parseXML ($ xml , $ entityId = null , $ desiredNameIdFormat = null )
101+ public static function parseXML ($ xml , $ entityId = null , $ desiredNameIdFormat = null , $ desiredSSOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT , $ desiredSLOBinding = OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT )
96102 {
97103 $ metadataInfo = array ();
98104
@@ -126,7 +132,7 @@ public static function parseXML($xml, $entityId = null, $desiredNameIdFormat = n
126132 $ metadataInfo ['idp ' ]['entityId ' ] = $ entityId ;
127133 }
128134
129- $ ssoNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleSignOnService[@Binding=" ' .OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT .'"] ' , $ idpDescriptor );
135+ $ ssoNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleSignOnService[@Binding=" ' .$ desiredSSOBinding .'"] ' , $ idpDescriptor );
130136 if ($ ssoNodes ->length < 1 ) {
131137 $ ssoNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleSignOnService ' , $ idpDescriptor );
132138 }
@@ -137,7 +143,7 @@ public static function parseXML($xml, $entityId = null, $desiredNameIdFormat = n
137143 );
138144 }
139145
140- $ sloNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleLogoutService[@Binding=" ' .OneLogin_Saml2_Constants:: BINDING_HTTP_REDIRECT .'"] ' , $ idpDescriptor );
146+ $ sloNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleLogoutService[@Binding=" ' .$ desiredSLOBinding .'"] ' , $ idpDescriptor );
141147 if ($ sloNodes ->length < 1 ) {
142148 $ sloNodes = OneLogin_Saml2_Utils::query ($ dom , './md:SingleLogoutService ' , $ idpDescriptor );
143149 }
@@ -168,7 +174,9 @@ public static function parseXML($xml, $entityId = null, $desiredNameIdFormat = n
168174 }
169175
170176 $ idpCertdata = $ metadataInfo ['idp ' ]['x509certMulti ' ];
171- 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 )) {
177+ if (count ($ idpCertdata ) == 1 and
178+ ((isset ($ idpCertdata ['signing ' ]) and count ($ idpCertdata ['signing ' ]) == 1 ) or (isset ($ idpCertdata ['encryption ' ]) and count ($ idpCertdata ['encryption ' ]) == 1 )) or
179+ ((isset ($ idpCertdata ['signing ' ]) && count ($ idpCertdata ['signing ' ]) == 1 ) && isset ($ idpCertdata ['encryption ' ]) && count ($ idpCertdata ['encryption ' ]) == 1 && strcmp ($ idpCertdata ['signing ' ][0 ], $ idpCertdata ['encryption ' ][0 ]) == 0 )) {
172180 if (isset ($ metadataInfo ['idp ' ]['x509certMulti ' ]['signing ' ][0 ])) {
173181 $ metadataInfo ['idp ' ]['x509cert ' ] = $ metadataInfo ['idp ' ]['x509certMulti ' ]['signing ' ][0 ];
174182 } else {
0 commit comments