abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1195048 - in /abdera/abdera2: common/src/main/java/org/apache/abdera2/common/security/ examples/src/main/java/org/apache/abdera2/examples/activities/ examples/src/main/java/org/apache/abdera2/examples/ext/ examples/src/main/java/org/apache...
Date Sat, 29 Oct 2011 21:51:18 GMT
Author: jmsnell
Date: Sat Oct 29 21:51:17 2011
New Revision: 1195048

URL: http://svn.apache.org/viewvc?rev=1195048&view=rev
Log:
Few example updates

Added:
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/ApiKeyExample.java
  (with props)
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java
  (with props)
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/OtpExample.java
  (with props)
Modified:
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/ApiKey.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyBase.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyHelper.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/FeedToStreamConversionExample.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GeneratorStreamingExample.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Bidi.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Features.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Json.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/License.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Paging.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/ApiKey.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/ApiKey.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/ApiKey.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/ApiKey.java Sat
Oct 29 21:51:17 2011
@@ -71,6 +71,10 @@ public class ApiKey extends KeyBase {
     return Hex.encodeHexString(buf);
   }
   
+  public Supplier<String> asSupplier() {
+    return supplier(this);
+  }
+  
   public static ApiKey WEAK(byte[] key) {
     return new ApiKey(key,"HmacSHA1",20);
   }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyBase.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyBase.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyBase.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyBase.java Sat
Oct 29 21:51:17 2011
@@ -7,7 +7,10 @@ import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.commons.codec.binary.Hex;
 
