19
19
20
20
import org .picketlink .common .PicketLinkLogger ;
21
21
import org .picketlink .common .PicketLinkLoggerFactory ;
22
+ import org .picketlink .common .constants .JBossSAMLConstants ;
22
23
import org .picketlink .common .constants .JBossSAMLURIConstants ;
23
24
import org .picketlink .common .constants .WSTrustConstants ;
24
25
import org .picketlink .common .exceptions .ParsingException ;
@@ -500,9 +501,18 @@ public static boolean validate(Document signedDoc, Key publicKey) throws Marshal
500
501
501
502
if (publicKey == null )
502
503
throw logger .nullValueError ("Public Key" );
503
-
504
+ int signedAssertions = 0 ;
505
+ String assertionNameSpaceUri = null ;
504
506
for (int i = 0 ; i < nl .getLength (); i ++) {
505
- DOMValidateContext valContext = new DOMValidateContext (publicKey , nl .item (i ));
507
+ Node signatureNode = nl .item (i );
508
+ Node parent = signatureNode .getParentNode ();
509
+ if (parent != null && JBossSAMLConstants .ASSERTION .get ().equals (parent .getLocalName ())) {
510
+ ++signedAssertions ;
511
+ if (assertionNameSpaceUri == null ) {
512
+ assertionNameSpaceUri = parent .getNamespaceURI ();
513
+ }
514
+ }
515
+ DOMValidateContext valContext = new DOMValidateContext (publicKey , signatureNode );
506
516
XMLSignature signature = fac .unmarshalXMLSignature (valContext );
507
517
508
518
boolean coreValidity = signature .validate (valContext );
@@ -521,7 +531,11 @@ public static boolean validate(Document signedDoc, Key publicKey) throws Marshal
521
531
return false ;
522
532
}
523
533
}
524
-
534
+ NodeList assertions = signedDoc .getElementsByTagNameNS (assertionNameSpaceUri , JBossSAMLConstants .ASSERTION .get ());
535
+ if (signedAssertions > 0 && assertions != null && assertions .getLength () != signedAssertions ) {
536
+ // there are unsigned assertions mixed with signed ones
537
+ return false ;
538
+ }
525
539
return true ;
526
540
}
527
541
0 commit comments