shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rbaxte...@apache.org
Subject svn commit: r1352277 - in /shindig/trunk/java: common/src/main/java/org/apache/shindig/auth/ gadgets/src/main/java/org/apache/shindig/gadgets/render/ gadgets/src/test/java/org/apache/shindig/gadgets/render/
Date Wed, 20 Jun 2012 19:36:49 GMT
Author: rbaxter85
Date: Wed Jun 20 19:36:48 2012
New Revision: 1352277

URL: http://svn.apache.org/viewvc?rev=1352277&view=rev
Log:
SHINDIG-1799
Committed for Brian Lillie
Pass token on listMethods to enable allowUnauthenticated=false

Modified:
    shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodec.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/DefaultServiceFetcher.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java

Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodec.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodec.java?rev=1352277&r1=1352276&r2=1352277&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodec.java
(original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodec.java
Wed Jun 20 19:36:48 2012
@@ -163,7 +163,7 @@ public class BlobCrypterSecurityTokenCod
   public String encodeToken(SecurityToken token) throws SecurityTokenException {
     if (!token.getAuthenticationMode().equals(
             AuthenticationMode.SECURITY_TOKEN_URL_PARAMETER.name())) {
-      throw new SecurityTokenException("Can only encode BlogCrypterSecurityTokens");
+      throw new SecurityTokenException("Can only encode BlobCrypterSecurityTokens");
     }
 
     // Test code sends in real AbstractTokens, they have modified time sources in them so

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/DefaultServiceFetcher.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/DefaultServiceFetcher.java?rev=1352277&r1=1352276&r2=1352277&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/DefaultServiceFetcher.java
(original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/DefaultServiceFetcher.java
Wed Jun 20 19:36:48 2012
@@ -18,13 +18,24 @@
  */
 package org.apache.shindig.gadgets.render;
 
+import static org.apache.shindig.auth.AbstractSecurityToken.Keys.APP_URL;
+import static org.apache.shindig.auth.AbstractSecurityToken.Keys.OWNER;
+import static org.apache.shindig.auth.AbstractSecurityToken.Keys.VIEWER;
 
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import static org.apache.shindig.auth.AnonymousSecurityToken.ANONYMOUS_ID;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
+import com.google.inject.Inject;
+
+import org.apache.shindig.auth.BlobCrypterSecurityToken;
+import org.apache.shindig.auth.SecurityToken;
+import org.apache.shindig.auth.SecurityTokenCodec;
+import org.apache.shindig.auth.SecurityTokenException;
 import org.apache.shindig.common.logging.i18n.MessageKeys;
 import org.apache.shindig.common.servlet.Authority;
 import org.apache.shindig.common.uri.Uri;
@@ -33,16 +44,16 @@ import org.apache.shindig.gadgets.Gadget
 import org.apache.shindig.gadgets.http.HttpFetcher;
 import org.apache.shindig.gadgets.http.HttpRequest;
 import org.apache.shindig.gadgets.http.HttpResponse;
+
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.LinkedHashMultimap;
-import com.google.common.collect.Multimap;
-import com.google.inject.Inject;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Retrieves the rpc services for a container by fetching them from the container's
@@ -72,6 +83,7 @@ public class DefaultServiceFetcher {
   private final HttpFetcher fetcher;
 
   private Authority authority;
+  private SecurityTokenCodec codec;
 
   /** @param config Container Config for looking up endpoints */
   @Inject
@@ -85,6 +97,11 @@ public class DefaultServiceFetcher {
     this.authority = authority;
   }
 
+  @Inject
+  public void setSecurityTokenCodec(SecurityTokenCodec codec) {
+    this.codec = codec;
+  }
+
   /**
    * Returns the services, keyed by endpoint for the given container.
    *
@@ -116,7 +133,7 @@ public class DefaultServiceFetcher {
       if ( endpoint.startsWith("//") && authority != null ){
         endpointVal = authority.getScheme() + ':' + endpoint;
       }
-      endpointServices.putAll(endpoint, retrieveServices(endpointVal.replace("%host%", host)));
+      endpointServices.putAll(endpoint, retrieveServices(container, endpointVal.replace("%host%",
host)));
     }
     return ImmutableMultimap.copyOf(endpointServices);
   }
@@ -132,10 +149,19 @@ public class DefaultServiceFetcher {
     return ImmutableList.of();
   }
 
-  private Set<String> retrieveServices(String endpoint) {
-    Uri url = Uri.parse(endpoint + "?method=" + SYSTEM_LIST_METHODS_METHOD);
-    HttpRequest request = new HttpRequest(url).setInternalRequest(true);
+  private Set<String> retrieveServices(String container, String endpoint) {
     try {
+      StringBuilder sb = new StringBuilder( 250 );
+      sb.append(endpoint).append( "?method=" + SYSTEM_LIST_METHODS_METHOD );
+      Map<String, String> parms = Maps.newHashMap();
+      parms.put( OWNER.getKey(), ANONYMOUS_ID );
+      parms.put( VIEWER.getKey(), ANONYMOUS_ID );
+      parms.put( APP_URL.getKey(), "0" );
+      SecurityToken token = new BlobCrypterSecurityToken(container, "*", "0", parms);
+      sb.append( "&st=" ).append( codec.encodeToken( token ));
+      Uri url = Uri.parse(sb.toString());
+      HttpRequest request = new HttpRequest(url).setInternalRequest(true);
+
       HttpResponse response = fetcher.fetch(request);
       if (response.getHttpStatusCode() == HttpResponse.SC_OK) {
         return getServicesFromJsonResponse(response.getResponseAsString());
@@ -144,6 +170,10 @@ public class DefaultServiceFetcher {
           LOG.logp(Level.SEVERE, classname, "retrieveServices", MessageKeys.HTTP_ERROR_FETCHING,
new Object[] {response.getHttpStatusCode(),endpoint});
         }
       }
+    } catch (SecurityTokenException se) {
+      if (LOG.isLoggable(Level.SEVERE)) {
+        LOG.logp(Level.SEVERE, classname, "retrieveServices", MessageKeys.FAILED_TO_FETCH_SERVICE,
new Object[] {endpoint,se.getMessage()});
+      }
     } catch (GadgetException ge) {
       if (LOG.isLoggable(Level.SEVERE)) {
         LOG.logp(Level.SEVERE, classname, "retrieveServices", MessageKeys.FAILED_TO_FETCH_SERVICE,
new Object[] {endpoint,ge.getMessage()});

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java?rev=1352277&r1=1352276&r2=1352277&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java
(original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java
Wed Jun 20 19:36:48 2012
@@ -23,6 +23,7 @@ import com.google.common.collect.Immutab
 import com.google.common.collect.LinkedHashMultimap;
 import com.google.common.collect.Multimap;
 
+import org.apache.shindig.auth.BasicSecurityTokenCodec;
 import org.apache.shindig.common.EasyMockTestCase;
 import org.apache.shindig.config.ContainerConfig;
 import org.apache.shindig.config.JsonContainerConfig;
@@ -36,8 +37,8 @@ import org.apache.shindig.gadgets.http.H
 
 import org.easymock.EasyMock;
 import org.json.JSONArray;
-import org.json.JSONObject;
 import org.json.JSONException;
+import org.json.JSONObject;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -115,6 +116,7 @@ public class DefaultServiceFetcherTest e
     EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn(
         new HttpResponse("")).anyTimes();
     replay();
+    fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() );
     Multimap<String, String> services = fetcher.getServicesForContainer("default",
"dontcare");
     verify();
     assertEquals(configuredServices, services);
@@ -136,6 +138,7 @@ public class DefaultServiceFetcherTest e
         new HttpResponse(service2.toString()));
 
     replay();
+    fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() );
     Multimap<String, String> services = fetcher.getServicesForContainer("default",
"dontcare");
     verify();
     Multimap<String, String> mergedServices = LinkedHashMultimap.create(configuredServices);
@@ -163,6 +166,7 @@ public class DefaultServiceFetcherTest e
             Expressions.forTesting(new Functions()));
     CapturingHttpFetcher httpFetcher = new CapturingHttpFetcher();
     fetcher = new DefaultServiceFetcher(containerConfig, httpFetcher);
+    fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() );
     Multimap<String, String> services = fetcher.getServicesForContainer("default",
"dontcare");
     assertEquals(configuredServices, services);
     assertNotNull( httpFetcher.request );



Mime
View raw message