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.common;
21  
22  import org.w3c.dom.Element;
23  
24  
25  public class WSEncryptionPart {
26  
27      private String name;
28      private String namespace;
29      private String encModifier;
30      private String encId;
31      private String id;
32      private Element element;
33      private boolean required = true;
34  
35      /**
36       * An xpath expression pointing to the data element
37       * that may be specified in case the encryption part is of type
38       * <code>org.apache.wss4j.dom.WSConstants.PART_TYPE_ELEMENT</code>
39       */
40      private String xpath;
41  
42      /**
43       * Constructor to initialize part structure with element, namespace, and modifier.
44       *
45       * This constructor initializes the parts structure to lookup for a
46       * fully qualified name of an element to encrypt or sign. The modifier
47       * controls how encryption encrypts the element, signature processing does
48       * not use the modifier information.
49       *
50       * <p/>
51       *
52       * Regarding the modifier ("Content" or "Element") refer to the W3C
53       * XML Encryption specification.
54       *
55       * @param nm Element's name
56       * @param nmspace Element's namespace
57       * @param encMod The encryption modifier
58       */
59      public WSEncryptionPart(String nm, String nmspace, String encMod) {
60          name = nm;
61          namespace = nmspace;
62          encModifier = encMod;
63          id = null;
64      }
65  
66      /**
67       * Constructor to initialize part structure with element id.
68       *
69       * This constructor initializes the parts structure to lookup for a
70       * an element with the given Id to encrypt or sign.
71       *
72       * @param id The Id to of the element to process
73       */
74      public WSEncryptionPart(String id) {
75          this.id = id;
76          name = namespace = encModifier = null;
77      }
78  
79      /**
80       * Constructor to initialize part structure with element id and modifier.
81       *
82       * This constructor initializes the parts structure to lookup for a
83       * an element with the given Id to encrypt or sign. The modifier
84       * controls how encryption encrypts the element, signature processing does
85       * not use the modifier information.
86       *
87       * <p/>
88       *
89       * Regarding the modifier ("Content" or "Element") refer to the W3C
90       * XML Encryption specification.
91       *
92       * @param id The Id to of the element to process
93       * @param encMod The encryption modifier
94       */
95      public WSEncryptionPart(String id, String encMod) {
96          this.id = id;
97          encModifier = encMod;
98          name = namespace = null;
99      }
100 
101     /**
102      * @return the local name of the element to encrypt.
103      */
104     public String getName() {
105         return name;
106     }
107 
108     /**
109      * @return the namespace of the element to encrypt
110      */
111     public String getNamespace() {
112         return namespace;
113     }
114 
115     /**
116      * @return the encryption modifier
117      */
118     public String getEncModifier() {
119         return encModifier;
120     }
121 
122     /**
123      * Set the encryption modifier
124      */
125     public void setEncModifier(String encModifier) {
126         this.encModifier = encModifier;
127     }
128 
129     /**
130      * @return Returns the id.
131      */
132     public String getId() {
133         return id;
134     }
135 
136     /**
137      * Set the id
138      * @param id
139      */
140     public void setId(String id) {
141         this.id = id;
142     }
143 
144     public void setEncId(String id) {
145         encId = id;
146     }
147 
148     public String getEncId() {
149         return encId;
150     }
151 
152     /**
153      * @return the xpath
154      */
155     public String getXpath() {
156         return xpath;
157     }
158 
159     /**
160      * @param xpath the xpath to set
161      */
162     public void setXpath(String xpath) {
163         this.xpath = xpath;
164     }
165 
166     /**
167      * Set the DOM Element corresponding to this EncryptionPart
168      * @param element the DOM Element corresponding to this EncryptionPart
169      */
170     public void setElement(Element element) {
171         this.element = element;
172     }
173 
174     /**
175      * Get the DOM Element corresponding to this EncryptionPart
176      * @return the DOM Element corresponding to this EncryptionPart
177      */
178     public Element getElement() {
179         return element;
180     }
181 
182     public boolean isRequired() {
183         return required;
184     }
185 
186     public void setRequired(boolean required) {
187         this.required = required;
188     }
189 
190 }