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.incoming;
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.impl.JAXBFilterProcessingContext;
028: import com.sun.xml.wss.XWSSecurityException;
029: import com.sun.xml.wss.impl.MessageConstants;
030: import com.sun.xml.wss.impl.policy.mls.WSSPolicy;
031:
032: import java.io.InputStream;
033: import java.io.OutputStream;
034: import java.security.Key;
035: import java.util.HashMap;
036:
037: import javax.xml.stream.XMLStreamException;
038: import javax.xml.stream.XMLStreamReader;
039: import javax.xml.stream.XMLStreamWriter;
040:
041: /**
042: *
043: * @author Ashutosh.Shahi@sun.com
044: */
045: public class EncryptedHeader implements SecurityHeaderElement,
046: SecurityElementWriter {
047:
048: private JAXBFilterProcessingContext pc = null;
049: private String id = "";
050: private String namespaceURI = "";
051: private String localName = "";
052: private EncryptedData ed = null;
053: private HashMap<String, String> parentNS = null;
054:
055: /** Creates a new instance of EncryptedHeader */
056: public EncryptedHeader(XMLStreamReader reader,
057: JAXBFilterProcessingContext pc,
058: HashMap<String, String> parentNS)
059: throws XMLStreamException, XWSSecurityException {
060: this .pc = pc;
061: this .parentNS = parentNS;
062: process(reader);
063: }
064:
065: public EncryptedData getEncryptedData() {
066: return ed;
067: }
068:
069: public String getEncryptionAlgorithm() {
070: return ed.getEncryptionAlgorithm();
071: }
072:
073: public Key getKey() {
074: return ed.getKey();
075: }
076:
077: public InputStream getCipherInputStream()
078: throws XWSSecurityException {
079: return ed.getCipherInputStream();
080: }
081:
082: public InputStream getCipherInputStream(Key key)
083: throws XWSSecurityException {
084: return ed.getCipherInputStream(key);
085: }
086:
087: public XMLStreamReader getDecryptedData()
088: throws XMLStreamException, XWSSecurityException {
089: return ed.getDecryptedData();
090: }
091:
092: public XMLStreamReader getDecryptedData(Key key)
093: throws XMLStreamException, XWSSecurityException {
094: return ed.getDecryptedData(key);
095: }
096:
097: public boolean refersToSecHdrWithId(String id) {
098: throw new UnsupportedOperationException();
099: }
100:
101: public String getId() {
102: return id;
103: }
104:
105: public void setId(String id) {
106: throw new UnsupportedOperationException();
107: }
108:
109: public String getNamespaceURI() {
110: return namespaceURI;
111: }
112:
113: public String getLocalPart() {
114: return localName;
115: }
116:
117: public XMLStreamReader readHeader() throws XMLStreamException {
118: throw new UnsupportedOperationException();
119: }
120:
121: public void writeTo(XMLStreamWriter streamWriter)
122: throws XMLStreamException {
123: throw new UnsupportedOperationException();
124: }
125:
126: public void writeTo(XMLStreamWriter streamWriter, HashMap props)
127: throws XMLStreamException {
128: throw new UnsupportedOperationException();
129: }
130:
131: public void writeTo(OutputStream os) {
132: throw new UnsupportedOperationException();
133: }
134:
135: private void process(XMLStreamReader reader)
136: throws XMLStreamException, XWSSecurityException {
137: id = reader.getAttributeValue(MessageConstants.WSU_NS, "Id");
138: namespaceURI = reader.getNamespaceURI();
139: localName = reader.getLocalName();
140:
141: while (reader.hasNext()) {
142: reader.next();
143: if (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
144: if (MessageConstants.ENCRYPTED_DATA_LNAME.equals(reader
145: .getLocalName())
146: && MessageConstants.XENC_NS.equals(reader
147: .getNamespaceURI())) {
148: ed = new EncryptedData(reader, pc, parentNS);
149: }
150: }
151:
152: if (reader.getEventType() == XMLStreamReader.END_ELEMENT) {
153: if (MessageConstants.ENCRYPTED_HEADER_LNAME
154: .equals(reader.getLocalName())
155: && MessageConstants.WSSE11_NS.equals(reader
156: .getNamespaceURI())) {
157: break;
158: }
159: }
160: }
161: }
162:
163: public WSSPolicy getInferredKB() {
164: return ed.getInferredKB();
165: }
166:
167: }
|