author | avstepan |
Fri, 31 Jul 2015 15:07:18 +0300 | |
changeset 32003 | acb12269398a |
parent 27747 | 3a271dc8b758 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1337 | 2 |
* reserved comment block |
3 |
* DO NOT REMOVE OR ALTER! |
|
2 | 4 |
*/ |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
5 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
7 |
* or more contributor license agreements. See the NOTICE file |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
8 |
* distributed with this work for additional information |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
9 |
* regarding copyright ownership. The ASF licenses this file |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
10 |
* to you under the Apache License, Version 2.0 (the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
11 |
* "License"); you may not use this file except in compliance |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
12 |
* with the License. You may obtain a copy of the License at |
1337 | 13 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
1337 | 15 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
16 |
* Unless required by applicable law or agreed to in writing, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
17 |
* software distributed under the License is distributed on an |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
19 |
* KIND, either express or implied. See the License for the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
20 |
* specific language governing permissions and limitations |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
21 |
* under the License. |
1337 | 22 |
*/ |
23 |
/* |
|
24970
094bfaa699c3
8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents:
23010
diff
changeset
|
24 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
1337 | 25 |
*/ |
26 |
/* |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
27 |
* $Id: DOMSignatureProperties.java 1333415 2012-05-03 12:03:51Z coheigea $ |
2 | 28 |
*/ |
29 |
package org.jcp.xml.dsig.internal.dom; |
|
30 |
||
31 |
import javax.xml.crypto.*; |
|
32 |
import javax.xml.crypto.dom.DOMCryptoContext; |
|
33 |
import javax.xml.crypto.dsig.*; |
|
34 |
||
35 |
import java.util.*; |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
36 |
|
18240 | 37 |
import org.w3c.dom.Attr; |
2 | 38 |
import org.w3c.dom.Document; |
39 |
import org.w3c.dom.Element; |
|
40 |
import org.w3c.dom.Node; |
|
41 |
import org.w3c.dom.NodeList; |
|
42 |
||
43 |
/** |
|
44 |
* DOM-based implementation of SignatureProperties. |
|
45 |
* |
|
46 |
* @author Sean Mullan |
|
47 |
*/ |
|
48 |
public final class DOMSignatureProperties extends DOMStructure |
|
49 |
implements SignatureProperties { |
|
50 |
||
51 |
private final String id; |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
52 |
private final List<SignatureProperty> properties; |
2 | 53 |
|
54 |
/** |
|
55 |
* Creates a <code>DOMSignatureProperties</code> from the specified |
|
56 |
* parameters. |
|
57 |
* |
|
58 |
* @param properties a list of one or more {@link SignatureProperty}s. The |
|
59 |
* list is defensively copied to protect against subsequent modification. |
|
60 |
* @param id the Id (may be <code>null</code>) |
|
61 |
* @throws ClassCastException if <code>properties</code> contains any |
|
62 |
* entries that are not of type {@link SignatureProperty} |
|
63 |
* @throws IllegalArgumentException if <code>properties</code> is empty |
|
64 |
* @throws NullPointerException if <code>properties</code> |
|
65 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
66 |
public DOMSignatureProperties(List<? extends SignatureProperty> properties, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
67 |
String id) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
68 |
{ |
2 | 69 |
if (properties == null) { |
70 |
throw new NullPointerException("properties cannot be null"); |
|
27747 | 71 |
} |
72 |
List<SignatureProperty> tempList = |
|
73 |
Collections.checkedList(new ArrayList<SignatureProperty>(), |
|
74 |
SignatureProperty.class); |
|
75 |
tempList.addAll(properties); |
|
76 |
if (tempList.isEmpty()) { |
|
2 | 77 |
throw new IllegalArgumentException("properties cannot be empty"); |
78 |
} |
|
27747 | 79 |
this.properties = Collections.unmodifiableList(tempList); |
2 | 80 |
this.id = id; |
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Creates a <code>DOMSignatureProperties</code> from an element. |
|
85 |
* |
|
86 |
* @param propsElem a SignatureProperties element |
|
87 |
* @throws MarshalException if a marshalling error occurs |
|
88 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
89 |
public DOMSignatureProperties(Element propsElem, XMLCryptoContext context) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
90 |
throws MarshalException |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
91 |
{ |
2 | 92 |
// unmarshal attributes |
18240 | 93 |
Attr attr = propsElem.getAttributeNodeNS(null, "Id"); |
94 |
if (attr != null) { |
|
95 |
id = attr.getValue(); |
|
96 |
propsElem.setIdAttributeNode(attr, true); |
|
97 |
} else { |
|
98 |
id = null; |
|
99 |
} |
|
2 | 100 |
|
101 |
NodeList nodes = propsElem.getChildNodes(); |
|
102 |
int length = nodes.getLength(); |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
103 |
List<SignatureProperty> properties = |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
104 |
new ArrayList<SignatureProperty>(length); |
2 | 105 |
for (int i = 0; i < length; i++) { |
106 |
Node child = nodes.item(i); |
|
107 |
if (child.getNodeType() == Node.ELEMENT_NODE) { |
|
19051
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
108 |
String name = child.getLocalName(); |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
109 |
if (!name.equals("SignatureProperty")) { |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
110 |
throw new MarshalException("Invalid element name: " + name + |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
111 |
", expected SignatureProperty"); |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
112 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
113 |
properties.add(new DOMSignatureProperty((Element)child, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
114 |
context)); |
2 | 115 |
} |
116 |
} |
|
117 |
if (properties.isEmpty()) { |
|
118 |
throw new MarshalException("properties cannot be empty"); |
|
119 |
} else { |
|
120 |
this.properties = Collections.unmodifiableList(properties); |
|
121 |
} |
|
122 |
} |
|
123 |
||
24970
094bfaa699c3
8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents:
23010
diff
changeset
|
124 |
public List<SignatureProperty> getProperties() { |
2 | 125 |
return properties; |
126 |
} |
|
127 |
||
128 |
public String getId() { |
|
129 |
return id; |
|
130 |
} |
|
131 |
||
132 |
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
133 |
throws MarshalException |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
134 |
{ |
2 | 135 |
Document ownerDoc = DOMUtils.getOwnerDocument(parent); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
136 |
Element propsElem = DOMUtils.createElement(ownerDoc, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
137 |
"SignatureProperties", |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
138 |
XMLSignature.XMLNS, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
139 |
dsPrefix); |
2 | 140 |
|
141 |
// set attributes |
|
142 |
DOMUtils.setAttributeID(propsElem, "Id", id); |
|
143 |
||
144 |
// create and append any properties |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
145 |
for (SignatureProperty property : properties) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
146 |
((DOMSignatureProperty)property).marshal(propsElem, dsPrefix, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
147 |
context); |
2 | 148 |
} |
149 |
||
150 |
parent.appendChild(propsElem); |
|
151 |
} |
|
152 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
153 |
@Override |
2 | 154 |
public boolean equals(Object o) { |
155 |
if (this == o) { |
|
156 |
return true; |
|
157 |
} |
|
158 |
||
159 |
if (!(o instanceof SignatureProperties)) { |
|
160 |
return false; |
|
161 |
} |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
162 |
SignatureProperties osp = (SignatureProperties)o; |
2 | 163 |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
164 |
boolean idsEqual = (id == null ? osp.getId() == null |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
165 |
: id.equals(osp.getId())); |
2 | 166 |
|
167 |
return (properties.equals(osp.getProperties()) && idsEqual); |
|
168 |
} |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
169 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
170 |
@Override |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
171 |
public int hashCode() { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
172 |
int result = 17; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
173 |
if (id != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
174 |
result = 31 * result + id.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
175 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
176 |
result = 31 * result + properties.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
177 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
178 |
return result; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
179 |
} |
2 | 180 |
} |