001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the License). You may not use this file except in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * Header Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022: /*
023: * EncryptedHeaderBlock.java
024: *
025: * Created on October 13, 2006, 4:48 PM
026: *
027: */
028:
029: package com.sun.xml.wss.core;
030:
031: import com.sun.xml.wss.XWSSecurityException;
032: import com.sun.xml.wss.impl.MessageConstants;
033: import com.sun.xml.wss.impl.SecurableSoapMessage;
034: import com.sun.xml.wss.impl.misc.SOAPElementExtension;
035: import com.sun.xml.wss.logging.LogDomainConstants;
036: import java.util.Iterator;
037: import java.util.logging.Level;
038: import java.util.logging.Logger;
039: import javax.xml.soap.Name;
040: import javax.xml.soap.SOAPElement;
041: import javax.xml.soap.SOAPException;
042: import javax.xml.soap.SOAPFactory;
043: import org.w3c.dom.Attr;
044: import org.w3c.dom.DOMException;
045: import org.w3c.dom.Document;
046: import org.w3c.dom.Element;
047: import org.w3c.dom.NamedNodeMap;
048: import org.w3c.dom.Node;
049: import org.w3c.dom.NodeList;
050: import org.w3c.dom.TypeInfo;
051: import org.w3c.dom.UserDataHandler;
052:
053: /**
054: *
055: * @author Mayank.Mishra@Sun.com
056: */
057: /**
058: * Corresponds to Schema definition for EncryptedData.
059: * Schema definition for EncryptedData is as follows:
060: * <p>
061: * <xmp>
062: * <element name='EncryptedHeader' type='wsse11:EncryptedHeaderType'/>
063: * <complexType name='EncryptedHeaderType'>
064: * <element name='EncryptedData'>
065: * <complexContent>
066: * <extension base='xenc:EncryptedType'/>
067: * </complexContent>
068: * </element>
069: * </complexType>
070: * </xmp>
071: *
072: * @author Mayank Mishra
073: */
074: public class EncryptedHeaderBlock extends SOAPElementExtension
075: implements SOAPElement {
076:
077: private static Logger log = Logger.getLogger(
078: LogDomainConstants.WSS_API_DOMAIN,
079: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
080:
081: protected SOAPElement delegateElement;
082: private static SOAPFactory soapFactory;
083:
084: private static final Name idAttributeName;
085: //private Document ownerDoc;
086:
087: private boolean bsp = false;
088:
089: static {
090: Name temp = null;
091: try {
092: soapFactory = SOAPFactory.newInstance();
093: temp = getSoapFactory().createName("Id", "wsu",
094: "http://schemas.xmlsoap.org/ws/2003/06/utility");
095: } catch (SOAPException e) {
096: log.log(Level.SEVERE, "WSS0654.soap.exception", e
097: .getMessage());
098: }
099:
100: idAttributeName = temp;
101: }
102:
103: public EncryptedHeaderBlock(Document doc)
104: throws XWSSecurityException {
105: try {
106: setSOAPElement((SOAPElement) doc.createElementNS(
107: MessageConstants.WSSE11_NS,
108: MessageConstants.ENCRYPTED_HEADER_QNAME));
109: addNamespaceDeclaration(MessageConstants.WSSE11_PREFIX,
110: MessageConstants.WSSE11_NS);
111: } catch (SOAPException e) {
112: log.log(Level.SEVERE, "WSS0360.error.creating.ehb", e
113: .getMessage());
114: throw new XWSSecurityException(e);
115: }
116: //ownerDoc = doc;
117: }
118:
119: /** Creates a new instance of EncryptedHeaderBlock */
120: public EncryptedHeaderBlock(SOAPElement delegateElement)
121: throws XWSSecurityException {
122: setSOAPElement(delegateElement);
123: try {
124: setSOAPElement(getSoapFactory().createElement(
125: "EncryptedHeader", MessageConstants.WSSE11_PREFIX,
126: MessageConstants.WSSE11_NS));
127: addNamespaceDeclaration(MessageConstants.WSSE11_PREFIX,
128: MessageConstants.WSSE11_NS);
129:
130: } catch (SOAPException e) {
131: log.log(Level.SEVERE, "WSS0360.error.creating.ehb", e
132: .getMessage());
133: throw new XWSSecurityException(e);
134: }
135: //ownerDoc = delegateElement.getOwnerDocument();
136: }
137:
138: protected void setSOAPElement(SOAPElement delegateElement) {
139: this .delegateElement = delegateElement;
140: }
141:
142: public void copyAttributes(final SecurableSoapMessage secureMsg,
143: final SecurityHeader _secHeader)
144: throws XWSSecurityException {
145:
146: String SOAP_namespace = secureMsg.getEnvelope()
147: .getNamespaceURI();
148: String SOAP_prefix = secureMsg.getEnvelope().getPrefix();
149: String value_mustUnderstand = _secHeader.getAttributeNS(
150: SOAP_namespace, "mustUnderstand");
151: String value_S12_role = _secHeader.getAttributeNS(
152: SOAP_namespace, "role");
153: String value_S11_actor = _secHeader.getAttributeNS(
154: SOAP_namespace, "actor");
155: String value_S12_relay = _secHeader.getAttributeNS(
156: SOAP_namespace, "relay");
157:
158: if (value_mustUnderstand != null
159: && !value_mustUnderstand.equals("")) {
160: this .setAttributeNS(SOAP_namespace, SOAP_prefix
161: + ":mustUnderstand", value_mustUnderstand);
162: }
163: if (value_S12_role != null && !value_S12_role.equals("")) {
164: this .setAttributeNS(SOAP_namespace, SOAP_prefix + ":role",
165: value_S12_role);
166: }
167: if (value_S11_actor != null && !value_S11_actor.equals("")) {
168: this .setAttributeNS(SOAP_namespace, SOAP_prefix + ":actor",
169: value_S11_actor);
170: }
171: if (value_S12_relay != null && !value_S12_relay.equals("")) {
172: this .setAttributeNS(SOAP_namespace, SOAP_prefix + ":relay",
173: value_S12_relay);
174: }
175: }
176:
177: protected void setWsuIdAttr(Element element, String wsuId) {
178: element.setAttributeNS(MessageConstants.NAMESPACES_NS, "xmlns:"
179: + MessageConstants.WSU_PREFIX, MessageConstants.WSU_NS);
180: element.setAttributeNS(MessageConstants.WSU_NS,
181: MessageConstants.WSU_ID_QNAME, wsuId);
182: }
183:
184: protected static SOAPFactory getSoapFactory() {
185: return soapFactory;
186: }
187:
188: /**
189: * Returns null if id attr is not present
190: */
191: public String getId() {
192: String id = getAttribute("Id");
193: if (id.equals(""))
194: return null;
195: return id;
196: }
197:
198: public void setId(String id) {
199: setAttribute("Id", id);
200: setIdAttribute("Id", true);
201: }
202:
203: /**
204: * Returns null if Type attr is not present
205: */
206: public String getType() {
207: String type = getAttribute("Type");
208: if (type.equals(""))
209: return null;
210: return type;
211: }
212:
213: public void setType(String type) {
214: setAttribute("Type", type);
215: }
216:
217: /**
218: * Returns null if MimeType attr is not present
219: */
220: public String getMimeType() {
221: String mimeType = getAttribute("MimeType");
222: if (mimeType.equals(""))
223: return null;
224: return mimeType;
225: }
226:
227: public void setMimeType(String mimeType) {
228: setAttribute("MimeType", mimeType);
229: }
230:
231: // public String getId() {
232: // return delegateElement.getAttributeValue(idAttributeName);
233: // }
234: //
235: public SOAPElement getAsSoapElement() throws XWSSecurityException {
236: return delegateElement;
237: }
238:
239: public SOAPElement addChildElement(Name name) throws SOAPException {
240: return delegateElement.addChildElement(name);
241: }
242:
243: public SOAPElement addChildElement(String string)
244: throws SOAPException {
245: return delegateElement.addChildElement(string);
246: }
247:
248: public SOAPElement addChildElement(String string, String string0)
249: throws SOAPException {
250: return delegateElement.addChildElement(string, string0);
251: }
252:
253: public SOAPElement addChildElement(String string, String string0,
254: String string1) throws SOAPException {
255: return delegateElement
256: .addChildElement(string, string0, string1);
257: }
258:
259: public SOAPElement addChildElement(SOAPElement sOAPElement)
260: throws SOAPException {
261: return delegateElement.addChildElement(sOAPElement);
262: }
263:
264: public void removeContents() {
265: delegateElement.removeContents();
266: }
267:
268: public SOAPElement addTextNode(String string) throws SOAPException {
269: return delegateElement.addTextNode(string);
270: }
271:
272: public SOAPElement addAttribute(Name name, String string)
273: throws SOAPException {
274: return delegateElement.addAttribute(name, string);
275: }
276:
277: public SOAPElement addNamespaceDeclaration(String string,
278: String string0) throws SOAPException {
279: return delegateElement.addNamespaceDeclaration(string, string0);
280: }
281:
282: public String getAttributeValue(Name name) {
283: return delegateElement.getAttributeValue(name);
284: }
285:
286: public Iterator getAllAttributes() {
287: return delegateElement.getAllAttributes();
288: }
289:
290: public Iterator getAllAttributesAsQNames() {
291: return delegateElement.getAllAttributesAsQNames();
292: }
293:
294: public String getNamespaceURI(String string) {
295: return delegateElement.getNamespaceURI(string);
296: }
297:
298: public Iterator getNamespacePrefixes() {
299: return delegateElement.getNamespacePrefixes();
300: }
301:
302: public Iterator getVisibleNamespacePrefixes() {
303: return delegateElement.getVisibleNamespacePrefixes();
304: }
305:
306: public Name getElementName() {
307: return delegateElement.getElementName();
308: }
309:
310: public boolean removeAttribute(Name name) {
311: return delegateElement.removeAttribute(name);
312: }
313:
314: public boolean removeNamespaceDeclaration(String string) {
315: return delegateElement.removeNamespaceDeclaration(string);
316: }
317:
318: public Iterator getChildElements() {
319: return delegateElement.getChildElements();
320: }
321:
322: public Iterator getChildElements(Name name) {
323: return delegateElement.getChildElements(name);
324: }
325:
326: public void setEncodingStyle(String string) throws SOAPException {
327: delegateElement.setEncodingStyle(string);
328: }
329:
330: public String getEncodingStyle() {
331: return delegateElement.getEncodingStyle();
332: }
333:
334: public String getValue() {
335: return delegateElement.getValue();
336: }
337:
338: public void setValue(String string) {
339: delegateElement.setValue(string);
340: }
341:
342: public void setParentElement(SOAPElement sOAPElement)
343: throws SOAPException {
344: delegateElement.setParentElement(sOAPElement);
345: }
346:
347: public SOAPElement getParentElement() {
348: return delegateElement.getParentElement();
349: }
350:
351: public void detachNode() {
352: delegateElement.detachNode();
353: }
354:
355: public void recycleNode() {
356: delegateElement.recycleNode();
357: }
358:
359: public String getNodeName() {
360: return delegateElement.getNodeName();
361: }
362:
363: public String getNodeValue() throws DOMException {
364: return delegateElement.getNodeValue();
365: }
366:
367: public void setNodeValue(String nodeValue) throws DOMException {
368: delegateElement.setNodeValue(nodeValue);
369: }
370:
371: public short getNodeType() {
372: return delegateElement.getNodeType();
373: }
374:
375: public Node getParentNode() {
376: return delegateElement.getParentNode();
377: }
378:
379: public NodeList getChildNodes() {
380: return delegateElement.getChildNodes();
381: }
382:
383: public Node getFirstChild() {
384: return delegateElement.getFirstChild();
385: }
386:
387: public Node getLastChild() {
388: return delegateElement.getLastChild();
389: }
390:
391: public Node getPreviousSibling() {
392: return delegateElement.getPreviousSibling();
393: }
394:
395: public Node getNextSibling() {
396: return delegateElement.getNextSibling();
397: }
398:
399: public NamedNodeMap getAttributes() {
400: return delegateElement.getAttributes();
401: }
402:
403: public Document getOwnerDocument() {
404: return delegateElement.getOwnerDocument();
405: }
406:
407: public Node insertBefore(Node newChild, Node refChild)
408: throws DOMException {
409: return delegateElement.insertBefore(newChild, refChild);
410: }
411:
412: public Node replaceChild(Node newChild, Node oldChild)
413: throws DOMException {
414: return delegateElement.replaceChild(newChild, oldChild);
415: }
416:
417: public Node removeChild(Node oldChild) throws DOMException {
418: return delegateElement.removeChild(oldChild);
419: }
420:
421: public Node appendChild(Node newChild) throws DOMException {
422: return delegateElement.appendChild(newChild);
423: }
424:
425: public boolean hasChildNodes() {
426: return delegateElement.hasChildNodes();
427:
428: }
429:
430: public Node cloneNode(boolean deep) {
431: return delegateElement.cloneNode(deep);
432: }
433:
434: public void normalize() {
435: delegateElement.normalize();
436: }
437:
438: public boolean isSupported(String feature, String version) {
439: return delegateElement.isSupported(feature, version);
440: }
441:
442: public String getNamespaceURI() {
443: return delegateElement.getNamespaceURI();
444: }
445:
446: public String getPrefix() {
447: return delegateElement.getPrefix();
448: }
449:
450: public void setPrefix(String prefix) throws DOMException {
451: delegateElement.setPrefix(prefix);
452: }
453:
454: public String getLocalName() {
455: return delegateElement.getLocalName();
456: }
457:
458: public boolean hasAttributes() {
459: return delegateElement.hasAttributes();
460: }
461:
462: public String getBaseURI() {
463: return delegateElement.getBaseURI();
464: }
465:
466: public short compareDocumentPosition(Node other)
467: throws DOMException {
468: return delegateElement.compareDocumentPosition(other);
469: }
470:
471: public String getTextContent() throws DOMException {
472: return delegateElement.getTextContent();
473: }
474:
475: public void setTextContent(String textContent) throws DOMException {
476: delegateElement.setTextContent(textContent);
477: }
478:
479: public boolean isSameNode(Node other) {
480: return delegateElement.isSameNode(other);
481: }
482:
483: public String lookupPrefix(String namespaceURI) {
484: return delegateElement.lookupPrefix(namespaceURI);
485: }
486:
487: public boolean isDefaultNamespace(String namespaceURI) {
488: return delegateElement.isDefaultNamespace(namespaceURI);
489: }
490:
491: public String lookupNamespaceURI(String prefix) {
492: return delegateElement.lookupNamespaceURI(prefix);
493: }
494:
495: public boolean isEqualNode(Node arg) {
496: return delegateElement.isEqualNode(arg);
497: }
498:
499: public Object getFeature(String feature, String version) {
500: return delegateElement.getFeature(feature, version);
501: }
502:
503: public Object setUserData(String key, Object data,
504: UserDataHandler handler) {
505: return delegateElement.setUserData(key, data, handler);
506: }
507:
508: public Object getUserData(String key) {
509: return delegateElement.getUserData(key);
510: }
511:
512: public String getTagName() {
513: return delegateElement.getTagName();
514: }
515:
516: public String getAttribute(String name) {
517: return delegateElement.getAttribute(name);
518: }
519:
520: public void setAttribute(String name, String value)
521: throws DOMException {
522: delegateElement.setAttribute(name, value);
523: }
524:
525: public void removeAttribute(String name) throws DOMException {
526: delegateElement.removeAttribute(name);
527: }
528:
529: public Attr getAttributeNode(String name) {
530: return delegateElement.getAttributeNode(name);
531: }
532:
533: public Attr setAttributeNode(Attr newAttr) throws DOMException {
534: return delegateElement.setAttributeNode(newAttr);
535: }
536:
537: public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
538: return delegateElement.removeAttributeNode(oldAttr);
539: }
540:
541: public NodeList getElementsByTagName(String name) {
542: return delegateElement.getElementsByTagName(name);
543: }
544:
545: public String getAttributeNS(String namespaceURI, String localName)
546: throws DOMException {
547: return delegateElement.getAttributeNS(namespaceURI, localName);
548: }
549:
550: public void setAttributeNS(String namespaceURI,
551: String qualifiedName, String value) throws DOMException {
552: delegateElement.setAttributeNS(namespaceURI, qualifiedName,
553: value);
554:
555: }
556:
557: public void removeAttributeNS(String namespaceURI, String localName)
558: throws DOMException {
559: delegateElement.removeAttributeNS(namespaceURI, localName);
560: }
561:
562: public Attr getAttributeNodeNS(String namespaceURI, String localName)
563: throws DOMException {
564: return delegateElement.getAttributeNodeNS(namespaceURI,
565: localName);
566: }
567:
568: public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
569: return delegateElement.setAttributeNodeNS(newAttr);
570: }
571:
572: public NodeList getElementsByTagNameNS(String namespaceURI,
573: String localName) throws DOMException {
574: return delegateElement.getElementsByTagNameNS(namespaceURI,
575: localName);
576: }
577:
578: public boolean hasAttribute(String name) {
579: return delegateElement.hasAttribute(name);
580: }
581:
582: public boolean hasAttributeNS(String namespaceURI, String localName)
583: throws DOMException {
584: return delegateElement.hasAttributeNS(namespaceURI, localName);
585: }
586:
587: public TypeInfo getSchemaTypeInfo() {
588: return delegateElement.getSchemaTypeInfo();
589: }
590:
591: public void setIdAttribute(String name, boolean isId)
592: throws DOMException {
593: delegateElement.setIdAttribute(name, isId);
594: }
595:
596: public void setIdAttributeNS(String namespaceURI, String localName,
597: boolean isId) throws DOMException {
598: delegateElement.setIdAttributeNS(namespaceURI, localName, isId);
599: }
600:
601: public void setIdAttributeNode(Attr idAttr, boolean isId)
602: throws DOMException {
603: delegateElement.setIdAttributeNode(idAttr, isId);
604: }
605:
606: public void isBSP(boolean flag) {
607: bsp = flag;
608: }
609:
610: public boolean isBSP() {
611: return bsp;
612: }
613:
614: }
|