|
From: <pe...@us...> - 2003-12-19 18:03:38
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id
In directory sc8-pr-cvs1:/tmp/cvs-serv5310/src/java/org/neuclear/id
Modified Files:
Identity.java InvalidNamedObjectException.java NSTools.java
NameResolutionException.java NamedObjectReader.java
SignatureRequest.java SignedMessage.java SignedNamedCore.java
SignedNamedObject.java
Log Message:
Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
- For most cases the main exception to worry about now is InvalidNamedObjectException.
- Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
runtime exception.
- Source and Store patterns each now have their own exceptions that generalizes the various physical
exceptions that can happen in that area.
Index: Identity.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/Identity.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** Identity.java 17 Dec 2003 12:45:57 -0000 1.25
--- Identity.java 19 Dec 2003 18:03:34 -0000 1.26
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.26 2003/12/19 18:03:34 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.25 2003/12/17 12:45:57 pelle
* NeuClear JCE Certificates now work with KeyStore.
***************
*** 331,338 ****
* @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 NeuClearException
*/
! protected Identity(final SignedNamedCore core, final String repository, final String signer, final String logger, final String receiver, final PublicKey pub) throws NeuClearException {
super(core);
this.repository = repository;
--- 339,345 ----
* @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
*/
! protected Identity(final SignedNamedCore core, final String repository, final String signer, final String logger, final String receiver, final PublicKey pub) {
super(core);
this.repository = repository;
***************
*** 491,504 ****
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) throws NeuClearException, XMLSecurityException {
! final String repository = elem.attributeValue(DocumentHelper.createQName("repository", NSTools.NS_NEUID));
! final String signer = elem.attributeValue(DocumentHelper.createQName("signer", NSTools.NS_NEUID));
! final String logger = elem.attributeValue(DocumentHelper.createQName("logger", NSTools.NS_NEUID));
! final String receiver = elem.attributeValue(DocumentHelper.createQName("receiver", NSTools.NS_NEUID));
! final Element allowElement = elem.element(DocumentHelper.createQName("allow", NSTools.NS_NEUID));
! final KeyInfo ki = new KeyInfo(allowElement.element(XMLSecTools.createQName("KeyInfo")));
! final PublicKey pub = ki.getPublicKey();
! return new Identity(core, repository, signer, logger, receiver, pub);
}
--- 498,515 ----
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) throws InvalidNamedObjectException {
! final String repository = elem.attributeValue(createNEUIDQName("repository"));
! final String signer = elem.attributeValue(createNEUIDQName("signer"));
! final String logger = elem.attributeValue(createNEUIDQName("logger"));
! final String receiver = elem.attributeValue(createNEUIDQName("receiver"));
! final Element allowElement = InvalidNamedObjectException.assertContainsElementQName(core,elem,createNEUIDQName("allow"));
! try {
! final KeyInfo ki = new KeyInfo(InvalidNamedObjectException.assertContainsElementQName(allowElement, XMLSecTools.createQName("KeyInfo")));
! final PublicKey pub = ki.getPublicKey();
! return new Identity(core, repository, signer, logger, receiver, pub);
! } catch (XMLSecurityException e) {
! throw new InvalidNamedObjectException(core.getName(),e);
! }
}
Index: InvalidNamedObjectException.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/InvalidNamedObjectException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** InvalidNamedObjectException.java 19 Dec 2003 00:31:30 -0000 1.2
--- InvalidNamedObjectException.java 19 Dec 2003 18:03:34 -0000 1.3
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.3 2003/12/19 18:03:34 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.2 2003/12/19 00:31:30 pelle
* Lots of usability changes through out all the passphrase agents and end user tools.
***************
*** 107,112 ****
--- 115,133 ----
import org.neuclear.commons.NeuClearException;
+ import org.dom4j.Element;
+ import org.dom4j.QName;
+ /**
+ * Thrown if an object is invalid. Also contains various helper methods for validating named objects
+ */
public final class InvalidNamedObjectException extends NeuClearException {
+ public InvalidNamedObjectException(final String name,final String message) {
+ super(name+" is an invalid Identity\nCause: "+message);
+ this.name=name;
+ }
+ public InvalidNamedObjectException(final String name,Throwable e) {
+ super(name+" is an invalid Identity\nCause: "+e.getLocalizedMessage(),e);
+ this.name=name;
+ }
public InvalidNamedObjectException(final String name) {
super(name+" is an invalid Identity");
***************
*** 116,119 ****
--- 137,175 ----
public String getName() {
return name;
+ }
+
+ public static void assertElementQName(SignedNamedCore core,Element elem,QName qname) throws InvalidNamedObjectException{
+ if (!elem.getQName().equals(qname))
+ throw new InvalidNamedObjectException(core.getName(),"Element: "+elem.getQualifiedName()+ " should be: "+qname.getQualifiedName());
+ }
+
+ public static Element assertContainsElementQName(SignedNamedCore core,Element elem,QName qname) throws InvalidNamedObjectException{
+ final Element sub = elem.element(qname);
+ if (sub==null)
+ throw new InvalidNamedObjectException(core.getName(),"Element: "+elem.getQualifiedName()+ " should be: "+qname.getQualifiedName());
+ return sub;
+ }
+
+ public static String assertAttributeQName(SignedNamedCore core,Element elem,QName qname) throws InvalidNamedObjectException{
+ if (elem.attribute(qname)==null)
+ throw new InvalidNamedObjectException(core.getName(),"Element: "+elem.getQualifiedName()+ " should contain attribute: "+qname.getQualifiedName());
+ return elem.attributeValue(qname);
+ }
+ public static void assertElementQName(Element elem,QName qname) throws InvalidNamedObjectException{
+ if (!elem.getQName().equals(qname))
+ throw new InvalidNamedObjectException("unknown","Element: "+elem.getQualifiedName()+ " should be: "+qname.getQualifiedName());
+ }
+
+ public static Element assertContainsElementQName(Element elem,QName qname) throws InvalidNamedObjectException{
+ final Element sub = elem.element(qname);
+ if (sub==null)
+ throw new InvalidNamedObjectException("unknown","Element: "+elem.getQualifiedName()+ " should be: "+qname.getQualifiedName());
+ return sub;
+ }
+
+ public static String assertAttributeQName(Element elem,QName qname) throws InvalidNamedObjectException{
+ if (elem.attribute(qname)==null)
+ throw new InvalidNamedObjectException("unknown","Element: "+elem.getQualifiedName()+ " should contain attribute: "+qname.getQualifiedName());
+ return elem.attributeValue(qname);
}
private final String name;
Index: NSTools.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/NSTools.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** NSTools.java 19 Dec 2003 00:31:30 -0000 1.23
--- NSTools.java 19 Dec 2003 18:03:34 -0000 1.24
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.24 2003/12/19 18:03:34 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.23 2003/12/19 00:31:30 pelle
* Lots of usability changes through out all the passphrase agents and end user tools.
***************
*** 205,211 ****
* @param name Valid NEU Name
* @return Valid URI
! * @throws NeuClearException If name isn't a valid NEU Name
*/
! public static String normalizeNameURI(String name) throws NeuClearException {
if (name == null)
return "neu://";
--- 213,219 ----
* @param name Valid NEU Name
* @return Valid URI
! * @throws InvalidNamedObjectException If name isn't a valid NEU Name
*/
! public static String normalizeNameURI(String name) throws InvalidNamedObjectException {
if (name == null)
return "neu://";
***************
*** 293,299 ****
* @param uri a valid NEU Name
* @return Parent URI or null if name is the root
! * @throws NeuClearException if name is invalid
*/
! public static String getLocalName(final String uri) throws NeuClearException {
if (!isValidName(uri))
throw new InvalidNamedObjectException("Invalid Neu ID: " + uri);
--- 301,307 ----
* @param uri a valid NEU Name
* @return Parent URI or null if name is the root
! * @throws InvalidNamedObjectException if name is invalid
*/
! public static String getLocalName(final String uri) throws InvalidNamedObjectException {
if (!isValidName(uri))
throw new InvalidNamedObjectException("Invalid Neu ID: " + uri);
Index: NameResolutionException.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/NameResolutionException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NameResolutionException.java 19 Dec 2003 00:31:30 -0000 1.1
--- NameResolutionException.java 19 Dec 2003 18:03:34 -0000 1.2
***************
*** 13,16 ****
--- 13,20 ----
private final String name;
+ public NameResolutionException(final String name,final String cause) {
+ super(name+" couldnt be resolved\nCause:"+cause);
+ this.name=name;
+ }
public NameResolutionException(final String name) {
super(name+" couldnt be resolved");
Index: NamedObjectReader.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/NamedObjectReader.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** NamedObjectReader.java 10 Dec 2003 23:58:51 -0000 1.6
--- NamedObjectReader.java 19 Dec 2003 18:03:34 -0000 1.7
***************
*** 25,28 ****
--- 25,36 ----
$Id$
$Log$
+ Revision 1.7 2003/12/19 18:03:34 pelle
+ Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ runtime exception.
+ - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ exceptions that can happen in that area.
+
Revision 1.6 2003/12/10 23:58:51 pelle
Did some cleaning up in the builders
***************
*** 84,87 ****
* @return
*/
! public SignedNamedObject read(SignedNamedCore core, Element elem) throws NeuClearException, XMLSecurityException;
}
--- 92,95 ----
* @return
*/
! public SignedNamedObject read(SignedNamedCore core, Element elem) throws InvalidNamedObjectException;
}
Index: SignatureRequest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/SignatureRequest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SignatureRequest.java 10 Dec 2003 23:58:51 -0000 1.9
--- SignatureRequest.java 19 Dec 2003 18:03:34 -0000 1.10
***************
*** 28,31 ****
--- 28,39 ----
$Id$
$Log$
+ Revision 1.10 2003/12/19 18:03:34 pelle
+ Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ runtime exception.
+ - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ exceptions that can happen in that area.
+
Revision 1.9 2003/12/10 23:58:51 pelle
Did some cleaning up in the builders
***************
*** 94,98 ****
*/
public final class SignatureRequest extends SignedNamedObject {
! private SignatureRequest(final SignedNamedCore core, final String userid, final NamedObjectBuilder unsigned, final String description) throws NeuClearException {
super(core);
this.userid = userid;
--- 102,106 ----
*/
public final class SignatureRequest extends SignedNamedObject {
! private SignatureRequest(final SignedNamedCore core, final String userid, final NamedObjectBuilder unsigned, final String description) {
super(core);
this.userid = userid;
***************
*** 120,135 ****
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) throws NeuClearException, XMLSecurityException {
! final Element request = elem.element(DocumentHelper.createQName("Unsigned", NSTools.NS_NEUID));
! final String userid = elem.attributeValue(DocumentHelper.createQName("userid", NSTools.NS_NEUID));
final Element uelem = ((Element) request.elements().get(0)).createCopy();
final Document doc = DocumentHelper.createDocument(uelem);
! final NamedObjectBuilder unsigned = new NamedObjectBuilder(uelem);
! String description = null;
! final Element descrelem = elem.element(DocumentHelper.createQName("Description", NSTools.NS_NEUID));
! if (descrelem != null)
! description = descrelem.getText();
! return new SignatureRequest(core, userid, unsigned, description);
}
--- 128,148 ----
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) throws InvalidNamedObjectException {
! InvalidNamedObjectException.assertElementQName(core,elem,createNEUIDQName(SIGREQUEST_TAG));
! final Element request = InvalidNamedObjectException.assertContainsElementQName(core,elem,createNEUIDQName("Unsigned"));
! final String userid = InvalidNamedObjectException.assertAttributeQName(core,elem,createNEUIDQName("userid"));
final Element uelem = ((Element) request.elements().get(0)).createCopy();
final Document doc = DocumentHelper.createDocument(uelem);
! try {
! final NamedObjectBuilder unsigned = new NamedObjectBuilder(uelem);
! String description = null;
! final Element descrelem = elem.element(DocumentHelper.createQName("Description", NSTools.NS_NEUID));
! if (descrelem != null)
! description = descrelem.getText();
! return new SignatureRequest(core, userid, unsigned, description);
! } catch (XMLSecurityException e) {
! throw new InvalidNamedObjectException(core.getName(),e);
! }
}
Index: SignedMessage.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/SignedMessage.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SignedMessage.java 16 Dec 2003 15:05:00 -0000 1.1
--- SignedMessage.java 19 Dec 2003 18:03:34 -0000 1.2
***************
*** 18,22 ****
*/
public class SignedMessage extends SignedNamedObject{
! private SignedMessage(SignedNamedCore core, String recipient,String subject, String message) throws NeuClearException {
super(core);
this.recipient=recipient;
--- 18,22 ----
*/
public class SignedMessage extends SignedNamedObject{
! private SignedMessage(SignedNamedCore core, String recipient,String subject, String message) {
super(core);
this.recipient=recipient;
***************
*** 44,48 ****
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) throws NeuClearException, XMLSecurityException {
final String to=elem.attributeValue("recipient");
final String subject=elem.element("subject").getText();
--- 44,48 ----
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) {
final String to=elem.attributeValue("recipient");
final String subject=elem.element("subject").getText();
Index: SignedNamedCore.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/SignedNamedCore.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** SignedNamedCore.java 11 Dec 2003 23:57:29 -0000 1.6
--- SignedNamedCore.java 19 Dec 2003 18:03:34 -0000 1.7
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.7 2003/12/19 18:03:34 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.6 2003/12/11 23:57:29 pelle
* Trying to test the ReceiverServlet with cactus. Still no luck. Need to return a ElementProxy of some sort.
***************
*** 227,233 ****
--- 235,243 ----
import org.neuclear.xml.xmlsec.KeyInfo;
import org.neuclear.xml.xmlsec.XMLSecTools;
+ import org.neuclear.xml.xmlsec.XMLSecurityException;
import java.security.PublicKey;
import java.sql.Timestamp;
+ import java.text.ParseException;
/**
***************
*** 266,289 ****
* @param elem
* @return
! * @throws XMLException
! * @throws NeuClearException
*/
! public final static SignedNamedCore read(final Element elem) throws XMLException, NeuClearException {
! final String name = NSTools.normalizeNameURI(elem.attributeValue(getNameAttrQName()));
! final String signatoryName = NSTools.getSignatoryURI(name);
! final Identity signatory = NSResolver.resolveIdentity(signatoryName);
! PublicKey publicKey = signatory.getPublicKey();
! if (NSTools.isHttpScheme(name) != null) {
! // We have a self signed http authenticated certificate and need to extract
! // the PublicKey from the xml
! final Element allowElement = elem.element(DocumentHelper.createQName("allow", NSTools.NS_NEUID));
! final KeyInfo ki = new KeyInfo(allowElement.element(XMLSecTools.createQName("KeyInfo")));
! publicKey = ki.getPublicKey();
}
- if (XMLSecTools.verifySignature(elem, publicKey)) {
- final Timestamp timestamp = TimeTools.parseTimeStamp(elem.attributeValue("timestamp"));
- return new SignedNamedCore(name, signatory, timestamp, new String(XMLSecTools.canonicalize(elem)));
- } else
- throw new InvalidNamedObjectException(name + " isnt valid");
}
--- 276,304 ----
* @param elem
* @return
! * @throws InvalidNamedObjectException
*/
! public final static SignedNamedCore read(final Element elem) throws InvalidNamedObjectException, NameResolutionException {
! final String name = NSTools.normalizeNameURI(InvalidNamedObjectException.assertAttributeQName(elem,getNameAttrQName()));
! try {
! final String signatoryName = NSTools.getSignatoryURI(name);
! final Identity signatory = NSResolver.resolveIdentity(signatoryName);
! PublicKey publicKey = signatory.getPublicKey();
! if (NSTools.isHttpScheme(name) != null) {
! // We have a self signed http authenticated certificate and need to extract
! // the PublicKey from the xml
! final Element allowElement = InvalidNamedObjectException.assertContainsElementQName(elem,createQName("allow"));
! final KeyInfo ki = new KeyInfo(InvalidNamedObjectException.assertContainsElementQName(allowElement, XMLSecTools.createQName("KeyInfo")));
! publicKey = ki.getPublicKey();
! }
! if (XMLSecTools.verifySignature(elem, publicKey)) {
! final Timestamp timestamp = TimeTools.parseTimeStamp(InvalidNamedObjectException.assertAttributeQName(elem,createQName("timestamp")));
! return new SignedNamedCore(name, signatory, timestamp, new String(XMLSecTools.canonicalize(elem)));
! } else
! throw new InvalidNamedObjectException(name);
! } catch (XMLSecurityException e) {
! throw new InvalidNamedObjectException(name);
! } catch (ParseException e) {
! throw new InvalidNamedObjectException(name,"invalid timestamp");
}
}
***************
*** 299,304 ****
private static QName getNameAttrQName() {
return DocumentHelper.createQName("name", NSTools.NS_NEUID);
-
}
/**
--- 314,322 ----
private static QName getNameAttrQName() {
return DocumentHelper.createQName("name", NSTools.NS_NEUID);
}
+ private static QName createQName(String name) {
+ return DocumentHelper.createQName(name, NSTools.NS_NEUID);
+ }
+
/**
Index: SignedNamedObject.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/SignedNamedObject.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** SignedNamedObject.java 10 Dec 2003 23:58:51 -0000 1.13
--- SignedNamedObject.java 19 Dec 2003 18:03:34 -0000 1.14
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.14 2003/12/19 18:03:34 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.13 2003/12/10 23:58:51 pelle
* Did some cleaning up in the builders
***************
*** 208,211 ****
--- 216,221 ----
import org.dom4j.Element;
+ import org.dom4j.QName;
+ import org.dom4j.DocumentHelper;
import org.neuclear.commons.NeuClearException;
import org.neuclear.xml.xmlsec.XMLSecurityException;
***************
*** 236,240 ****
public class SignedNamedObject implements SignedObject, Named {
! protected SignedNamedObject(final SignedNamedCore core) throws NeuClearException {
this.core = core;
}
--- 246,250 ----
public class SignedNamedObject implements SignedObject, Named {
! protected SignedNamedObject(final SignedNamedCore core) {
this.core = core;
}
***************
*** 314,318 ****
getSignatory().receive(this);
}
!
private final SignedNamedCore core;
--- 324,330 ----
getSignatory().receive(this);
}
! public final static QName createNEUIDQName(String name){
! return DocumentHelper.createQName(name, NSTools.NS_NEUID);
! }
private final SignedNamedCore core;
***************
*** 324,328 ****
* @return
*/
! public SignedNamedObject read(final SignedNamedCore core, final Element elem) throws NeuClearException, XMLSecurityException {
return new SignedNamedObject(core);
}
--- 336,340 ----
* @return
*/
! public SignedNamedObject read(final SignedNamedCore core, final Element elem) {
return new SignedNamedObject(core);
}
|