Author: evan
Date: Thu Aug 28 09:46:44 2008
New Revision: 689886

URL: http://svn.apache.org/viewvc?rev=689886&view=rev
Log:
Inject List<AuthenticationHandler> instead of AuthenticationHandlerProvider. 
Makes it a little simpler to customize auth, as you are not required to 
subclass AuthenticationHandlerProvider.

If you don't use SocialApiGuiceModule, you will need to add one
extra bind statement after syncing:

   bind(new TypeLiteral<List<AuthenticationHandler>>(){}).toProvider(
       AuthenticationHandlerProvider.class

Added:
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/config/
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/config/SocialApiGuiceModuleTest.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/AuthenticationProviderHandlerTest.java
Modified:
    
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndModule.java
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationHandlerProvider.java
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationServletFilter.java

Modified: 
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndModule.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndModule.java?rev=689886&r1=689885&r2=689886&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndModule.java
 (original)
+++ 
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndModule.java
 Thu Aug 28 09:46:44 2008
@@ -21,10 +21,15 @@
 import org.apache.shindig.social.core.util.BeanJsonConverter;
 import org.apache.shindig.social.core.util.BeanXmlConverter;
 import org.apache.shindig.social.core.oauth.AnonymousAuthenticationHandler;
+import org.apache.shindig.social.core.oauth.AuthenticationHandlerProvider;
+import org.apache.shindig.social.opensocial.oauth.AuthenticationHandler;
 import org.apache.shindig.social.opensocial.service.BeanConverter;
 import org.apache.shindig.social.opensocial.service.DataServiceServletFetcher;
 
+import java.util.List;
+
 import com.google.inject.AbstractModule;
+import com.google.inject.TypeLiteral;
 import com.google.inject.name.Names;
 
 /**
@@ -32,6 +37,7 @@
  */
 public class EndToEndModule extends AbstractModule {
 
+  @Override
   protected void configure() {
     bind(String.class).annotatedWith(Names.named("shindig.canonical.json.db"))
         .toInstance("sampledata/canonicaldb.json");
@@ -45,5 +51,8 @@
     bind(Boolean.class)
         
.annotatedWith(Names.named(AnonymousAuthenticationHandler.ALLOW_UNAUTHENTICATED))
         .toInstance(Boolean.FALSE);
+
+    bind(new TypeLiteral<List<AuthenticationHandler>>(){}).toProvider(
+        AuthenticationHandlerProvider.class);
   }
 }

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java?rev=689886&r1=689885&r2=689886&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java
 Thu Aug 28 09:46:44 2008
@@ -20,14 +20,19 @@
 
 import org.apache.shindig.common.servlet.ParameterFetcher;
 import org.apache.shindig.social.core.oauth.AnonymousAuthenticationHandler;
+import org.apache.shindig.social.core.oauth.AuthenticationHandlerProvider;
 import org.apache.shindig.social.core.util.BeanJsonConverter;
 import org.apache.shindig.social.core.util.BeanXmlConverter;
+import org.apache.shindig.social.opensocial.oauth.AuthenticationHandler;
 import org.apache.shindig.social.opensocial.service.BeanConverter;
 import org.apache.shindig.social.opensocial.service.DataServiceServletFetcher;
 import org.apache.shindig.social.opensocial.service.HandlerProvider;
 import org.apache.shindig.social.sample.service.SampleContainerHandlerProvider;
 
+import java.util.List;
+
 import com.google.inject.AbstractModule;
+import com.google.inject.TypeLiteral;
 import com.google.inject.name.Names;
 
 /**
@@ -57,5 +62,8 @@
         BeanXmlConverter.class);
     
bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.json")).to(
         BeanJsonConverter.class);
+
+    bind(new TypeLiteral<List<AuthenticationHandler>>(){}).toProvider(
+        AuthenticationHandlerProvider.class);
   }
 }

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationHandlerProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationHandlerProvider.java?rev=689886&r1=689885&r2=689886&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationHandlerProvider.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationHandlerProvider.java
 Thu Aug 28 09:46:44 2008
@@ -21,10 +21,11 @@
 
 import com.google.common.collect.Lists;
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 
 import java.util.List;
 
-public class AuthenticationHandlerProvider {
+public class AuthenticationHandlerProvider implements 
Provider<List<AuthenticationHandler>> {
   protected List<AuthenticationHandler> handlers;
 
   @Inject

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationServletFilter.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationServletFilter.java?rev=689886&r1=689885&r2=689886&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationServletFilter.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/AuthenticationServletFilter.java
 Thu Aug 28 09:46:44 2008
@@ -67,8 +67,8 @@
   }
 
   @Inject
-  public void setAuthenticationHandlers(AuthenticationHandlerProvider 
handlerProvider) {
-    this.handlers = handlerProvider.get();
+  public void setAuthenticationHandlers(List<AuthenticationHandler> handlers) {
+    this.handlers = handlers;
   }
 
   public void destroy() { }

Added: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/config/SocialApiGuiceModuleTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/config/SocialApiGuiceModuleTest.java?rev=689886&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/config/SocialApiGuiceModuleTest.java
 (added)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/config/SocialApiGuiceModuleTest.java
 Thu Aug 28 09:46:44 2008
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social.core.config;
+
+import org.apache.shindig.social.core.oauth.AuthenticationHandlerProvider;
+import org.apache.shindig.social.opensocial.oauth.AuthenticationHandler;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.TypeLiteral;
+
+import junit.framework.TestCase;
+
+import java.util.List;
+
+public class SocialApiGuiceModuleTest extends TestCase {
+  private Injector injector;
+  
+  @Override public void setUp() throws Exception {
+    super.setUp();
+    injector = Guice.createInjector(new SocialApiGuiceModule());
+  }
+  
+  /**
+   * Test default auth handler injection
+   */
+  public void testAuthHandler() {
+    List<AuthenticationHandler> expected =
+        injector.getInstance(AuthenticationHandlerProvider.class).get();
+    
+    AuthenticationHandlerProvider provider =
+        injector.getInstance(AuthenticationHandlerProvider.class);
+    assertEquals(3, provider.get().size());
+
+    List<AuthenticationHandler> handlers = injector.getInstance(
+        Key.get(new TypeLiteral<List<AuthenticationHandler>>(){}));
+    
+    assertEquals(3, handlers.size());
+  }
+}

