|
From: <pe...@us...> - 2003-10-01 19:08:37
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/builders
In directory sc8-pr-cvs1:/tmp/cvs-serv19838/src/java/org/neuclear/id/builders
Modified Files:
IdentityBuilder.java NamedObjectBuilder.java
TargetReference.java
Log Message:
Changed XML Format. Now NameSpace has been modified to Identity also the
xml namespace prefix nsdl has been changed to neuid.
The standard constants for using these have been moved into NSTools.
The NamedObjectBuilder can also now take an Element, such as an unsigned template.
Index: IdentityBuilder.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/builders/IdentityBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IdentityBuilder.java 27 Sep 2003 19:23:11 -0000 1.1
--- IdentityBuilder.java 1 Oct 2003 19:08:30 -0000 1.2
***************
*** 2,5 ****
--- 2,11 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/10/01 19:08:30 pelle
+ * Changed XML Format. Now NameSpace has been modified to Identity also the
+ * xml namespace prefix nsdl has been changed to neuid.
+ * The standard constants for using these have been moved into NSTools.
+ * The NamedObjectBuilder can also now take an Element, such as an unsigned template.
+ *
* Revision 1.1 2003/09/27 19:23:11 pelle
* Added Builders to create named objects from scratch.
***************
*** 132,186 ****
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";
}
}
--- 138,202 ----
import org.dom4j.Element;
import org.dom4j.QName;
+ import org.neuclear.id.Identity;
+ import org.neuclear.id.NSTools;
import org.neudist.utils.NeudistException;
import org.neudist.utils.Utility;
import org.neudist.xml.xmlsec.XMLSecTools;
import java.security.PublicKey;
! 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, "Identity");
! Element root = getElement();
! // We have meaningful defaults for the following two
! root.addAttribute(DocumentHelper.createQName("repository", NSTools.NS_NEUID), repository);
! root.addAttribute(DocumentHelper.createQName("logger", NSTools.NS_NEUID), receiver);
! if (!Utility.isEmpty(signer))
! root.addAttribute(DocumentHelper.createQName("signer", NSTools.NS_NEUID), signer);
! if (!Utility.isEmpty(receiver))
! root.addAttribute(DocumentHelper.createQName("receiver", NSTools.NS_NEUID), receiver);
! if (allow != null) {
! QName allowName = DocumentHelper.createQName("allow", NSTools.NS_NEUID);
! 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 "Identity";
! }
!
! public static void main(String args[]) {
! System.out.println("Test Building NeuClear Identities");
! try {
! NamedObjectBuilder id = new IdentityBuilder("neu://", Identity.NEUROOT.getPublicKey());
! System.out.println(new String(id.canonicalize()));
! } catch (NeudistException e) {
! e.printStackTrace();
! }
}
}
Index: NamedObjectBuilder.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/builders/NamedObjectBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** NamedObjectBuilder.java 1 Oct 2003 17:05:37 -0000 1.2
--- NamedObjectBuilder.java 1 Oct 2003 19:08:30 -0000 1.3
***************
*** 2,5 ****
--- 2,11 ----
* $Id$
* $Log$
+ * Revision 1.3 2003/10/01 19:08:30 pelle
+ * Changed XML Format. Now NameSpace has been modified to Identity also the
+ * xml namespace prefix nsdl has been changed to neuid.
+ * The standard constants for using these have been moved into NSTools.
+ * The NamedObjectBuilder can also now take an Element, such as an unsigned template.
+ *
* Revision 1.2 2003/10/01 17:05:37 pelle
* Moved the NeuClearCertificate class to be an inner class of Identity.
***************
*** 122,125 ****
--- 128,136 ----
import org.dom4j.*;
+ import org.neuclear.id.Identity;
+ import org.neuclear.id.NSTools;
+ import org.neuclear.id.Named;
+ import org.neuclear.id.resolver.NSResolver;
+ import org.neuclear.senders.Sender;
import org.neuclear.time.TimeTools;
import org.neudist.utils.NeudistException;
***************
*** 130,138 ****
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;
--- 141,144 ----
***************
*** 140,148 ****
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();
--- 146,155 ----
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 class NamedObjectBuilder extends SignedElement implements Named {
! public NamedObjectBuilder(String name, String tagName, String prefix, String nsURI) {
super(tagName, prefix, nsURI);
createDocument();
***************
*** 150,165 ****
}
! 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();
--- 157,173 ----
}
! public NamedObjectBuilder(String name, String tagName, Namespace ns) {
super(tagName, ns);
createDocument();
setName(name);
}
!
! public NamedObjectBuilder(String name, String tagName) {
! super(tagName, NSTools.NS_NEUID);
createDocument();
setName(name);
}
! public NamedObjectBuilder(String name, QName qname) {
super(qname);
createDocument();
***************
*** 167,170 ****
--- 175,192 ----
}
+ public NamedObjectBuilder(Element elem) throws XMLSecurityException {
+ super(elem);
+ //TODO Load targets
+ }
+
+ public String getTagName() {
+ if (getElement() == null)
+ return "Object";
+ return getElement().getName();
+ }
+
+ public NamedObjectBuilder(Document doc) throws XMLSecurityException {
+ super(doc.getRootElement());
+ }
/**
***************
*** 184,212 ****
* @return Parent Name
*/
! public String getLocalName() {
! 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 {
! return getName();
}
--- 206,236 ----
* @return Parent Name
*/
! public String getLocalName() {
! 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", NSTools.NS_NEUID);
}
+
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 {
! return getName();
}
***************
*** 215,223 ****
*/
public Namespace getNS() {
! return NamedObjectBuilder.NS_NSDL;
}
protected void addElement(NamedObjectBuilder child) throws XMLException {
! addElement((AbstractElementProxy)child);
}
--- 239,247 ----
*/
public Namespace getNS() {
! return NSTools.NS_NEUID;
}
protected void addElement(NamedObjectBuilder child) throws XMLException {
! addElement((AbstractElementProxy) child);
}
***************
*** 226,233 ****
* 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());
! }
/**
--- 250,257 ----
* 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", NSTools.NS_NEUID), TimeTools.createTimeStamp());
! }
/**
***************
*** 249,269 ****
*/
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
--- 273,294 ----
*/
public void addTarget(TargetReference target) throws NeudistException {
! if (target == null)
return;
! QName targetsQN = DocumentHelper.createQName("Targets", NSTools.NS_NEUID);
! 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
***************
*** 277,289 ****
* 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());
}
--- 302,314 ----
* 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());
}
***************
*** 293,298 ****
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);
--- 318,323 ----
public Timestamp getTimeStamp() throws NeudistException {
! String timeString = getElement().attributeValue(DocumentHelper.createQName("timestamp", NSTools.NS_NEUID));
! if (isSigned() && !Utility.isEmpty(timeString)) {
try {
return TimeTools.parseTimeStamp(timeString);
***************
*** 306,325 ****
}
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:";
}
--- 331,346 ----
}
+
public final void log() throws NeudistException {
Identity ns = getParent();
! Sender.quickSend(ns.getLogger(), this);
}
public Identity getParent() throws NeudistException {
! return NSResolver.resolveIdentity(NSTools.getParentNSURI(getName()));
}
private List targets;
}
Index: TargetReference.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/builders/TargetReference.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TargetReference.java 27 Sep 2003 19:23:11 -0000 1.1
--- TargetReference.java 1 Oct 2003 19:08:30 -0000 1.2
***************
*** 2,5 ****
--- 2,11 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/10/01 19:08:30 pelle
+ * Changed XML Format. Now NameSpace has been modified to Identity also the
+ * xml namespace prefix nsdl has been changed to neuid.
+ * The standard constants for using these have been moved into NSTools.
+ * The NamedObjectBuilder can also now take an Element, such as an unsigned template.
+ *
* Revision 1.1 2003/09/27 19:23:11 pelle
* Added Builders to create named objects from scratch.
***************
*** 41,76 ****
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() {
--- 47,82 ----
import org.dom4j.Element;
import org.dom4j.Namespace;
! import org.neuclear.id.NSTools;
import org.neuclear.senders.Sender;
import org.neudist.utils.NeudistException;
import org.neudist.utils.Utility;
import org.neudist.xml.AbstractElementProxy;
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, NSTools.NS_NEUID));
if (!Utility.isEmpty(href))
! getElement().addAttribute(DocumentHelper.createQName("href", NSTools.NS_NEUID), href);
if (!Utility.isEmpty(type))
! getElement().addAttribute(DocumentHelper.createQName("type", NSTools.NS_NEUID), type);
! owner = obj;
! }
public String getHref() {
! return getElement().attributeValue(DocumentHelper.createQName("href", NSTools.NS_NEUID));
}
+
public String getType() {
! return getElement().attributeValue(DocumentHelper.createQName("type", NSTools.NS_NEUID));
}
! private static final String TAG_NAME = "Target";
public String getTagName() {
***************
*** 79,86 ****
public Namespace getNS() {
! return NamedObjectBuilder.NS_NSDL;
}
public void send() throws NeudistException {
! Sender.quickSend(getHref(),owner);
}
--- 85,93 ----
public Namespace getNS() {
! return NSTools.NS_NEUID;
}
+
public void send() throws NeudistException {
! Sender.quickSend(getHref(), owner);
}
|