|
From: <pe...@us...> - 2003-09-28 02:24:18
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/builders In directory sc8-pr-cvs1:/tmp/cvs-serv3423/src/java/org/neuclear/id/builders Added Files: IdentityBuilder.java NamedObjectBuilder.java TargetReference.java Log Message: Added Builders to create named objects from scratch. --- NEW FILE: IdentityBuilder.java --- /* * $Id: IdentityBuilder.java,v 1.1 2003/09/27 19:23:11 pelle Exp $ * $Log: IdentityBuilder.java,v $ * Revision 1.1 2003/09/27 19:23:11 pelle * Added Builders to create named objects from scratch. * * Revision 1.11 2003/02/18 14:57:18 pelle * Finished Cleaning up Receivers and Stores. * Also updated nsdl.xsd xml schema with latest changes. * The whole API is now very simple. * * Revision 1.10 2003/02/18 00:06:15 pelle * Moved the SignerStore's into xml-sig * * Revision 1.9 2003/02/16 00:22:59 pelle * LogSender now works and there is a corresponding server side cgi script to do the logging in * http://neudist.org/logger/ Site is not yet up but will be soon. * * Revision 1.8 2003/02/14 21:10:29 pelle * The email sender works. The LogSender and the SoapSender should work but havent been tested yet. * The NamedObject has a new log() method that logs it's contents at it's parent NameSpace's logger. * The NameSpace object also has a new method send() which allows one to send a named object to the NameSpace's * default receiver. * * Revision 1.7 2003/02/10 22:30:05 pelle * Got rid of even further dependencies. In Particular OSCore * * Revision 1.6 2003/02/09 00:15:52 pelle * Fixed things so they now compile with r_0.7 of XMLSig * * Revision 1.5 2003/01/16 22:20:02 pelle * First Draft of new generalised Ledger Interface. * Currently we have a Book and Transaction class. * We also need a Ledger class and a Ledger Factory. * * Revision 1.4 2002/12/17 21:40:54 pelle * First part of refactoring of NamedObject and SignedObject Interface/Class parings. * * Revision 1.3 2002/12/17 20:34:39 pelle * Lots of changes to core functionality. * First of all I've refactored most of the Resolving and verification code. I have a few more things to do * on it before I'm happy. * There is now a NSResolver class, which handles all the namespace resolution. I took most of the functionality * for this out of NamedObject. * Then there is the veriifer, which verifies a given NamedObject using the NSResolver. * This has simplified the NamedObject classes drastically, leaving them as mainly data objects, which is what they * should be. * I have also gone around and tightened up security on many different classes, making clases and/or methods final where appropriate. * NSCache now operates using http://www.waterken.com's fantastic ADT collections library. * Something important has been added, which is a SignRequest named object. This signed object, embeds an unsigned * named object for signing by an end users' signing service. * Now were almost ready to start seriously implementing AssetIssuers and Transfers, which will be the most important * part of the framework. * * Revision 1.2 2002/10/02 21:03:44 pelle * Major Commit * I completely redid the namespace resolving code. * It now works correctly with the new store attribute of the namespace * And can correctly work out the location of a namespace file * by hierarchically signing it. * I have also included several top level namespaces and finalised * the root namespace. * In short all of the above means that we can theoretically call * Neubia live now. (Well on my first deployment anyway). * There is a new CommandLineSigner utility class which creates and signs * namespaces using standard java keystores. * I'm now working on updating the documentation, so other people * than me might have a chance at using it. * * Revision 1.1.1.1 2002/09/18 10:55:42 pelle * First release in new CVS structure. * Also first public release. * This implemnts simple named objects. * - NameSpace Objects * - NSAuth Objects * * Storage systems * - In Memory Storage * - Clear text file based storage * - Encrypted File Storage (with SHA256 digested filenames) * - CachedStorage * - SoapStorage * * Simple SOAP client/server * - Simple Single method call SOAP client, for arbitrary dom4j based requests * - Simple Abstract SOAP Servlet for implementing http based SOAP Servers * * Simple XML-Signature Implementation * - Based on dom4j * - SHA-RSA only * - Very simple (likely imperfect) highspeed canonicalizer * - Zero support for X509 (We dont like that anyway) * - Super Simple * * * Revision 1.5 2002/06/18 03:04:11 pelle * Just added all the necessary jars. * Fixed a few things in the framework and * started a GUI Application to manage Neu's. * * Revision 1.4 2002/06/17 20:48:33 pelle * The NS functionality should now work. FileStore is working properly. * The example .ns objects in the neuspace folder have been updated with the * latest version of the format. * "neuspace/root.ns" should now be considered the universal parent of the * neudist system. * Still more to go, but we're getting there. I will now focus on a quick * Web interface. After which Contracts will be added. * * Revision 1.3 2002/06/13 19:04:07 pelle * A start to a web interface into the architecture. * We're getting a bit further now with functionality. * * Revision 1.2 2002/06/05 23:42:04 pelle * The Throw clauses of several method definitions were getting out of hand, so I have * added a new wrapper exception NeudistException, to keep things clean in the ledger. * This is used as a catchall wrapper for all Exceptions in the underlying API's such as IOExceptions, * XML Exceptions etc. * You can catch any Exception and rethrow it using Utility.rethrowException(e) as a quick way of handling * exceptions. * Otherwise the Store framework and the NameSpaces are really comming along quite well. I added a CachedStore * which wraps around any other Store and caches the access to the store. * * Revision 1.1.1.1 2002/05/29 10:02:22 pelle * Lets try one more time. This is the first rev of the next gen of Neudist * * */ package org.neuclear.id.builders; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.QName; import org.neudist.utils.NeudistException; import org.neudist.utils.Utility; import org.neudist.xml.xmlsec.KeyInfo; import org.neudist.xml.xmlsec.XMLSecTools; import java.security.PublicKey; import java.util.Iterator; import java.util.List; public final class IdentityBuilder extends NamedObjectBuilder { /** * This constructor should be used by subclasses of NameSpace. It creates a Standard NameSpace document, but doesn't sign it. * The signing should be done as the last step of the constructor of the subclass. * @param name The Name of NameSpace * @param allow PublicKey allowed to sign in here * @param repository URL of Default Store for NameSpace. (Note. A NameSpace object is stored in the default repository of it's parent namespace) * @param signer URL of default interactive signing service for namespace. If null it doesnt allow interactive signing * @param receiver URL of default receiver for namespace * @throws NeudistException */ public IdentityBuilder(String name,PublicKey allow,String repository,String signer,String logger,String receiver) throws NeudistException { super(name,"NameSpace"); Element root=getElement(); // We have meaningful defaults for the following two root.addAttribute(DocumentHelper.createQName("repository",NamedObjectBuilder.NS_NSDL),repository); root.addAttribute(DocumentHelper.createQName("logger",NamedObjectBuilder.NS_NSDL),receiver); if (!Utility.isEmpty(signer)) root.addAttribute(DocumentHelper.createQName("signer",NamedObjectBuilder.NS_NSDL),signer); if (!Utility.isEmpty(receiver)) root.addAttribute(DocumentHelper.createQName("receiver",NamedObjectBuilder.NS_NSDL),receiver); if (allow!=null) { QName allowName=DocumentHelper.createQName("allow",NamedObjectBuilder.NS_NSDL); Element pub=root.addElement(allowName); pub.add(XMLSecTools.createKeyInfo(allow)); } } public IdentityBuilder(String name,PublicKey allow,String repository) throws NeudistException { this(name,allow,repository,null,null,null); } public IdentityBuilder(String name,PublicKey allow) throws NeudistException { this(name,allow,null); } public String getTagName() { return "NameSpace"; } } --- NEW FILE: NamedObjectBuilder.java --- /* * $Id: NamedObjectBuilder.java,v 1.1 2003/09/27 19:23:11 pelle Exp $ * $Log: NamedObjectBuilder.java,v $ * Revision 1.1 2003/09/27 19:23:11 pelle * Added Builders to create named objects from scratch. * * Revision 1.13 2003/02/18 14:57:19 pelle * Finished Cleaning up Receivers and Stores. * Also updated nsdl.xsd xml schema with latest changes. * The whole API is now very simple. * * Revision 1.12 2003/02/14 21:10:30 pelle * The email sender works. The LogSender and the SoapSender should work but havent been tested yet. * The NamedObject has a new log() method that logs it's contents at it's parent NameSpace's logger. * The NameSpace object also has a new method send() which allows one to send a named object to the NameSpace's * default receiver. * * Revision 1.11 2003/02/14 14:04:29 pelle * The New Source Classes work and NS resolution works as well. * I've renamed Target to TargetReference to prepare for the other main refactoring ahead. Implementation of * Senders. * * Revision 1.10 2003/02/10 22:30:06 pelle * Got rid of even further dependencies. In Particular OSCore * * Revision 1.9 2003/02/09 00:15:52 pelle * Fixed things so they now compile with r_0.7 of XMLSig * * Revision 1.8 2002/12/17 21:53:28 pelle * Final changes for refactoring. * * Revision 1.7 2002/12/17 20:34:39 pelle * Lots of changes to core functionality. * First of all I've refactored most of the Resolving and verification code. I have a few more things to do * on it before I'm happy. * There is now a NSResolver class, which handles all the namespace resolution. I took most of the functionality * for this out of NamedObject. * Then there is the veriifer, which verifies a given NamedObject using the NSResolver. * This has simplified the NamedObject classes drastically, leaving them as mainly data objects, which is what they * should be. * I have also gone around and tightened up security on many different classes, making clases and/or methods final where appropriate. * NSCache now operates using http://www.waterken.com's fantastic ADT collections library. * Something important has been added, which is a SignRequest named object. This signed object, embeds an unsigned * named object for signing by an end users' signing service. * Now were almost ready to start seriously implementing AssetIssuers and Transfers, which will be the most important * part of the framework. * * Revision 1.6 2002/10/03 01:51:58 pelle * Bunch of smaller fixes for bugs found during deployment. * Also a bit more documentation. * I'm happy with this being called rev. 0.4 * * Revision 1.5 2002/10/02 21:03:44 pelle * Major Commit * I completely redid the namespace resolving code. * It now works correctly with the new store attribute of the namespace * And can correctly work out the location of a namespace file * by hierarchically signing it. * I have also included several top level namespaces and finalised * the root namespace. * In short all of the above means that we can theoretically call * Neubia live now. (Well on my first deployment anyway). * There is a new CommandLineSigner utility class which creates and signs * namespaces using standard java keystores. * I'm now working on updating the documentation, so other people * than me might have a chance at using it. * * Revision 1.4 2002/09/25 19:20:15 pelle * Added various new schemas and updated most of the existing ones. * Added explanation interface for explaining the purpose of a * NamedObject to a user. We may want to use XSL instead. * Also made the signing webapp look a bit nicer. * * Revision 1.3 2002/09/21 23:11:13 pelle * A bunch of clean ups. Got rid of as many hard coded URL's as I could. * * Revision 1.2 2002/09/20 01:15:18 pelle * Added prototype webapplication under src/java * SOAPServlet appears to work * Any webservices taking named objects should subclass from ReceiverServlet * SigningServlet is not completely working right now, but * will be the main prototype of a web based signer. * * Other new features are GenericNamedObject for simple instantiation of * arbitrary named objects. * * Revision 1.1.1.1 2002/09/18 10:55:40 pelle * First release in new CVS structure. * Also first public release. * This implemnts simple named objects. * - NameSpace Objects * - NSAuth Objects * * Storage systems * - In Memory Storage * - Clear text file based storage * - Encrypted File Storage (with SHA256 digested filenames) * - CachedStorage * - SoapStorage * * Simple SOAP client/server * - Simple Single method call SOAP client, for arbitrary dom4j based requests * - Simple Abstract SOAP Servlet for implementing http based SOAP Servers * * Simple XML-Signature Implementation * - Based on dom4j * - SHA-RSA only * - Very simple (likely imperfect) highspeed canonicalizer * - Zero support for X509 (We dont like that anyway) * - Super Simple * * * Revision 1.1.1.1 2002/05/29 10:02:22 pelle * Lets try one more time. This is the first rev of the next gen of Neudist * * */ package org.neuclear.id.builders; import org.dom4j.*; import org.neuclear.time.TimeTools; import org.neudist.utils.NeudistException; import org.neudist.utils.Utility; import org.neudist.xml.AbstractElementProxy; import org.neudist.xml.XMLException; import org.neudist.xml.xmlsec.SignedElement; import org.neudist.xml.xmlsec.XMLSecTools; import org.neudist.xml.xmlsec.XMLSecurityException; import org.neuclear.id.Named; import org.neuclear.id.NSTools; import org.neuclear.id.Identity; import org.neuclear.id.resolver.NSResolver; import org.neuclear.senders.Sender; import java.sql.Timestamp; import java.util.Iterator; import java.util.LinkedList; import java.util.List; /** * This simple wrapper takes most of the contents of a NamedObject and puts it into a Serializable form that can be signed. */ public abstract class NamedObjectBuilder extends SignedElement implements Named { public NamedObjectBuilder(String name,String tagName, String prefix, String nsURI) { super(tagName, prefix, nsURI); createDocument(); setName(name); } public NamedObjectBuilder(String name,String tagName, Namespace ns) { super(tagName, ns); createDocument(); setName(name); } public NamedObjectBuilder(String name,String tagName) { super(tagName,NamedObjectBuilder.NS_NSDL); createDocument(); setName(name); } public NamedObjectBuilder(String name,QName qname) { super(qname); createDocument(); setName(name); } /** * The full name (URI) of an object * @return String containing the fully qualified URI of an object */ public String getName() throws NeudistException{ return NSTools.normalizeNameURI(getElement().attributeValue(getNameAttrQName())); } /** * The Name of an object within it's parent NameSpace * @return Parent Name */ public String getLocalName() throws NeudistException{ String fullName=getName(); int i=fullName.lastIndexOf('/'); return fullName.substring(i+1); } private void setName(String name) { getElement().addAttribute(getNameAttrQName(),name); } private static QName getNameAttrQName() { return DocumentHelper.createQName("name",NamedObjectBuilder.NS_NSDL); } private void createDocument() { Element elem=getElement(); if(elem.getDocument()==null) { Document doc=DocumentHelper.createDocument(elem); } } /** * @return the URI of the object. In this case the same as getName(); */ public final String getURI() throws XMLSecurityException { try { return getName(); } catch (NeudistException e) { XMLSecTools.rethrowException(e); //To change body of catch statement use Options | File Templates. } return null; } /** * @return the XML NameSpace object */ public Namespace getNS() { return NamedObjectBuilder.NS_NSDL; } protected void addElement(NamedObjectBuilder child) throws XMLException { addElement((AbstractElementProxy)child); } /** * Sign NamedObject using given PrivateKey. This also adds a timestamp to the root element prior to signing */ protected final void preSign() throws XMLSecurityException{ // We need to timestamp it before we sign it getElement().addAttribute(DocumentHelper.createQName("timestamp",NamedObjectBuilder.NS_NSDL),TimeTools.createTimeStamp()); } /** * This is called after signing to handle any post signing tasks such as logging * @throws XMLSecurityException */ protected void postSign() throws XMLSecurityException { try { log(); } catch (NeudistException e) { XMLSecTools.rethrowException(e); } } /** * Adds a TargetReference to a NamedObject.<br> * This can only be done if the object isn't signed. * @param target object */ public void addTarget(TargetReference target) throws NeudistException { if (target==null) return; QName targetsQN=DocumentHelper.createQName("Targets",NamedObjectBuilder.NS_NSDL); Element targetsElem=getElement().element(targetsQN); if (targetsElem==null){ targetsElem=DocumentHelper.createElement(targetsQN); getElement().add(targetsElem); } targetsElem.add(target.getElement()); targetList().add(target); } private synchronized List targetList() { if (targets==null) targets=new LinkedList(); return targets; } /** * Lists the targets within an object * @return Iterator of targets */ public Iterator listTargets() throws NeudistException { return targetList().iterator(); } /** * Sends copy of object to all targets within */ public void sendObject() throws NeudistException{ System.out.println("NEUDIST: Sending Object "+getName()); if (this.isSigned()) { Iterator iter=listTargets(); while(iter.hasNext()) { TargetReference tg=((TargetReference)iter.next()); tg.send(); System.out.println("NEUDIST: Sent to "+tg.getHref()); } } } public Timestamp getTimeStamp() throws NeudistException { String timeString=getElement().attributeValue(DocumentHelper.createQName("timestamp",NamedObjectBuilder.NS_NSDL)); if (isSigned()&&!Utility.isEmpty(timeString)){ try { return TimeTools.parseTimeStamp(timeString); } catch (NeudistException e) { return null; } } return null; } public final void log() throws NeudistException { Identity ns = getParent(); Sender.quickSend(ns.getLogger(),this); } public Identity getParent() throws NeudistException { Identity ns=NSResolver.resolveIdentity(NSTools.getParentNSURI(getName())); return ns; } private List targets; public static final String NSDL_NAMESPACE="http://neudist.org/neu/nsdl"; public static final Namespace NS_NSDL=DocumentHelper.createNamespace("nsdl",NamedObjectBuilder.NSDL_NAMESPACE); public static final String NSDL_PREFIX="nsdl:"; } --- NEW FILE: TargetReference.java --- /* * $Id: TargetReference.java,v 1.1 2003/09/27 19:23:11 pelle Exp $ * $Log: TargetReference.java,v $ * Revision 1.1 2003/09/27 19:23:11 pelle * Added Builders to create named objects from scratch. * * Revision 1.3 2003/02/18 14:57:19 pelle * Finished Cleaning up Receivers and Stores. * Also updated nsdl.xsd xml schema with latest changes. * The whole API is now very simple. * * Revision 1.2 2003/02/14 21:10:33 pelle * The email sender works. The LogSender and the SoapSender should work but havent been tested yet. * The NamedObject has a new log() method that logs it's contents at it's parent NameSpace's logger. * The NameSpace object also has a new method send() which allows one to send a named object to the NameSpace's * default receiver. * * Revision 1.1 2003/02/14 14:04:59 pelle * The New Source Classes work and NS resolution works as well. * I've renamed Target to TargetReference to prepare for the other main refactoring ahead. Implementation of * Senders. * * Revision 1.5 2003/02/10 22:30:12 pelle * Got rid of even further dependencies. In Particular OSCore * * Revision 1.4 2003/02/09 00:15:55 pelle * Fixed things so they now compile with r_0.7 of XMLSig * * Revision 1.3 2002/09/21 23:11:16 pelle * A bunch of clean ups. Got rid of as many hard coded URL's as I could. * * User: pelleb * Date: Sep 14, 2002 * Time: 3:29:03 PM * To change template for new class use * Code Style | Class Templates options (Tools | IDE Options). */ package org.neuclear.id.builders; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.Namespace; //import org.neudist.ns.NamedObject; import org.neuclear.senders.Sender; import org.neudist.utils.NeudistException; import org.neudist.utils.Utility; import org.neudist.xml.AbstractElementProxy; import org.neuclear.senders.Sender; public class TargetReference extends AbstractElementProxy { public TargetReference(NamedObjectBuilder obj, Element elem) throws NeudistException{ super(elem); if (!elem.getName().equals(TAG_NAME)) throw new NeudistException("Element is not a <Target/> Element"); owner=obj; } public TargetReference(NamedObjectBuilder obj,String href,String type) { super(DocumentHelper.createQName(TAG_NAME,NamedObjectBuilder.NS_NSDL)); if (!Utility.isEmpty(href)) getElement().addAttribute(DocumentHelper.createQName("href",NamedObjectBuilder.NS_NSDL),href); if (!Utility.isEmpty(type)) getElement().addAttribute(DocumentHelper.createQName("type",NamedObjectBuilder.NS_NSDL),type); owner=obj; } public String getHref() { return getElement().attributeValue(DocumentHelper.createQName("href",NamedObjectBuilder.NS_NSDL)); } public String getType() { return getElement().attributeValue(DocumentHelper.createQName("type",NamedObjectBuilder.NS_NSDL)); } private static final String TAG_NAME="Target"; public String getTagName() { return TAG_NAME; } public Namespace getNS() { return NamedObjectBuilder.NS_NSDL; } public void send() throws NeudistException { Sender.quickSend(getHref(),owner); } private NamedObjectBuilder owner; } |