001: /*
002: * $Id: AttachmentCompleteTransform.java,v 1.5 2007/01/08 16:06:05 shyam_rao 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.impl.transform;
028:
029: import javax.mail.internet.ContentType;
030:
031: import com.sun.xml.wss.impl.c14n.Canonicalizer;
032: import com.sun.xml.wss.impl.c14n.CanonicalizerFactory;
033: import com.sun.xml.wss.impl.c14n.MimeHeaderCanonicalizer;
034:
035: import com.sun.xml.wss.impl.resolver.AttachmentSignatureInput;
036:
037: import com.sun.org.apache.xml.internal.security.transforms.TransformSpi;
038: import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
039: import com.sun.org.apache.xml.internal.security.transforms.TransformationException;
040:
041: public class AttachmentCompleteTransform extends TransformSpi {
042:
043: private static final String implementedTransformURI = "http://docs.oasis-open.org/wss/2004/XX/"
044: + "oasis-2004XX-wss-swa-profile-1.0#Attachment-Complete-Transform";
045:
046: protected String engineGetURI() {
047: return implementedTransformURI;
048: }
049:
050: protected XMLSignatureInput enginePerformTransform(
051: XMLSignatureInput input) throws TransformationException {
052: try {
053: return new XMLSignatureInput(_canonicalize(input));
054: } catch (Exception e) {
055: // log
056: throw new TransformationException(e.getMessage(), e);
057: }
058: }
059:
060: private byte[] _canonicalize(XMLSignatureInput input)
061: throws Exception {
062: byte[] inputContentBytes = input.getBytes();
063: //ContentType contentType = new ContentType(((AttachmentSignatureInput)input).getContentType());
064:
065: // rf. RFC822
066: MimeHeaderCanonicalizer mHCanonicalizer = CanonicalizerFactory
067: .getMimeHeaderCanonicalizer("US-ASCII");
068: byte[] outputHeaderBytes = mHCanonicalizer
069: ._canonicalize(((AttachmentSignatureInput) input)
070: .getMimeHeaders().iterator());
071:
072: Canonicalizer canonicalizer = CanonicalizerFactory
073: .getCanonicalizer(((AttachmentSignatureInput) input)
074: .getContentType());
075: byte[] outputContentBytes = canonicalizer
076: .canonicalize(inputContentBytes);
077:
078: byte[] outputBytes = new byte[outputHeaderBytes.length
079: + outputContentBytes.length];
080: System.arraycopy(outputHeaderBytes, 0, outputBytes, 0,
081: outputHeaderBytes.length);
082: System.arraycopy(outputContentBytes, 0, outputBytes,
083: outputHeaderBytes.length, outputContentBytes.length);
084:
085: return outputBytes;
086: }
087:
088: public boolean wantsOctetStream() {
089: return true;
090: }
091:
092: public boolean wantsNodeSet() {
093: return true;
094: }
095:
096: public boolean returnsOctetStream() {
097: return true;
098: }
099:
100: public boolean returnsNodeSet() {
101: return false;
102: }
103: }
|