View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.wss4j.dom;
21  
22  /**
23   * WSDataRef stores information about decrypted/signed elements
24   *
25   * When a processor decrypts/verifies an element it stores information
26   * about that element in a WSDataRef so this information can
27   * be used for validation.
28   */
29  
30  import java.util.List;
31  
32  import javax.xml.namespace.QName;
33  import org.w3c.dom.Element;
34  
35  public class WSDataRef {
36  
37      /**
38       * wsu:Id of the protected element
39       */
40      private String wsuId;
41  
42      /**
43       * QName of the protected element
44       */
45      private QName name;
46  
47      /**
48       * An xpath expression pointing to the data element
49       */
50      private String xpath;
51  
52      /**
53       * Algorithm used to encrypt/sign the element
54       */
55      private String algorithm;
56  
57      /**
58       * A list of algorithms used to transform the element before digest
59       */
60      private List<String> transformAlgorithms;
61  
62      /**
63       * If this reference represents signed content, this field
64       * represents the digest algorithm applied to the content.
65       */
66      private String digestAlgorithm;
67  
68      /**
69       * If this reference represents signed content, this field
70       * represents the digest bytes obtained after applying the digestAlgorithm
71       */
72      private byte[] digestValue;
73  
74      private boolean content;
75  
76      /**
77       * The protected DOM element
78       */
79      private Element protectedElement;
80  
81      /**
82       * Whether the protected Reference is an Attachment or not
83       */
84      private boolean attachment;
85  
86      /**
87       * If this reference represents encrypted content, then this is the EncryptedData Element
88       */
89      private Element encryptedElement;
90  
91      /**
92       * @return Id of the protected element
93       */
94      public String getWsuId() {
95          return wsuId;
96      }
97  
98      /**
99       * @param wsuId Id of the protected element
100      */
101     public void setWsuId(String wsuId) {
102         this.wsuId = wsuId;
103     }
104 
105     /**
106      * @return QName of the protected element
107      */
108     public QName getName() {
109         return name;
110     }
111 
112     /**
113      * @param name QName of the protected element
114      */
115     public void setName(QName name) {
116         this.name = name;
117     }
118 
119     /**
120      * @param element The protected DOM element to set
121      */
122     public void setProtectedElement(Element element) {
123         protectedElement = element;
124         String prefix = element.getPrefix();
125         if (prefix == null) {
126             name =
127                 new QName(
128                     element.getNamespaceURI(), element.getLocalName()
129                 );
130         } else {
131             name =
132                 new QName(
133                     element.getNamespaceURI(), element.getLocalName(), prefix
134                 );
135         }
136     }
137 
138     /**
139      * @return the protected DOM element
140      */
141     public Element getProtectedElement() {
142         return protectedElement;
143     }
144 
145     /**
146      * @return the xpath
147      */
148     public String getXpath() {
149         return xpath;
150     }
151 
152     /**
153      * @param xpath the xpath to set
154      */
155     public void setXpath(String xpath) {
156         this.xpath = xpath;
157     }
158 
159     /**
160      * @return the content
161      */
162     public boolean isContent() {
163         return content;
164     }
165 
166     /**
167      * @param content the content to set
168      */
169     public void setContent(boolean content) {
170         this.content = content;
171     }
172 
173     /**
174      * @return the algorithm used for encryption/signature
175      */
176     public String getAlgorithm() {
177         return algorithm;
178     }
179 
180     /**
181      * @param algo algorithm used for encryption
182      */
183     public void setAlgorithm(String algo) {
184         algorithm = algo;
185     }
186 
187     /**
188      * @return if this reference represents signed content,
189      * the digest algorithm applied to the content.
190      */
191     public String getDigestAlgorithm() {
192         return this.digestAlgorithm;
193     }
194 
195     /**
196      * @param digestAlgorithm if this reference represents
197      * signed content, the digest algorithm applied to the content.
198      */
199     public void setDigestAlgorithm(String digestAlgorithm) {
200         this.digestAlgorithm = digestAlgorithm;
201     }
202 
203     /**
204      * Set the Transform algorithm URIs used to transform the element before digest
205      */
206     public void setTransformAlgorithms(List<String> transformAlgorithms) {
207         this.transformAlgorithms = transformAlgorithms;
208     }
209 
210     /**
211      * Get the Transform algorithm URIs used to transform the element before digest
212      */
213     public List<String> getTransformAlgorithms() {
214         return transformAlgorithms;
215     }
216 
217     public boolean isAttachment() {
218         return attachment;
219     }
220 
221     public void setAttachment(boolean attachment) {
222         this.attachment = attachment;
223     }
224 
225     public byte[] getDigestValue() {
226         return digestValue;
227     }
228 
229     public void setDigestValue(byte[] digestValue) {
230         this.digestValue = digestValue;
231     }
232 
233     public Element getEncryptedElement() {
234         return encryptedElement;
235     }
236 
237     public void setEncryptedElement(Element encryptedElement) {
238         this.encryptedElement = encryptedElement;
239     }
240 }