001: /*
002: * $Id: EncryptedDataHeaderBlock.java,v 1.4 2007/01/08 09:28:47 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.core;
028:
029: import java.util.logging.Level;
030:
031: import com.sun.xml.wss.impl.XMLUtil;
032: import com.sun.xml.wss.impl.MessageConstants;
033: import com.sun.xml.wss.XWSSecurityException;
034:
035: import javax.xml.soap.SOAPElement;
036: import javax.xml.soap.SOAPException;
037:
038: import com.sun.xml.wss.impl.misc.SecurityHeaderBlockImpl;
039:
040: /**
041: * Corresponds to Schema definition for EncryptedData.
042: * Schema definition for EncryptedData is as follows:
043: * <p>
044: * <xmp>
045: * <element name='EncryptedData' type='xenc:EncryptedDataType'/>
046: * <complexType name='EncryptedDataType'>
047: * <complexContent>
048: * <extension base='xenc:EncryptedType'/>
049: * </complexContent>
050: * </complexType>
051: * </xmp>
052: *
053: * @author Vishal Mahajan
054: */
055: public class EncryptedDataHeaderBlock extends EncryptedTypeHeaderBlock {
056:
057: /**
058: * Create an empty EncryptedData element.
059: *
060: * @throws XWSSecurityException
061: * If there is problem creating an EncryptedData element.
062: */
063: public EncryptedDataHeaderBlock() throws XWSSecurityException {
064: try {
065: setSOAPElement(getSoapFactory().createElement(
066: MessageConstants.ENCRYPTED_DATA_LNAME,
067: MessageConstants.XENC_PREFIX,
068: MessageConstants.XENC_NS));
069: addNamespaceDeclaration(MessageConstants.XENC_PREFIX,
070: MessageConstants.XENC_NS);
071: } catch (SOAPException e) {
072: log.log(Level.SEVERE, "WSS0345.error.creating.edhb", e
073: .getMessage());
074: throw new XWSSecurityException(e);
075: }
076: }
077:
078: /**
079: * @throws XWSSecurityException
080: * If there is problem in initializing EncryptedData element.
081: */
082: public EncryptedDataHeaderBlock(SOAPElement element)
083: throws XWSSecurityException {
084:
085: setSOAPElement(element);
086:
087: if (!(element.getLocalName().equals(
088: MessageConstants.ENCRYPTED_DATA_LNAME) && XMLUtil
089: .inEncryptionNS(element))) {
090: log.log(Level.SEVERE, "WSS0346.error.creating.edhb",
091: element.getTagName());
092: throw new XWSSecurityException(
093: "Invalid EncryptedData passed");
094: }
095: initializeEncryptedType(element);
096: }
097:
098: public static SecurityHeaderBlock fromSoapElement(
099: SOAPElement element) throws XWSSecurityException {
100: return SecurityHeaderBlockImpl.fromSoapElement(element,
101: EncryptedDataHeaderBlock.class);
102: }
103:
104: public SOAPElement getAsSoapElement() throws XWSSecurityException {
105: if (updateRequired) {
106: removeContents();
107: try {
108: addTextNode("\n ");
109: if (encryptionMethod != null) {
110: addChildElement(encryptionMethod);
111: addTextNode("\n ");
112: }
113: if (keyInfo != null) {
114: addChildElement(keyInfo.getAsSoapElement());
115: addTextNode("\n ");
116: }
117: if (cipherData == null) {
118: log
119: .log(Level.SEVERE,
120: "WSS0347.missing.cipher.data");
121: throw new XWSSecurityException(
122: "CipherData is not present inside EncryptedType");
123: }
124: addChildElement(cipherData);
125: addTextNode("\n ");
126: if (encryptionProperties != null) {
127: addChildElement(encryptionProperties);
128: addTextNode("\n ");
129: }
130: } catch (SOAPException e) {
131: log.log(Level.SEVERE, "WSS0345.error.creating.edhb", e
132: .getMessage());
133: throw new XWSSecurityException(e);
134: }
135: }
136: return super.getAsSoapElement();
137: }
138:
139: }
|