abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r617335 - in /incubator/abdera/java/trunk/security/src: main/java/org/apache/abdera/security/util/filters/ test/java/org/apache/abdera/test/security/filter/
Date Fri, 01 Feb 2008 02:58:11 GMT
Author: jmsnell
Date: Thu Jan 31 18:58:08 2008
New Revision: 617335

URL: http://svn.apache.org/viewvc?rev=617335&view=rev
Log:
Fixes and SignedRequestFilter test case

Modified:
    incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/util/filters/SignedResponseFilter.java
    incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/CustomProvider.java
    incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SecurityFilterTest.java
    incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SimpleAdapter.java

Modified: incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/util/filters/SignedResponseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/util/filters/SignedResponseFilter.java?rev=617335&r1=617334&r2=617335&view=diff
==============================================================================
--- incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/util/filters/SignedResponseFilter.java
(original)
+++ incubator/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/util/filters/SignedResponseFilter.java
Thu Jan 31 18:58:08 2008
@@ -191,10 +191,9 @@
       if (doc != null) {
         doc = signDocument(abdera,doc);
         doc.writeTo(aout);
+      } else {
+        super.writeTo(aout);
       }
-      else 
-        throw new RuntimeException(
-          "There was an error signing the response");
     }
   }
 

Modified: incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/CustomProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/CustomProvider.java?rev=617335&r1=617334&r2=617335&view=diff
==============================================================================
--- incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/CustomProvider.java
(original)
+++ incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/CustomProvider.java
Thu Jan 31 18:58:08 2008
@@ -23,6 +23,7 @@
 import org.apache.abdera.protocol.server.impl.AbstractWorkspaceProvider;
 import org.apache.abdera.protocol.server.impl.RouteManager;
 import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
+import org.apache.abdera.security.util.filters.SignedRequestFilter;
 import org.apache.abdera.security.util.filters.SignedResponseFilter;
 
 public class CustomProvider 
@@ -55,6 +56,7 @@
     addWorkspace(workspace);
     
     addFilter(
+      new SignedRequestFilter(),
       new SignedResponseFilter(
         keystoreFile,
         keystorePass,

Modified: incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SecurityFilterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SecurityFilterTest.java?rev=617335&r1=617334&r2=617335&view=diff
==============================================================================
--- incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SecurityFilterTest.java
(original)
+++ incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SecurityFilterTest.java
Thu Jan 31 18:58:08 2008
@@ -17,15 +17,25 @@
  */
 package org.apache.abdera.test.security.filter;
 
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
+import java.util.Date;
+
 import junit.framework.Assert;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.protocol.Response.ResponseType;
 import org.apache.abdera.protocol.client.AbderaClient;
 import org.apache.abdera.protocol.client.ClientResponse;
 import org.apache.abdera.security.AbderaSecurity;
 import org.apache.abdera.security.Signature;
+import org.apache.abdera.security.SignatureOptions;
+import org.apache.abdera.test.security.DigitalSignatureTest;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -63,4 +73,56 @@
     assertTrue(sig.verify(root, sig.getDefaultSignatureOptions()));
   }
   
+  private static final String keystoreFile = "/key.jks";
+  private static final String keystoreType = "JKS";
+  private static final String keystorePass = "testing";
+  private static final String privateKeyAlias = "James";
+  private static final String privateKeyPass = "testing";
+  private static final String certificateAlias = "James";
+  
+ 
+  @Test
+  public void testSignedRequestFilter() throws Exception {
+    Entry entry = abdera.newEntry();
+    entry.setId("http://localhost:9002/feed/entries/1");
+    entry.setTitle("test entry");
+    entry.setContent("Test Content");
+    entry.addLink("http://example.org");
+    entry.setUpdated(new Date());
+    entry.addAuthor("James");
+    ClientResponse resp = client.post("http://localhost:9002/feed", entry);
+    assertNotNull(resp);
+    assertEquals(ResponseType.CLIENT_ERROR, resp.getType());
+
+    // Initialize the keystore
+    AbderaSecurity security = new AbderaSecurity(abdera);
+    KeyStore ks = KeyStore.getInstance(keystoreType);
+    assertNotNull(ks);
+    
+    InputStream in = DigitalSignatureTest.class.getResourceAsStream(keystoreFile);
+    assertNotNull(in);
+    
+    ks.load(in, keystorePass.toCharArray());
+    PrivateKey signingKey = 
+      (PrivateKey) ks.getKey(
+        privateKeyAlias,
+        privateKeyPass.toCharArray());
+    X509Certificate cert = 
+      (X509Certificate) ks.getCertificate(
+        certificateAlias);
+    assertNotNull(signingKey);
+    assertNotNull(cert);
+
+    Signature sig = security.getSignature();
+    SignatureOptions options = sig.getDefaultSignatureOptions();    
+    options.setCertificate(cert);
+    options.setSigningKey(signingKey);  
+
+    // Sign the entry
+    entry = sig.sign(entry, options);
+    
+    resp = client.post("http://localhost:9002/feed", entry);
+    assertNotNull(resp);
+    assertEquals(ResponseType.SUCCESS, resp.getType());
+  }
 }

Modified: incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SimpleAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SimpleAdapter.java?rev=617335&r1=617334&r2=617335&view=diff
==============================================================================
--- incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SimpleAdapter.java
(original)
+++ incubator/abdera/java/trunk/security/src/test/java/org/apache/abdera/test/security/filter/SimpleAdapter.java
Thu Jan 31 18:58:08 2008
@@ -57,7 +57,7 @@
   public String getHref(RequestContext request) {
     Map<String,Object> params = new HashMap<String,Object>();
     params.put("collection","feed");
-    return request.urlFor(TargetType.TYPE_COLLECTION, params);
+    return request.urlFor("feed", params);
   }
 
   public String getTitle(RequestContext request) {
@@ -184,7 +184,7 @@
     Map<String,String> params = new HashMap<String,String>();
     params.put("collection", request.getTarget().getParameter("collection"));
     params.put("entry", entryid);
-    return request.urlFor(TargetType.TYPE_ENTRY, params);
+    return request.urlFor("entry", params);
   }
   
   public ResponseContext putEntry(



Mime
View raw message