abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1187043 - in /abdera/abdera2/security/src/main/java/org/apache/abdera2/security: Security.java util/filters/SignedRequestFilter.java
Date Thu, 20 Oct 2011 20:52:55 GMT
Author: jmsnell
Date: Thu Oct 20 20:52:55 2011
New Revision: 1187043

URL: http://svn.apache.org/viewvc?rev=1187043&view=rev
Log:
Additional Guava integration...

Modified:
    abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java
    abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java

Modified: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java?rev=1187043&r1=1187042&r2=1187043&view=diff
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java (original)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java Thu Oct
20 20:52:55 2011
@@ -19,8 +19,14 @@ package org.apache.abdera2.security;
 
 import org.apache.abdera2.Abdera;
 import org.apache.abdera2.common.Discover;
+import org.apache.abdera2.model.Base;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
 import org.apache.abdera2.util.Configuration;
 
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+
 /**
  * The AbderaSecurity class provides the entry point for using XML Digital Signatures and
XML Encryption with Abdera.
  */
@@ -80,4 +86,66 @@ public class Security {
         return signature;
     }
 
+    public <T extends Element,E extends Element>Function<Document<T>,Document<E>>
encryptor(final EncryptionOptions options) {
+      return new Function<Document<T>,Document<E>>() {
+        public Document<E> apply(Document<T> input) {
+          return getEncryption().<E>encrypt(input, options);
+        }
+      };
+    }
+    
+    public <T extends Element,E extends Element>Function<Document<T>,Document<E>>
decryptor(final EncryptionOptions options) {
+      return new Function<Document<T>,Document<E>>() {
+        @SuppressWarnings("unchecked")
+        public Document<E> apply(Document<T> input) {
+          Encryption enc = getEncryption();
+          if (!enc.isEncrypted(input)) return (Document<E>)input;
+          return enc.<E>decrypt(input, options);
+        }
+      };
+    }
+    
+    public <T extends Element>Function<T,T> signer(final SignatureOptions options)
{
+      return new Function<T,T>() {
+        public T apply(T input) {
+          return getSignature().sign(input, options);
+        }
+      };
+    }
+    
+    public <T extends Element>Function<T,Boolean> verifier(final SignatureOptions
options) {
+      return new Function<T,Boolean>() {
+        public Boolean apply(T input) {
+          return getSignature().verify(input, options);
+        }
+      };
+    }
+        
+    public <T extends Element>Predicate<T> isVerified() {
+      return isVerified(null);
+    }
+    
+    public <T extends Element>Predicate<T> isVerified(final SignatureOptions
options) {
+      return new Predicate<T>() {
+        public boolean apply(T input) {
+          return verifier(options).apply(input);
+        }
+      };
+    }
+    
+    public boolean verified(Base e) {
+      return isVerified().apply(e instanceof Document ? ((Document<?>)e).getRoot()
: (Element)e);
+    }
+    
+    public boolean notVerified(Base e) {
+      return !verified(e);
+    }
+    
+    public boolean verified(Base e, SignatureOptions options) {
+      return isVerified(options).apply(e instanceof Document ? ((Document<?>)e).getRoot()
: (Element)e);
+    }
+    
+    public boolean notVerified(Base e, SignatureOptions options) {
+      return !verified(e,options);
+    }
 }

Modified: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java?rev=1187043&r1=1187042&r2=1187043&view=diff
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java
(original)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java
Thu Oct 20 20:52:55 2011
@@ -49,11 +49,15 @@ public class SignedRequestFilter impleme
         if (method.equals("POST") || method.equals("PUT")) {
             try {
                 Document<Element> doc = context.getDocument();
-                boolean valid = sig.verify(doc.getRoot(), null);
-                if (!valid)
-                    return ProviderHelper.badrequest(request, Localizer.get("VALID.SIGNATURE.REQUIRED"));
-                request.setAttribute(VALID, valid);
-                request.setAttribute(CERTS, sig.getValidSignatureCertificates(doc.getRoot(),
null));
+                if (security.notVerified(doc))
+                    return ProviderHelper.badrequest(
+                      request, 
+                      Localizer.get("VALID.SIGNATURE.REQUIRED"));
+                request.setAttribute(
+                  VALID, true);
+                request.setAttribute(
+                  CERTS, 
+                  sig.getValidSignatureCertificates(doc.getRoot(), null));
             } catch (Exception e) {
             }
         }



Mime
View raw message