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: package com.sun.xml.ws.security.opt.impl.dsig;
024:
025: import com.sun.xml.ws.security.opt.api.SecurityElementWriter;
026: import com.sun.xml.ws.security.opt.api.SecurityHeaderElement;
027: import com.sun.xml.ws.security.opt.crypto.dsig.Reference;
028: import com.sun.xml.ws.security.opt.impl.util.NamespaceContextEx;
029: import com.sun.xml.wss.impl.c14n.AttributeNS;
030: import com.sun.xml.wss.impl.c14n.StAXEXC14nCanonicalizerImpl;
031: import com.sun.org.apache.xml.internal.security.utils.UnsyncBufferedOutputStream;
032: import java.io.OutputStream;
033: import java.util.HashMap;
034: import java.util.Iterator;
035: import java.util.List;
036: import javax.xml.crypto.dsig.XMLSignatureException;
037: import javax.xml.stream.XMLStreamException;
038: import javax.xml.stream.XMLStreamReader;
039: import javax.xml.stream.XMLStreamWriter;
040: import org.jcp.xml.dsig.internal.DigesterOutputStream;
041:
042: /**
043: *
044: * @author K.Venugopal@sun.com
045: */
046: public class EnvelopedSignedMessageHeader implements
047: SecurityHeaderElement, SecurityElementWriter {
048: private Reference ref = null;
049: private SecurityHeaderElement she = null;
050: private StAXEXC14nCanonicalizerImpl stAXC14n = null;
051: private JAXBSignatureHeaderElement jse = null;
052: private String id = "";
053: private NamespaceContextEx nsContext = null;
054:
055: /** Creates a new instance of EnvelopedSignedMessageHeader */
056: public EnvelopedSignedMessageHeader(SecurityHeaderElement she,
057: Reference ref, JAXBSignatureHeaderElement jse,
058: NamespaceContextEx nsContext) {
059: this .she = she;
060: this .ref = ref;
061: this .jse = jse;
062: this .nsContext = nsContext;
063: stAXC14n = new StAXEXC14nCanonicalizerImpl();
064: }
065:
066: public boolean refersToSecHdrWithId(final String id) {
067: throw new UnsupportedOperationException();
068: }
069:
070: public String getId() {
071: return id;
072: }
073:
074: public void setId(final String id) {
075: }
076:
077: public String getNamespaceURI() {
078: return she.getNamespaceURI();
079: }
080:
081: public String getLocalPart() {
082: return she.getLocalPart();
083: }
084:
085: public XMLStreamReader readHeader() throws XMLStreamException {
086: throw new UnsupportedOperationException();
087: }
088:
089: public byte[] canonicalize(final String algorithm,
090: final List<AttributeNS> namespaceDecls) {
091: throw new UnsupportedOperationException();
092:
093: }
094:
095: public boolean isCanonicalized() {
096: throw new UnsupportedOperationException();
097: }
098:
099: public void writeTo(XMLStreamWriter streamWriter)
100: throws XMLStreamException {
101: if (nsContext == null) {
102: throw new XMLStreamException(
103: "NamespaceContext is null in writeTo method");
104: }
105:
106: Iterator<NamespaceContextEx.Binding> itr = nsContext.iterator();
107: stAXC14n.reset();
108: while (itr.hasNext()) {
109: final NamespaceContextEx.Binding nd = itr.next();
110: stAXC14n.writeNamespace(nd.getPrefix(), nd
111: .getNamespaceURI());
112: }
113: DigesterOutputStream dos = null;
114: try {
115: dos = ref.getDigestOutputStream();
116: } catch (XMLSignatureException xse) {
117: throw new XMLStreamException(xse);
118: }
119: OutputStream os = new UnsyncBufferedOutputStream(dos);
120: stAXC14n.setStream(os);
121: //EnvelopedTransformWriter etw = new EnvelopedTransformWriter(streamWriter,stAXC14n,ref,jse,dos);
122: ((SecurityElementWriter) she).writeTo(streamWriter);
123: }
124:
125: public void writeTo(XMLStreamWriter streamWriter, HashMap props)
126: throws XMLStreamException {
127: throw new UnsupportedOperationException("Not implemented yet");
128: }
129:
130: public void writeTo(OutputStream os) {
131: throw new UnsupportedOperationException("Not implemented yet");
132: }
133: }
|