001: /*
002: * $Id: EncryptionTarget.java,v 1.4 2007/01/08 09:28:46 ashutoshshahi Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025: */
026:
027: package com.sun.xml.wss.impl.policy.mls;
028:
029: import java.security.spec.AlgorithmParameterSpec;
030: import java.util.Iterator;
031: import java.util.ArrayList;
032:
033: import org.w3c.dom.Element;
034:
035: /**
036: * Objects of this class represent an Encryption Target that can be part of
037: * the FeatureBinding for an EncryptionPolicy (refer EncryptionPolicy.FeatureBinding).
038: */
039: public class EncryptionTarget extends Target implements Cloneable {
040:
041: String _dataEncryptionAlgorithm = ""; // Rf. MessageConstants
042:
043: ArrayList _cipherReferenceTransforms = new ArrayList();
044:
045: Element drefData = null;
046: private boolean isOptimized = false;
047:
048: /**
049: * Default constructor
050: */
051: public EncryptionTarget() {
052: }
053:
054: /**
055: * Constructor that takes a Target
056: */
057: public EncryptionTarget(Target target) {
058: this .setEnforce(target.getEnforce());
059: this .setType(target.getType());
060: this .setValue(target.getValue());
061: this .setContentOnly(target.getContentOnly());
062: }
063:
064: /**
065: * Constructor
066: * @param algorithm Data Encryption Algorithm
067: */
068: public EncryptionTarget(String algorithm) {
069: this ._dataEncryptionAlgorithm = algorithm;
070: }
071:
072: /**
073: * Constructor
074: * @param algorithm Data Encryption Algorithm
075: * @param transform Cipher Reference Transform
076: */
077: public EncryptionTarget(String algorithm, String transform) {
078: this ._dataEncryptionAlgorithm = algorithm;
079: this ._cipherReferenceTransforms.add(new Transform(transform));
080: }
081:
082: /**
083: * set the DataEncryptionAlgorithm
084: * @param algorithm Data Encryption Algorithm
085: */
086: public void setDataEncryptionAlgorithm(String algorithm) {
087: this ._dataEncryptionAlgorithm = algorithm;
088: }
089:
090: /**
091: * @return Data Encryption Algorithm
092: */
093: public String getDataEncryptionAlgorithm() {
094: return this ._dataEncryptionAlgorithm;
095: }
096:
097: /**
098: * add a CipherReference Transform
099: * @param transform Cipher Reference Transform
100: */
101: public void addCipherReferenceTransform(String transform) {
102: this ._cipherReferenceTransforms.add(new Transform(transform));
103: }
104:
105: /**
106: * add a CipherReference Transform
107: * @param transform CipherReference Transform
108: */
109: public void addCipherReferenceTransform(Transform transform) {
110: this ._cipherReferenceTransforms.add(transform);
111: }
112:
113: /**
114: * @return Collection of CipherReference Transforms
115: */
116: public ArrayList getCipherReferenceTransforms() {
117: return _cipherReferenceTransforms;
118: }
119:
120: /**
121: * @return a new instance of Encryption Transform
122: */
123: public Transform newEncryptionTransform() {
124: return new Transform();
125: }
126:
127: /**
128: * Equals operator
129: * @param target EncryptionTarget
130: * @return true if the target argument is equal to this Target
131: */
132: public boolean equals(EncryptionTarget target) {
133: boolean b1 = _dataEncryptionAlgorithm.equals("") ? true
134: : _dataEncryptionAlgorithm.equals(target
135: .getDataEncryptionAlgorithm());
136:
137: boolean b2 = _cipherReferenceTransforms.equals(target
138: .getCipherReferenceTransforms());
139:
140: return b1 && b2;
141: }
142:
143: /**
144: * clone operator
145: * @return a clone of this EncryptionTarget
146: */
147: public Object clone() {
148: EncryptionTarget target = new EncryptionTarget();
149:
150: try {
151: target.setDataEncryptionAlgorithm(_dataEncryptionAlgorithm);
152: target.setValue(this .getValue());
153: target.setType(this .getType());
154: target.setContentOnly(this .getContentOnly());
155: target.setEnforce(this .getEnforce());
156:
157: Iterator i = getCipherReferenceTransforms().iterator();
158: while (i.hasNext()) {
159: Transform transform = (Transform) i.next();
160: target.getCipherReferenceTransforms().add(
161: transform.clone());
162: }
163: } catch (Exception e) {
164: }
165:
166: return target;
167: }
168:
169: public void setElementData(Element data) {
170: this .drefData = data;
171: }
172:
173: public Element getElementData() {
174: return this .drefData;
175: }
176:
177: /**
178: * This class represents a Transform that can appear on an EcncryptionTarget,
179: * Instances of this class are added as CipherReference Transforms on an EcncryptionTarget
180: */
181: public static class Transform implements Cloneable {
182:
183: String _transform = "";
184:
185: AlgorithmParameterSpec _algorithmParameters = null;
186:
187: /**
188: *Default constructor
189: */
190: public Transform() {
191: }
192:
193: /**
194: * Constructor
195: * @param algorithm the URI for the transform alogrithm
196: */
197: public Transform(String algorithm) {
198: this ._transform = algorithm;
199: }
200:
201: /**
202: * @return the algorithm parameters
203: */
204: public AlgorithmParameterSpec getAlgorithmParameters() {
205: return this ._algorithmParameters;
206: }
207:
208: /**
209: * set any parameters for the Transform Algorithm
210: * @param params a HashMap of AlgorithmParameters
211: */
212: public void setAlgorithmParameters(AlgorithmParameterSpec params) {
213: this ._algorithmParameters = params;
214: }
215:
216: /**
217: * set the Transform Algorithm
218: * @param algorithm the Algorithm for the Transform
219: */
220: public void setTransform(String algorithm) {
221: this ._transform = algorithm;
222: }
223:
224: /**
225: * @return algorithm the transform algorithm
226: */
227: public String getTransform() {
228: return this ._transform;
229: }
230:
231: /**
232: * equals operator
233: * @param transform the transform to be compared for equality
234: * @return true if the argument transform is equal to this transform
235: */
236: public boolean equals(Transform transform) {
237: boolean b1 = _transform.equals("") ? true : _transform
238: .equals(transform.getTransform());
239: if (!b1)
240: return false;
241:
242: boolean b2 = _algorithmParameters.equals(transform
243: .getAlgorithmParameters());
244: if (!b2)
245: return false;
246:
247: return true;
248: }
249:
250: /**
251: * clone operator
252: * @return a clone of this Transform
253: */
254: public Object clone() {
255: Transform transform = new Transform(_transform);
256: transform.setAlgorithmParameters(_algorithmParameters);
257: return transform;
258: }
259: }
260:
261: public boolean isIsOptimized() {
262: return isOptimized;
263: }
264: }
|