abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r550343 - in /incubator/abdera/java/trunk: examples/src/main/java/org/apache/abdera/examples/security/ security/src/main/java/org/apache/abdera/security/ security/src/main/java/org/apache/abdera/security/xmlsec/
Date Mon, 25 Jun 2007 04:40:32 GMT
Author: jmsnell
Date: Sun Jun 24 21:40:31 2007
New Revision: 550343

URL: http://svn.apache.org/viewvc?view=rev&rev=550343
Log:
Helper method for removing invalid signatures from an entry.

Modified:
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/security/DSig.java
    incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/Signature.java
    incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/xmlsec/XmlSignature.java

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/security/DSig.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/security/DSig.java?view=diff&rev=550343&r1=550342&r2=550343
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/security/DSig.java
(original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/security/DSig.java
Sun Jun 24 21:40:31 2007
@@ -90,6 +90,8 @@
     
     System.out.println("Valid after changing the title? " + sig.verify(entry,null));
     
+    entry = sig.removeInvalidSignatures(entry, options);
+    
   }
   
 }

Modified: incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/Signature.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/Signature.java?view=diff&rev=550343&r1=550342&r2=550343
==============================================================================
--- incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/Signature.java
(original)
+++ incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/Signature.java
Sun Jun 24 21:40:31 2007
@@ -55,4 +55,6 @@
    */
   SignatureOptions getDefaultSignatureOptions() throws SecurityException;
   
+  <T extends Element>T removeInvalidSignatures(T element, SignatureOptions options)
throws SecurityException;
+  
 }

Modified: incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/xmlsec/XmlSignature.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/xmlsec/XmlSignature.java?view=diff&rev=550343&r1=550342&r2=550343
==============================================================================
--- incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/xmlsec/XmlSignature.java
(original)
+++ incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/xmlsec/XmlSignature.java
Sun Jun 24 21:40:31 2007
@@ -251,8 +251,39 @@
       }
   }
 
-  public SignatureOptions getDefaultSignatureOptions() throws SecurityException {
-    return new XmlSignatureOptions(getAbdera());
+  public SignatureOptions getDefaultSignatureOptions() 
+    throws SecurityException {
+      return new XmlSignatureOptions(getAbdera());
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T extends Element> T removeInvalidSignatures(
+    T element, 
+    SignatureOptions options) 
+      throws SecurityException {
+    List<org.w3c.dom.Element> remove = new ArrayList<org.w3c.dom.Element>();

+    org.w3c.dom.Element dom = fomToDom((Element)element, options);
+    NodeList children = dom.getChildNodes();
+    for (int n = 0; n < children.getLength(); n++) {
+      try {
+        Node node = children.item(n);
+        if (node.getNodeType() == Node.ELEMENT_NODE) {
+          org.w3c.dom.Element el = (org.w3c.dom.Element) node;
+          if (Constants.DSIG_NS.equals(el.getNamespaceURI()) &&
+              Constants.LN_SIGNATURE.equals(el.getLocalName())) {
+            IRI baseUri = element.getResolvedBaseUri();
+            XMLSignature sig = 
+              new XMLSignature(
+                el, (baseUri != null) ? baseUri.toString() : "");
+            if (!is_valid_signature(sig,options)) {
+              remove.add(el);
+            }
+          }
+        }
+      } catch (Exception e) {}
+    }
+    for (org.w3c.dom.Element el : remove) dom.removeChild(el);
+    return (T)domToFom(dom, options);
   }
 
 }



Mime
View raw message