01: /*
02: * $Id: AttachmentContentOnlyTransform.java,v 1.5 2007/01/08 16:06:04 shyam_rao Exp $
03: */
04:
05: /*
06: * The contents of this file are subject to the terms
07: * of the Common Development and Distribution License
08: * (the License). You may not use this file except in
09: * compliance with the License.
10: *
11: * You can obtain a copy of the license at
12: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
13: * See the License for the specific language governing
14: * permissions and limitations under the License.
15: *
16: * When distributing Covered Code, include this CDDL
17: * Header Notice in each file and include the License file
18: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
19: * If applicable, add the following below the CDDL Header,
20: * with the fields enclosed by brackets [] replaced by
21: * you own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
25: */
26:
27: package com.sun.xml.wss.impl.transform;
28:
29: import javax.mail.internet.ContentType;
30:
31: import com.sun.xml.wss.impl.c14n.Canonicalizer;
32: import com.sun.xml.wss.impl.c14n.CanonicalizerFactory;
33:
34: import com.sun.xml.wss.impl.resolver.AttachmentSignatureInput;
35:
36: import com.sun.org.apache.xml.internal.security.transforms.TransformSpi;
37: import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
38: import com.sun.org.apache.xml.internal.security.transforms.TransformationException;
39:
40: public class AttachmentContentOnlyTransform extends TransformSpi {
41:
42: private static final String implementedTransformURI = "http://docs.oasis-open.org/wss/2004/XX/"
43: + "oasis-2004XX-wss-swa-profile-1.0#Attachment-Content-Only-Transform";
44:
45: protected String engineGetURI() {
46: return implementedTransformURI;
47: }
48:
49: protected XMLSignatureInput enginePerformTransform(
50: XMLSignatureInput input) throws TransformationException {
51: try {
52: return new XMLSignatureInput(_canonicalize(input));
53: } catch (Exception e) {
54: // log
55: throw new TransformationException(e.getMessage(), e);
56: }
57: }
58:
59: private byte[] _canonicalize(XMLSignatureInput input)
60: throws Exception {
61: byte[] inputContentBytes = input.getBytes();
62: //ContentType contentType = new ContentType(((AttachmentSignatureInput)input).getContentType());
63:
64: Canonicalizer canonicalizer = CanonicalizerFactory
65: .getCanonicalizer(((AttachmentSignatureInput) input)
66: .getContentType());
67:
68: return canonicalizer.canonicalize(inputContentBytes);
69: }
70:
71: public boolean wantsOctetStream() {
72: return true;
73: }
74:
75: public boolean wantsNodeSet() {
76: return true;
77: }
78:
79: public boolean returnsOctetStream() {
80: return true;
81: }
82:
83: public boolean returnsNodeSet() {
84: return false;
85: }
86: }
|