View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2001 - 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 package com.sun.ebxml.registry.repository; 11 12 import java.io.IOException; 13 import java.io.InputStream; 14 import java.io.StringReader; 15 16 import javax.activation.DataHandler; 17 18 import org.apache.commons.logging.LogFactory; 19 import org.apache.xml.security.signature.XMLSignature; 20 import org.xml.sax.InputSource; 21 22 /*** 23 * Repository item wrapper. 24 * 25 * @author Adrian Chong 26 * @author Peter Burgess 27 * 28 * @version $Version: $ [$Date: 2003/03/18 07:56:08 $] 29 */ 30 public class RepositoryItem { 31 32 private org.apache.commons.logging.Log log = LogFactory.getLog(this.getClass()); 33 private static final String baseURI = "http://www.w3.org/2000/09/xmldsig#"; 34 35 private String id = null; 36 private XMLSignature signature = null; 37 private String signatureString = null; 38 private DataHandler handler = null; 39 private javax.xml.parsers.DocumentBuilder db = null; 40 41 /*** 42 * Constructor. 43 */ 44 public RepositoryItem(String id, XMLSignature signature, DataHandler handler) { 45 this.id = id; 46 this.signature = signature; 47 this.handler = handler; 48 init(); 49 } 50 51 /*** 52 * Constructor. 53 */ 54 public RepositoryItem(String id, String signature, DataHandler handler) { 55 this.id = id; 56 this.signatureString = signature; 57 this.handler = handler; 58 59 init(); 60 61 //Not yet working due to security issues 62 //on SOAP attachments 63 createXMLSignature(); 64 } 65 66 67 /*** 68 * Initialisation tasks. 69 */ 70 private void init() { 71 try { 72 log.trace("Entering init"); 73 74 javax.xml.parsers.DocumentBuilderFactory dbf = 75 javax.xml.parsers.DocumentBuilderFactory.newInstance(); 76 dbf.setNamespaceAware(true); 77 db = dbf.newDocumentBuilder(); 78 log.debug("db [javax.xml.parsers.DocumentBuilder] = " + db); 79 80 log.trace("init completed successfully"); 81 } catch(Exception e) { 82 log.error(e); 83 } 84 } 85 86 87 /*** 88 * Builds XMLSignature based on signature string.. 89 */ 90 private void createXMLSignature() { 91 try { 92 log.debug("signatureString = " + signatureString); 93 94 if(signatureString == null || 95 signatureString.trim().length() > 0) { 96 //??Fake the DSIG with canned DSIG 97 signatureString = "<ds:Signature xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#dsa-sha1\"></ds:SignatureMethod><ds:Reference URI=\"#Body\"><ds:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></ds:DigestMethod><ds:DigestValue>b44T45s+zCpv5C+qP7HIqIWGOvs=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>MUV8aucO2HN4k3DZ3+FC4dN5Gp4G5tL7SqaG2Bm/LuDG978ayRDbVg==</ds:SignatureValue><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIIC9jCCArQCBDruqiowCwYHKoZIzjgEAwUAMGExCzAJBgNVBAYTAkRFMR0wGwYDVQQKExRVbml2ZXJzaXR5IG9mIFNpZWdlbjEQMA4GA1UECxMHRkIxMk5VRTEhMB8GA1UEAxMYQ2hyaXN0aWFuIEdldWVyLVBvbGxtYW5uMB4XDTAxMDUwMTEyMjA1OFoXDTA2MTAyMjEyMjA1OFowYTELMAkGA1UEBhMCREUxHTAbBgNVBAoTFFVuaXZlcnNpdHkgb2YgU2llZ2VuMRAwDgYDVQQLEwdGQjEyTlVFMSEwHwYDVQQDExhDaHJpc3RpYW4gR2V1ZXItUG9sbG1hbm4wggG3MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9T gR11EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZgt2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/yIgMZndFIAccCFQC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8jUYZL3gZTNI=</ds:Y></ds:DSAKeyValue></ds:KeyValue></ds:KeyInfo> </ds:Signature>"; 98 99 log.warn("Using dummy XMLSignature because Signature string is null/whitespace"); 100 } 101 102 org.w3c.dom.Document doc = db.parse(new InputSource(new StringReader(signatureString))); 103 signature = new XMLSignature(doc.getDocumentElement(), baseURI); 104 105 } catch(Exception e) { 106 log.error("Exception creating XMLSignature", e); 107 } 108 } 109 110 /*** 111 * Return the size of of the repository item in bytes. 112 */ 113 public int getSize() throws IOException { 114 InputStream is = handler.getInputStream(); 115 int size = 0; 116 while(is.read() != -1) { 117 size++; 118 } 119 return size; 120 } 121 122 //------------------------------- 123 // ACCESSORS 124 //------------------------------- 125 126 public String getId() { 127 return id; 128 } 129 130 public void setId(String id) { 131 this.id = id; 132 } 133 134 public XMLSignature getSignature() { 135 return signature; 136 } 137 138 public String signatureToString() { 139 return signatureString; 140 } 141 142 public DataHandler getDataHandler() { 143 return handler; 144 } 145 146 }

This page was automatically generated by Maven