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: /*
024: * ACOTransform.java
025: *
026: * Created on March 15, 2005, 8:25 PM
027: */
028:
029: package com.sun.xml.wss.impl.transform;
030:
031: import com.sun.xml.wss.impl.MessageConstants;
032: import com.sun.xml.wss.logging.LogDomainConstants;
033: import java.util.logging.Level;
034: import java.util.logging.Logger;
035: import javax.xml.crypto.dsig.TransformService;
036: import com.sun.xml.wss.impl.c14n.Canonicalizer;
037: import com.sun.xml.wss.impl.c14n.CanonicalizerFactory;
038: import com.sun.xml.wss.impl.dsig.AttachmentData;
039: import java.io.ByteArrayInputStream;
040: import java.io.ByteArrayOutputStream;
041: import java.io.InputStream;
042: import java.io.OutputStream;
043:
044: import javax.xml.crypto.OctetStreamData;
045: import javax.xml.soap.AttachmentPart;
046:
047: /**
048: *
049: * @author K.venugopal@sun.com
050: */
051: public class ACOTransform extends TransformService {
052: private static Logger logger = Logger.getLogger(
053: LogDomainConstants.IMPL_SIGNATURE_DOMAIN,
054: LogDomainConstants.IMPL_SIGNATURE_DOMAIN_BUNDLE);
055:
056: private static final String implementedTransformURI = MessageConstants.ATTACHMENT_CONTENT_ONLY_TRANSFORM_URI;
057:
058: /** Creates a new instance of ACOTransform */
059: public ACOTransform() {
060: }
061:
062: public java.security.spec.AlgorithmParameterSpec getParameterSpec() {
063: return null;
064:
065: //Revisit.
066: }
067:
068: public void init(
069: javax.xml.crypto.dsig.spec.TransformParameterSpec transformParameterSpec)
070: throws java.security.InvalidAlgorithmParameterException {
071: }
072:
073: public void init(javax.xml.crypto.XMLStructure xMLStructure,
074: javax.xml.crypto.XMLCryptoContext xMLCryptoContext)
075: throws java.security.InvalidAlgorithmParameterException {
076: }
077:
078: public void marshalParams(
079: javax.xml.crypto.XMLStructure xMLStructure,
080: javax.xml.crypto.XMLCryptoContext xMLCryptoContext)
081: throws javax.xml.crypto.MarshalException {
082: //no-op
083: }
084:
085: private javax.xml.crypto.Data canonicalize(OctetStreamData data) {
086: throw new UnsupportedOperationException();
087: //Revisit ::
088: /*try{
089: //Raised issue that passing of input to attachment complete
090: //transform to be standardised.
091: String contentType = data.getMimeType();
092: InputStream ioStream = data.getOctetStream();
093: Canonicalizer canonicalizer = CanonicalizerFactory.getCanonicalizer(contentType);
094: InputStream canonicalizedStream = canonicalizer.canonicalize(ioStream);
095: return new OctetStreamData(canonicalizedStream);
096: }catch(Exception ex){
097: ex.printStackTrace();
098: }*/
099:
100: }
101:
102: private javax.xml.crypto.Data canonicalize(AttachmentData data,
103: OutputStream outputStream)
104: throws javax.xml.crypto.dsig.TransformException {
105: try {
106: AttachmentPart attachment = data.getAttachmentPart();
107: ByteArrayOutputStream os = new ByteArrayOutputStream();
108: attachment.getDataHandler().writeTo(os);
109: OutputStream byteStream = null;
110: ByteArrayInputStream byteInputStream = new ByteArrayInputStream(
111: os.toByteArray());
112: if (outputStream == null) {
113: byteStream = new ByteArrayOutputStream();
114: } else {
115: byteStream = outputStream;
116: }
117: Canonicalizer canonicalizer = CanonicalizerFactory
118: .getCanonicalizer(attachment.getContentType());
119: InputStream is = canonicalizer.canonicalize(
120: byteInputStream, byteStream);
121: if (is != null)
122: return new OctetStreamData(is);
123:
124: return null;
125: } catch (javax.xml.crypto.dsig.TransformException te) {
126: logger.log(Level.SEVERE, "WSS1318.ac.transform.error", te);
127: throw te;
128: } catch (Exception ex) {
129: logger.log(Level.SEVERE, "WSS1318.ac.transform.error", ex);
130: throw new javax.xml.crypto.dsig.TransformException(ex
131: .getMessage());
132: }
133: }
134:
135: public boolean isFeatureSupported(String str) {
136: return false;
137: }
138:
139: public javax.xml.crypto.Data transform(javax.xml.crypto.Data data,
140: javax.xml.crypto.XMLCryptoContext xMLCryptoContext)
141: throws javax.xml.crypto.dsig.TransformException {
142: if (data instanceof OctetStreamData) {
143: return canonicalize((OctetStreamData) data);
144: } else if (data instanceof AttachmentData) {
145: ByteArrayOutputStream os = null;
146: return canonicalize((AttachmentData) data, os);
147: }
148: return null;
149: }
150:
151: public javax.xml.crypto.Data transform(javax.xml.crypto.Data data,
152: javax.xml.crypto.XMLCryptoContext xMLCryptoContext,
153: java.io.OutputStream outputStream)
154: throws javax.xml.crypto.dsig.TransformException {
155: if (data instanceof AttachmentData) {
156: return canonicalize((AttachmentData) data, outputStream);
157: }
158: return null;
159: }
160:
161: }
|