-public abstract class KeyBase {
+import com.google.common.base.Supplier;
+
+public abstract class KeyBase 
+  implements Supplier<String> {
 
   public static final String DEFAULT_ALG="HmacSHA256";
   public static final int DEFAULT_SIZE=256;
@@ -18,6 +21,10 @@ public abstract class KeyBase {
   
   public abstract String generateNext();
   
+  public String get() {
+    return generateNext();
+  }
+  
   public KeyBase(Key key) {
     this(key,DEFAULT_ALG,DEFAULT_SIZE);
   }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyHelper.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyHelper.java
(original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyHelper.java
Sat Oct 29 21:51:17 2011
@@ -156,6 +156,7 @@ public final class KeyHelper {
         Class<?> provider = Class.forName(className);
         return prepareJceProvider(provider);
       } catch (Exception e) {
+        e.printStackTrace();
         return false;
       }
     }

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/FeedToStreamConversionExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/FeedToStreamConversionExample.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/FeedToStreamConversionExample.java
(original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/FeedToStreamConversionExample.java
Sat Oct 29 21:51:17 2011
@@ -3,9 +3,6 @@ package org.apache.abdera2.examples.acti
 import java.net.URL;
 
 import org.apache.abdera2.Abdera;
-import org.apache.abdera2.activities.model.CollectionWriter;
-import org.apache.abdera2.activities.model.IO;
-import org.apache.abdera2.ext.activities.FeedToActivityConverter;
 import org.apache.abdera2.model.Document;
 import org.apache.abdera2.model.Feed;
 import org.apache.abdera2.parser.Parser;
@@ -21,15 +18,8 @@ public class FeedToStreamConversionExamp
     ParserOptions options = parser.getDefaultParserOptions();
     options.setCharset("UTF-8");
     Document<Feed> doc = abdera.getParser().parse(url.openStream(),url.toString(),options);
-    Feed feed = doc.getRoot();
-
-    FeedToActivityConverter c = new FeedToActivityConverter() {};
-
-    IO io = IO.get();
-
-    CollectionWriter cw = io.getCollectionWriter(System.out, "UTF-8");
-
-    c.convert(feed, cw);
+    Feed feed = doc.getRoot();    
+    feed.writeTo("activity", System.out);
     
   }
   

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GeneratorStreamingExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GeneratorStreamingExample.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GeneratorStreamingExample.java
(original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GeneratorStreamingExample.java
Sat Oct 29 21:51:17 2011
@@ -37,13 +37,16 @@ public class GeneratorStreamingExample {
     writer.writeHeader(header);
     
     // Prepare the Activity template
-    Activity template = new Activity();
-    PersonObject person = new PersonObject();
-    person.setDisplayName("joe");
-    template.setActor(person);
-    template.setVerb(Verb.POST);
-    template.setProvider(
-      new ServiceObject("My Application"));
+    PersonObject person = 
+      new PersonObject();
+    Activity template = 
+      Activity.makeActivity()
+        .actor(person)
+        .verb(Verb.POST)
+        .provider(
+          new ServiceObject("My Application"))
+        .displayName("joe")
+        .get();
     Generator<Activity> gen = 
       template.newGenerator();
     
@@ -75,9 +78,8 @@ public class GeneratorStreamingExample {
     Collection<Activity> col = io.readCollection(in, "UTF-8");
     System.out.println(col.getProperty("title"));
     System.out.println(col.getTotalItems());
-    for (Activity a : col.getItems()) {
+    for (Activity a : col.getItems())
       System.out.println(a.getTitle() + "\t" + a.getVerb());
-    }
   }
   
 }

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java
(original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java
Sat Oct 29 21:51:17 2011
@@ -2,7 +2,6 @@ package org.apache.abdera2.examples.acti
 
 import org.apache.abdera2.activities.extra.Extra;
 import org.apache.abdera2.activities.model.Activity;
-import org.apache.abdera2.activities.model.Activity.Audience;
 import org.apache.abdera2.activities.model.objects.NoteObject;
 import org.apache.abdera2.activities.model.objects.PersonObject;
 
@@ -10,19 +9,18 @@ public class RepliesAndTargetingExample 
 
   public static void main(String... args) throws Exception {
     
-    
-    Activity activity = new Activity();
-    
-    // Specify the audience
-    activity.addAudience(Audience.TO, new PersonObject("bob"));
-    activity.addAudience(Audience.CC, Extra.FRIENDS("Colleagues"));
-    activity.addAudience(Audience.BTO, new PersonObject("sally"));
-    activity.addAudience(Audience.BCC, Extra.NETWORK());
-    
-    // Indicate that this is a reply to something else
-    NoteObject note = new NoteObject();
-    note.setId("urn:foo:note:1");
-    activity.addInReplyTo(note);
+    Activity activity = 
+      Activity.makeActivity()
+        .to(new PersonObject("bob"))
+        .cc(Extra.FRIENDS("Colleagues"))
+        .bto(new PersonObject("sally"))
+        .bcc(Extra.NETWORK())
+        .inReplyTo(
+          NoteObject
+            .makeNote()
+            .id("urn:foo:note:1")
+          .get())
+        .get();
     
     activity.writeTo(System.out);
     

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Bidi.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Bidi.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Bidi.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Bidi.java Sat Oct
29 21:51:17 2011
@@ -18,8 +18,7 @@
 package org.apache.abdera2.examples.ext;
 
 import org.apache.abdera2.Abdera;
-import org.apache.abdera2.ext.bidi.BidiHelper;
-import org.apache.abdera2.ext.bidi.BidiHelper.Direction;
+import static org.apache.abdera2.ext.bidi.BidiHelper.*;
 import org.apache.abdera2.model.Entry;
 
 /**
@@ -34,27 +33,27 @@ public class Bidi {
 
         Abdera abdera =Abdera.getInstance();
         Entry entry = abdera.newEntry();
-        BidiHelper.setDirection(Direction.RTL, entry);
-
+        setDirection(Direction.RTL, entry);
+        
         entry.setTitle(text);
 
         // non bidi, incorrectly displayed
         System.out.println(entry.getTitle());
 
         // with bidi, correctly displayed
-        System.out.println(BidiHelper.getBidiElementText(entry.getTitleElement()));
+        System.out.println(getBidiElementText(entry.getTitleElement()));
 
         // with bidi, correctly displayed
-        System.out.println(BidiHelper.getBidiText(BidiHelper.getDirection(entry), entry.getTitle()));
+        System.out.println(getBidiText(getDirection(entry), entry.getTitle()));
 
         // there are also direction guessing algorithms available
         entry = abdera.newEntry();
         entry.setTitle(text);
         entry.setLanguage("ar");
 
-        System.out.println(BidiHelper.guessDirectionFromJavaBidi(entry.getTitleElement()));
-        System.out.println(BidiHelper.guessDirectionFromTextProperties(entry.getTitleElement()));
-        System.out.println(BidiHelper.guessDirectionFromLanguage(entry.getTitleElement()));
+        System.out.println(guessDirectionFromJavaBidi(entry.getTitleElement()));
+        System.out.println(guessDirectionFromTextProperties(entry.getTitleElement()));
+        System.out.println(guessDirectionFromLanguage(entry.getTitleElement()));
     }
 
 }

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Features.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Features.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Features.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Features.java Sat
Oct 29 21:51:17 2011
@@ -20,7 +20,7 @@ package org.apache.abdera2.examples.ext;
 import org.apache.abdera2.Abdera;
 import org.apache.abdera2.ext.features.Feature;
 import org.apache.abdera2.ext.features.FeatureSelector;
-import org.apache.abdera2.ext.features.FeaturesHelper;
+import static org.apache.abdera2.ext.features.FeaturesHelper.*;
 import org.apache.abdera2.model.Collection;
 import org.apache.abdera2.model.Service;
 import org.apache.abdera2.model.Workspace;
@@ -39,28 +39,28 @@ public class Features {
         Collection collection = workspace.addCollection("My collection", "foo");
 
         // Specify which features are supported by the collection
-        org.apache.abdera2.ext.features.Features features = FeaturesHelper.addFeaturesElement(collection);
-        features.addFeature(FeaturesHelper.FEATURE_SUPPORTS_DRAFTS);
-        features.addFeature(FeaturesHelper.FEATURE_REQUIRES_TEXT_TEXT);
-        features.addFeature(FeaturesHelper.FEATURE_IGNORES_SLUG);
-        features.addFeature(FeaturesHelper.FEATURE_SUPPORTS_BIDI);
+        org.apache.abdera2.ext.features.Features features = addFeaturesElement(collection);
+        features.addFeature(FEATURE_SUPPORTS_DRAFTS);
+        features.addFeature(FEATURE_REQUIRES_TEXT_TEXT);
+        features.addFeature(FEATURE_IGNORES_SLUG);
+        features.addFeature(FEATURE_SUPPORTS_BIDI);
 
         // Get the support status of a specific feature
-        System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.FEATURE_SUPPORTS_DRAFTS));
-        System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.FEATURE_REQUIRES_TEXT_TEXT));
-        System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.FEATURE_IGNORES_SLUG));
-        System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.FEATURE_SUPPORTS_BIDI));
-        System.out.println(FeaturesHelper.getFeatureStatus(collection, FeaturesHelper.FEATURE_SUPPORTS_GEO));
+        System.out.println(getFeatureStatus(collection, FEATURE_SUPPORTS_DRAFTS));
+        System.out.println(getFeatureStatus(collection, FEATURE_REQUIRES_TEXT_TEXT));
+        System.out.println(getFeatureStatus(collection, FEATURE_IGNORES_SLUG));
+        System.out.println(getFeatureStatus(collection, FEATURE_SUPPORTS_BIDI));
+        System.out.println(getFeatureStatus(collection, FEATURE_SUPPORTS_GEO));
 
-        Iterable<Feature> fs = FeaturesHelper.getFeatures(collection);
-        for (Feature feature : fs) {
+        Iterable<Feature> fs = getFeatures(collection);
+        for (Feature feature : fs)
             System.out.println("\t" + feature.getRef());
-        }
 
         // Select a collection by feature
         Iterable<Collection> selectedCollections =
-            FeaturesHelper.select(service, new FeatureSelector(FeaturesHelper.FEATURE_SUPPORTS_DRAFTS,
-                                                               FeaturesHelper.FEATURE_SUPPORTS_BIDI));
+            select(service, new FeatureSelector(
+              FEATURE_SUPPORTS_DRAFTS,
+              FEATURE_SUPPORTS_BIDI));
         System.out.println("Selected Collections:");
         for (Collection selected : selectedCollections)
             System.out.println("\t" + selected.getTitle());

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Json.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Json.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Json.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Json.java Sat Oct
29 21:51:17 2011
@@ -27,6 +27,15 @@ public class Json {
 
     public static void main(String... args) throws Exception {
 
+        /**
+         * NOTE: If you need to convert and Atom Feed to JSON, consider
+         * using the Activity Streams "activity" writer as an alternative to this.
+         * The Activity Streams format is a standard and defines a 
+         * mapping between Atom and JSON that is much more efficient and
+         * useful than the generic output the "json" writer used here
+         * does.
+         */
+      
         Abdera abdera =Abdera.getInstance();
         Entry entry = abdera.newEntry();
         entry.newId();

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/License.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/License.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/License.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/License.java Sat
Oct 29 21:51:17 2011
@@ -18,7 +18,7 @@
 package org.apache.abdera2.examples.ext;
 
 import org.apache.abdera2.Abdera;
-import org.apache.abdera2.ext.license.LicenseHelper;
+import static org.apache.abdera2.ext.license.LicenseHelper.*;
 import org.apache.abdera2.model.Entry;
 import org.apache.abdera2.model.Feed;
 import org.apache.abdera2.model.Link;
@@ -36,29 +36,28 @@ public class License {
         Entry entry = feed.addEntry();
 
         // Add a license to the feed
-        LicenseHelper.addLicense(feed, "http://example.org/foo", "Foo");
+        addLicense(feed, "http://example.org/foo", "Foo");
 
         // does the feed have a license link?
-        System.out.println(LicenseHelper.hasLicense(feed));
+        System.out.println(hasLicense(feed));
 
         // does the feed have a specific license link?
-        System.out.println(LicenseHelper.hasLicense(feed, "http://example.org/foo"));
+        System.out.println(hasLicense(feed, "http://example.org/foo"));
 
         // since the entry does not have a license, it inherits the feeds
-        System.out.println(LicenseHelper.hasLicense(entry));
-        System.out.println(LicenseHelper.hasLicense(entry, "http://example.org/foo"));
+        System.out.println(hasLicense(entry));
+        System.out.println(hasLicense(entry, "http://example.org/foo"));
 
         // list the licenses
-        Iterable<Link> licenses = LicenseHelper.getLicense(entry);
-        for (Link link : licenses) {
+        Iterable<Link> licenses = getLicense(entry);
+        for (Link link : licenses)
             System.out.println(link.getResolvedHref());
-        }
 
         // Add an unspecified license to the entry
-        LicenseHelper.addUnspecifiedLicense(entry);
+        addUnspecifiedLicense(entry);
 
         // now the entry does not inherit the feeds license
-        System.out.println(LicenseHelper.hasLicense(entry, "http://example.org/foo"));
+        System.out.println(hasLicense(entry, "http://example.org/foo"));
 
     }
 

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Paging.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Paging.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Paging.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Paging.java Sat
Oct 29 21:51:17 2011
@@ -20,7 +20,7 @@ package org.apache.abdera2.examples.ext;
 import org.apache.abdera2.Abdera;
 import org.apache.abdera2.common.templates.MapContext;
 import org.apache.abdera2.common.templates.Template;
-import org.apache.abdera2.ext.history.FeedPagingHelper;
+import static org.apache.abdera2.ext.history.FeedPagingHelper.*;
 import org.apache.abdera2.model.Feed;
 
 public class Paging {
@@ -41,30 +41,30 @@ public class Paging {
         
 
         // Set/Get the paging links
-        FeedPagingHelper.setCurrent(feed, gen(-1));
-        FeedPagingHelper.setNext(feed, gen(3));
-        FeedPagingHelper.setPrevious(feed, gen(1));
-        FeedPagingHelper.setFirst(feed, gen(-1));
-        FeedPagingHelper.setLast(feed, gen(10));
-        FeedPagingHelper.setNextArchive(feed, gen(3));
-        FeedPagingHelper.setPreviousArchive(feed, gen(1));
-
-        System.out.println(FeedPagingHelper.getCurrent(feed));
-        System.out.println(FeedPagingHelper.getNext(feed));
-        System.out.println(FeedPagingHelper.getPrevious(feed));
-        System.out.println(FeedPagingHelper.getFirst(feed));
-        System.out.println(FeedPagingHelper.getLast(feed));
-        System.out.println(FeedPagingHelper.getNextArchive(feed));
-        System.out.println(FeedPagingHelper.getPreviousArchive(feed));
+        setCurrent(feed, gen(-1));
+        setNext(feed, gen(3));
+        setPrevious(feed, gen(1));
+        setFirst(feed, gen(-1));
+        setLast(feed, gen(10));
+        setNextArchive(feed, gen(3));
+        setPreviousArchive(feed, gen(1));
+
+        System.out.println(getCurrent(feed));
+        System.out.println(getNext(feed));
+        System.out.println(getPrevious(feed));
+        System.out.println(getFirst(feed));
+        System.out.println(getLast(feed));
+        System.out.println(getNextArchive(feed));
+        System.out.println(getPreviousArchive(feed));
 
         // Set/Get the archive flag
-        FeedPagingHelper.setArchive(feed, true);
-        if (FeedPagingHelper.isArchive(feed))
+        setArchive(feed, true);
+        if (isArchive(feed))
             System.out.println("archive feed!");
 
         // Set/Get the complete flag
-        FeedPagingHelper.setComplete(feed, true);
-        if (FeedPagingHelper.isComplete(feed))
+        setComplete(feed, true);
+        if (isComplete(feed))
             System.out.println("complete feed!");
 
     }

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java?rev=1195048&r1=1195047&r2=1195048&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java Sat
Oct 29 21:51:17 2011
@@ -19,7 +19,7 @@ package org.apache.abdera2.examples.ext;
 
 import org.apache.abdera2.Abdera;
 import org.apache.abdera2.ext.thread.InReplyTo;
-import org.apache.abdera2.ext.thread.ThreadHelper;
+import static org.apache.abdera2.ext.thread.ThreadHelper.*;
 import org.apache.abdera2.model.Entry;
 import org.apache.abdera2.model.Link;
 
@@ -39,20 +39,20 @@ public class Thread {
         e2.newId();
 
         // Entry e2 is a reply to Entry e1
-        ThreadHelper.addInReplyTo(e2, e1);
+        addInReplyTo(e2, e1);
 
         // Get the in-reply-to information
-        InReplyTo irt = ThreadHelper.getInReplyTo(e2);
+        InReplyTo irt = getInReplyTo(e2);
         System.out.println(irt.getRef());
 
         // Add a link to a feed containing replies to e1
         Link replies = e1.addLink("replies.xml", Link.REL_REPLIES);
 
         // Set the known number of replies as an attribute on the link
-        ThreadHelper.setCount(replies, 10);
+        setCount(replies, 10);
 
         // alternatively, use the thr:total element to specify the number of replies
-        ThreadHelper.addTotal(e1, 10);
+        addTotal(e1, 10);
 
     }
 

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/ApiKeyExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/ApiKeyExample.java?rev=1195048&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/ApiKeyExample.java
(added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/ApiKeyExample.java
Sat Oct 29 21:51:17 2011
@@ -0,0 +1,42 @@
+package org.apache.abdera2.examples.security;
+
+import org.apache.abdera2.common.security.ApiKey;
+
+import com.google.common.base.Supplier;
+
+public class ApiKeyExample {
+
+  public static void main(String... args) throws Exception {
+    
+    // Many REST-apis deployed today employ random, cryptographically
+    // generated API Keys used for keeping track of api calls and 
+    // monitoring quotas, etc. Abdera includes a simple Api Key 
+    // generator that can be used to generate several variations of
+    // random strings usable as API Keys. The generated values are
+    // cryptographically derived from a given key and can vary in 
+    // size. 
+    
+    byte[] key = new byte[] {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0};
+
+    ApiKey apikey = ApiKey.STRONG(key);
+    
+    System.out.println(apikey.generateNext());
+    
+    // You can use the Guava Library Supplier interface also...
+    
+    Supplier<String> sup = apikey.asSupplier();
+    System.out.println(sup.get()); // every call generates a new 
+    System.out.println(sup.get()); // random api key string
+    
+    // instances of the ApiKey and the supplier are immutable and
+    // threadsafe..
+    
+    // the generated api keys are guaranteed to only contain characters
+    // that are safe for use within URL's, so they can easily be passed
+    // around in URL Query String parameters as is typical of most API
+    // key usage scenarios
+    
+    
+  }
+  
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/ApiKeyExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java?rev=1195048&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java
(added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java
Sat Oct 29 21:51:17 2011
@@ -0,0 +1,38 @@
+package org.apache.abdera2.examples.security;
+
+import java.security.KeyPair;
+
+import org.apache.abdera2.activities.extra.Jwt;
+import org.apache.abdera2.activities.model.Activity;
+import org.apache.abdera2.activities.model.Verb;
+import org.apache.abdera2.common.security.KeyHelper;
+
+/**
+ * The Abdera Activity Streams implementation includes
+ * basic support for the JSON Web Tokens (JWT) spec.
+ * This essentially gives us digital signatures for 
+ * Activities / JSON. The mechanism can generate and 
+ * validate JWT's using a supplier key pair
+ */
+public class JwtExample {
+
+  public static void main(String... args) throws Exception {
+   
+    KeyHelper.prepareDefaultJceProvider();
+    
+    KeyPair pair = KeyHelper.generateKeyPair("RSA", 1024);
+
+    Activity activity = new Activity();
+    activity.setVerb(Verb.POST);
+
+    String jwt = Jwt.generate(pair.getPrivate(), activity);
+    
+    System.out.println(jwt);
+
+    activity = (Activity) Jwt.getClaimIfValid(pair.getPrivate(), jwt);  
+    
+    System.out.println(activity);
+    
+  }
+  
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/OtpExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/OtpExample.java?rev=1195048&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/OtpExample.java
(added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/OtpExample.java
Sat Oct 29 21:51:17 2011
@@ -0,0 +1,105 @@
+package org.apache.abdera2.examples.security;
+
+import java.security.Key;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.abdera2.common.security.Otp;
+import com.google.common.base.Supplier;
+
+/**
+ * Abdera includes a simple One-time-password generator
+ * that can be used in a variety of scenarios to enhance 
+ * security through two-factor authentication. 
+ */
+public class OtpExample {
+
+  public static void main(String... args) throws Exception {
+    
+    // the time-based one-time-password uses time as the 
+    // moving factor. so long as two parties have the same
+    // source key and synchronize their clocks, they will
+    // be able to generate the same one-time-password for 
+    // the same window of time (in this example, the window
+    // changes every 30 seconds). 
+    
+    // OTP generators are immutable and threadsafe.
+    
+    byte[] key = new byte[] {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0};
+
+    Otp.Totp totp = new Otp.Totp(30, key);
+
+    System.out.println(totp.generateNext());
+    
+    
+    // We can also use the Guava libraries supplier interface...
+    
+    Supplier<String> otp = Otp.totpSupplier(key, 30);
+    System.out.println(otp.get());
+    
+    // Use your own OTP if you'd like...
+    
+    otp = Otp.supplier(new MyOtp(key));
+    System.out.println(otp.get()); // with this one,
+    System.out.println(otp.get()); // the otp changes
+    System.out.println(otp.get()); // every call because
+    System.out.println(otp.get()); // of the counter
+    
+  }
+  
+  /** 
+   * You can easily implement your own OTP based on 
+   * other moving factors... such as this counter
+   * based otp
+   */
+  public static class MyOtp extends Otp {
+
+    public MyOtp(byte[] key, int size) {
+      super(key, size);
+    }
+
+    public MyOtp(byte[] key, String alg, int size) {
+      super(key, alg, size);
+    }
+
+    public MyOtp(byte[] key) {
+      super(key);
+    }
+
+    public MyOtp(Key key, int size) {
+      super(key, size);
+    }
+
+    public MyOtp(Key key, String alg, int size) {
+      super(key, alg, size);
+    }
+
+    public MyOtp(Key key) {
+      super(key);
+    }
+
+    public MyOtp(String key, int size) {
+      super(key, size);
+    }
+
+    public MyOtp(String key, String alg, int size) {
+      super(key, alg, size);
+    }
+
+    public MyOtp(String key) {
+      super(key);
+    }
+
+    private final AtomicInteger counter = new AtomicInteger();
+    
+    @Override
+    protected byte[] getMovingFactor() {
+      int val = counter.incrementAndGet();
+      return new byte[] {
+          (byte)(val >>> 24),
+          (byte)(val >>> 16),
+          (byte)(val >>> 8),
+          (byte)val};
+    }
+    
+  }
+  
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/OtpExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message