@@ -272,7 +272,10 @@ public function isValid($requestId = null)
272272
273273 // Check destination
274274 if ($ this ->document ->documentElement ->hasAttribute ('Destination ' )) {
275- $ destination = trim ($ this ->document ->documentElement ->getAttribute ('Destination ' ));
275+ $ destination = $ this ->document ->documentElement ->getAttribute ('Destination ' );
276+ if (isset ($ destination )) {
277+ $ destination = trim ($ destination );
278+ }
276279 if (empty ($ destination )) {
277280 if (!$ security ['relaxDestinationValidation ' ]) {
278281 throw new ValidationError (
@@ -298,25 +301,24 @@ public function isValid($requestId = null)
298301 // Check audience
299302 $ validAudiences = $ this ->getAudiences ();
300303 if (!empty ($ validAudiences ) && !in_array ($ spEntityId , $ validAudiences , true )) {
304+ $ validAudiencesStr = implode (', ' , $ validAudiences );
301305 throw new ValidationError (
302- sprintf (
303- "Invalid audience for this Response (expected '%s', got '%s') " ,
304- $ spEntityId ,
305- implode (', ' , $ validAudiences )
306- ),
306+ "Invalid audience for this Response (expected ' " .$ spEntityId ."', got ' " .$ validAudiencesStr ."') " ,
307307 ValidationError::WRONG_AUDIENCE
308308 );
309309 }
310310
311311 // Check the issuers
312312 $ issuers = $ this ->getIssuers ();
313313 foreach ($ issuers as $ issuer ) {
314- $ trimmedIssuer = trim ($ issuer );
315- if (empty ($ trimmedIssuer ) || $ trimmedIssuer !== $ idPEntityId ) {
316- throw new ValidationError (
317- "Invalid issuer in the Assertion/Response (expected ' $ idPEntityId', got ' $ trimmedIssuer') " ,
318- ValidationError::WRONG_ISSUER
319- );
314+ if (isset ($ issuer )) {
315+ $ trimmedIssuer = trim ($ issuer );
316+ if (empty ($ trimmedIssuer ) || $ trimmedIssuer !== $ idPEntityId ) {
317+ throw new ValidationError (
318+ "Invalid issuer in the Assertion/Response (expected ' " .$ idPEntityId ."', got ' " .$ trimmedIssuer ."') " ,
319+ ValidationError::WRONG_ISSUER
320+ );
321+ }
320322 }
321323 }
322324
@@ -546,7 +548,10 @@ public function getAudiences()
546548
547549 $ entries = $ this ->_queryAssertion ('/saml:Conditions/saml:AudienceRestriction/saml:Audience ' );
548550 foreach ($ entries as $ entry ) {
549- $ value = trim ($ entry ->textContent );
551+ $ value = $ entry ->textContent ;
552+ if (isset ($ value )) {
553+ $ value = trim ($ value );
554+ }
550555 if (!empty ($ value )) {
551556 $ audiences [] = $ value ;
552557 }
@@ -651,7 +656,7 @@ public function getNameIdData()
651656 $ spEntityId = $ spData ['entityId ' ];
652657 if ($ spEntityId != $ nameId ->getAttribute ($ attr )) {
653658 throw new ValidationError (
654- "The SPNameQualifier value mistmatch the SP entityID value. " ,
659+ "The SPNameQualifier value mismatch the SP entityID value. " ,
655660 ValidationError::SP_NAME_QUALIFIER_NAME_MISMATCH
656661 );
657662 }
@@ -1261,13 +1266,19 @@ public function getErrorException()
12611266 /**
12621267 * After execute a validation process, if fails this method returns the cause
12631268 *
1269+ * @param bool $escape Apply or not htmlentities to the message.
1270+ *
12641271 * @return null|string Error reason
12651272 */
1266- public function getError ()
1273+ public function getError ($ escape = true )
12671274 {
12681275 $ errorMsg = null ;
12691276 if (isset ($ this ->_error )) {
1270- $ errorMsg = htmlentities ($ this ->_error ->getMessage ());
1277+ if ($ escape ) {
1278+ $ errorMsg = htmlentities ($ this ->_error ->getMessage ());
1279+ } else {
1280+ $ errorMsg = $ this ->_error ->getMessage ();
1281+ }
12711282 }
12721283 return $ errorMsg ;
12731284 }
0 commit comments