jdk/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXMLSignature.java
changeset 27747 3a271dc8b758
parent 25859 3317bb8137f4
equal deleted inserted replaced
27736:8c9bd4be4a86 27747:3a271dc8b758
   107             throw new NullPointerException("signedInfo cannot be null");
   107             throw new NullPointerException("signedInfo cannot be null");
   108         }
   108         }
   109         this.si = si;
   109         this.si = si;
   110         this.id = id;
   110         this.id = id;
   111         this.sv = new DOMSignatureValue(signatureValueId);
   111         this.sv = new DOMSignatureValue(signatureValueId);
   112         if (objs == null) {
   112         List<XMLObject> tempList =
   113             this.objects = Collections.emptyList();
   113             Collections.checkedList(new ArrayList<XMLObject>(),
   114         } else {
   114                                     XMLObject.class);
   115             this.objects =
   115         if (objs != null) {
   116                 Collections.unmodifiableList(new ArrayList<XMLObject>(objs));
   116             tempList.addAll(objs);
   117             for (int i = 0, size = this.objects.size(); i < size; i++) {
   117         }
   118                 if (!(this.objects.get(i) instanceof XMLObject)) {
   118         this.objects = Collections.unmodifiableList(tempList);
   119                     throw new ClassCastException
       
   120                         ("objs["+i+"] is not an XMLObject");
       
   121                 }
       
   122             }
       
   123         }
       
   124         this.ki = ki;
   119         this.ki = ki;
   125     }
   120     }
   126 
   121 
   127     /**
   122     /**
   128      * Creates a <code>DOMXMLSignature</code> from XML.
   123      * Creates a <code>DOMXMLSignature</code> from XML.
   268             validated = true;
   263             validated = true;
   269             return validationStatus;
   264             return validationStatus;
   270         }
   265         }
   271 
   266 
   272         // validate all References
   267         // validate all References
   273         @SuppressWarnings("unchecked")
       
   274         List<Reference> refs = this.si.getReferences();
   268         List<Reference> refs = this.si.getReferences();
   275         boolean validateRefs = true;
   269         boolean validateRefs = true;
   276         for (int i = 0, size = refs.size(); validateRefs && i < size; i++) {
   270         for (int i = 0, size = refs.size(); validateRefs && i < size; i++) {
   277             Reference ref = refs.get(i);
   271             Reference ref = refs.get(i);
   278             boolean refValid = ref.validate(vc);
   272             boolean refValid = ref.validate(vc);
   295         if (Boolean.TRUE.equals(vc.getProperty
   289         if (Boolean.TRUE.equals(vc.getProperty
   296                                 ("org.jcp.xml.dsig.validateManifests")))
   290                                 ("org.jcp.xml.dsig.validateManifests")))
   297         {
   291         {
   298             for (int i=0, size=objects.size(); validateMans && i < size; i++) {
   292             for (int i=0, size=objects.size(); validateMans && i < size; i++) {
   299                 XMLObject xo = objects.get(i);
   293                 XMLObject xo = objects.get(i);
   300                 @SuppressWarnings("unchecked")
       
   301                 List<XMLStructure> content = xo.getContent();
   294                 List<XMLStructure> content = xo.getContent();
   302                 int csize = content.size();
   295                 int csize = content.size();
   303                 for (int j = 0; validateMans && j < csize; j++) {
   296                 for (int j = 0; validateMans && j < csize; j++) {
   304                     XMLStructure xs = content.get(j);
   297                     XMLStructure xs = content.get(j);
   305                     if (xs instanceof Manifest) {
   298                     if (xs instanceof Manifest) {
   306                         if (log.isLoggable(java.util.logging.Level.FINE)) {
   299                         if (log.isLoggable(java.util.logging.Level.FINE)) {
   307                             log.log(java.util.logging.Level.FINE, "validating manifest");
   300                             log.log(java.util.logging.Level.FINE, "validating manifest");
   308                         }
   301                         }
   309                         Manifest man = (Manifest)xs;
   302                         Manifest man = (Manifest)xs;
   310                         @SuppressWarnings("unchecked")
       
   311                         List<Reference> manRefs = man.getReferences();
   303                         List<Reference> manRefs = man.getReferences();
   312                         int rsize = manRefs.size();
   304                         int rsize = manRefs.size();
   313                         for (int k = 0; validateMans && k < rsize; k++) {
   305                         for (int k = 0; validateMans && k < rsize; k++) {
   314                             Reference ref = manRefs.get(k);
   306                             Reference ref = manRefs.get(k);
   315                             boolean refValid = ref.validate(vc);
   307                             boolean refValid = ref.validate(vc);
   346         // traverse the Signature and register all objects with IDs that
   338         // traverse the Signature and register all objects with IDs that
   347         // may contain References
   339         // may contain References
   348         signatureIdMap = new HashMap<String, XMLStructure>();
   340         signatureIdMap = new HashMap<String, XMLStructure>();
   349         signatureIdMap.put(id, this);
   341         signatureIdMap.put(id, this);
   350         signatureIdMap.put(si.getId(), si);
   342         signatureIdMap.put(si.getId(), si);
   351         @SuppressWarnings("unchecked")
       
   352         List<Reference> refs = si.getReferences();
   343         List<Reference> refs = si.getReferences();
   353         for (Reference ref : refs) {
   344         for (Reference ref : refs) {
   354             signatureIdMap.put(ref.getId(), ref);
   345             signatureIdMap.put(ref.getId(), ref);
   355         }
   346         }
   356         for (XMLObject obj : objects) {
   347         for (XMLObject obj : objects) {
   357             signatureIdMap.put(obj.getId(), obj);
   348             signatureIdMap.put(obj.getId(), obj);
   358             @SuppressWarnings("unchecked")
       
   359             List<XMLStructure> content = obj.getContent();
   349             List<XMLStructure> content = obj.getContent();
   360             for (XMLStructure xs : content) {
   350             for (XMLStructure xs : content) {
   361                 if (xs instanceof Manifest) {
   351                 if (xs instanceof Manifest) {
   362                     Manifest man = (Manifest)xs;
   352                     Manifest man = (Manifest)xs;
   363                     signatureIdMap.put(man.getId(), man);
   353                     signatureIdMap.put(man.getId(), man);
   364                     @SuppressWarnings("unchecked")
       
   365                     List<Reference> manRefs = man.getReferences();
   354                     List<Reference> manRefs = man.getReferences();
   366                     for (Reference ref : manRefs) {
   355                     for (Reference ref : manRefs) {
   367                         allReferences.add(ref);
   356                         allReferences.add(ref);
   368                         signatureIdMap.put(ref.getId(), ref);
   357                         signatureIdMap.put(ref.getId(), ref);
   369                     }
   358                     }
   481             }
   470             }
   482             // if uri="" and there are XPath Transforms, there may be
   471             // if uri="" and there are XPath Transforms, there may be
   483             // reference dependencies in the XPath Transform - so be on
   472             // reference dependencies in the XPath Transform - so be on
   484             // the safe side, and skip and do at end in the final sweep
   473             // the safe side, and skip and do at end in the final sweep
   485             if (uri.length() == 0) {
   474             if (uri.length() == 0) {
   486                 @SuppressWarnings("unchecked")
       
   487                 List<Transform> transforms = ref.getTransforms();
   475                 List<Transform> transforms = ref.getTransforms();
   488                 for (Transform transform : transforms) {
   476                 for (Transform transform : transforms) {
   489                     String transformAlg = transform.getAlgorithm();
   477                     String transformAlg = transform.getAlgorithm();
   490                     if (transformAlg.equals(Transform.XPATH) ||
   478                     if (transformAlg.equals(Transform.XPATH) ||
   491                         transformAlg.equals(Transform.XPATH2)) {
   479                         transformAlg.equals(Transform.XPATH2)) {