Added: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/AuthenticationProviderHandlerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/AuthenticationProviderHandlerTest.java?rev=689886&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/AuthenticationProviderHandlerTest.java
 (added)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/AuthenticationProviderHandlerTest.java
 Thu Aug 28 09:46:44 2008
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social.core.oauth;
+
+import org.apache.shindig.social.core.config.SocialApiGuiceModule;
+import org.apache.shindig.social.opensocial.oauth.AuthenticationHandler;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.TypeLiteral;
+
+import junit.framework.TestCase;
+
+import java.util.Collections;
+import java.util.List;
+
+
+public class AuthenticationProviderHandlerTest extends TestCase {
+  /**
+   * Test that existing custom handlers won't be broken with the switch
+   * to injecting List<ProviderHandler>.
+   */
+  public void testCustomHandler() {
+    Injector injector = Guice.createInjector(new SocialApiGuiceModule(),
+        new CustomAuthHandlerProviderModule());
+    
+    AuthenticationHandlerProvider provider = injector.getInstance(
+        AuthenticationHandlerProvider.class);
+    assertEquals(0, provider.get().size());
+    
+    List<AuthenticationHandler> handlers = injector.getInstance(
+        Key.get(new TypeLiteral<List<AuthenticationHandler>>(){}));
+    assertEquals(0, handlers.size());
+  }
+  
+  /**
+   * AuthenticationHandlerProvider with no handlers
+   */
+  public static class ProvidesNoHandlers extends AuthenticationHandlerProvider 
{
+    public ProvidesNoHandlers() {
+      super(null, null, null);
+    }
+    
+    @Override
+    public List<AuthenticationHandler> get() {
+      return Collections.emptyList();
+    }
+  }
+  
+  /**
+   * Module with a custom AuthenticationHandler
+   */
+  public static class CustomAuthHandlerProviderModule extends AbstractModule {
+    @Override
+    protected void configure() {
+      bind(AuthenticationHandlerProvider.class).to(ProvidesNoHandlers.class);
+    }
+  }
+}


Reply via email to