Author: hnguy
Date: Thu Feb 10 22:21:57 2011
New Revision: 1069590

URL: http://svn.apache.org/viewvc?rev=1069590&view=rev
Log:
Apply patch SHINDIG-1503 | Gadget not rendered in commoncontainer sample due to 
missing security token | From Han Nguyen

Added:
    
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/
    
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/
    
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerAuthGuiceModule.java
    
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerSecurityTokenCodec.java
    
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/TestSecurityTokenCodec.java
Modified:
    shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js

Modified: 
shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js
URL: 
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js?rev=1069590&r1=1069589&r2=1069590&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js 
(original)
+++ shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js 
Thu Feb 10 22:21:57 2011
@@ -21,10 +21,6 @@ var testConfig =  testConfig || {};
 testConfig[shindig.container.ServiceConfig.API_PATH] = '/rpc'; 
 testConfig[shindig.container.ContainerConfig.RENDER_DEBUG] = "1";
 
-//Default the security token for testing.
-shindig.auth.updateSecurityToken('john.doe:john.doe:appid:cont:url:0:default');
-
-
 //  Create the new CommonContainer 
 var CommonContainer = new shindig.container.Container(testConfig);
 

Added: 
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerAuthGuiceModule.java
URL: 
http://svn.apache.org/viewvc/shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerAuthGuiceModule.java?rev=1069590&view=auto
==============================================================================
--- 
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerAuthGuiceModule.java
 (added)
+++ 
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerAuthGuiceModule.java
 Thu Feb 10 22:21:57 2011
@@ -0,0 +1,47 @@
+/*
+ * 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.sample.commoncontainer.auth;
+
+import org.apache.shindig.auth.SecurityTokenCodec;
+
+import com.google.inject.AbstractModule;
+
+/**
+ * Add this GuiceModule to shindig-server web.xml to override the
+ * SecurityTokenCodec default implementation, DefaultSecurityTokenCodec.
+ * 
+ * <context-param>
+ *   <param-name>guice-modules</param-name>
+ *   <param-value>
+ *     ...
+ *     
org.apache.shindig.sample.commoncontainer.auth.CommonContainerAuthGuiceModule:
+ *   </param-value>
+ * </context-param>
+ * 
+ */
+public class CommonContainerAuthGuiceModule extends AbstractModule {
+
+  @Override
+  protected void configure() {
+    // override the SecurityTokenCodec default implementation,
+    // DefaultSecurityTokenCodec
+    bind(SecurityTokenCodec.class).to(CommonContainerSecurityTokenCodec.class);
+  }
+
+}

Added: 
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerSecurityTokenCodec.java
URL: 
http://svn.apache.org/viewvc/shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerSecurityTokenCodec.java?rev=1069590&view=auto
==============================================================================
--- 
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerSecurityTokenCodec.java
 (added)
+++ 
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/CommonContainerSecurityTokenCodec.java
 Thu Feb 10 22:21:57 2011
@@ -0,0 +1,83 @@
+/*
+ * 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.sample.commoncontainer.auth;
+
+import java.util.Map;
+
+import org.apache.shindig.auth.BasicSecurityTokenCodec;
+import org.apache.shindig.auth.BlobCrypterSecurityTokenCodec;
+import org.apache.shindig.auth.SecurityToken;
+import org.apache.shindig.auth.SecurityTokenCodec;
+import org.apache.shindig.auth.SecurityTokenException;
+import org.apache.shindig.common.util.Utf8UrlCoder;
+import org.apache.shindig.config.ContainerConfig;
+
+import com.google.common.base.Joiner;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * Creates a dummy security token used for testing common container sample.
+ */
+@Singleton
+public class CommonContainerSecurityTokenCodec implements SecurityTokenCodec {
+
+  private static final String SECURITY_TOKEN_TYPE = 
"gadgets.securityTokenType";
+
+  private final SecurityTokenCodec codec;
+
+  @Inject
+  public CommonContainerSecurityTokenCodec(ContainerConfig config) {
+    String tokenType = config.getString(ContainerConfig.DEFAULT_CONTAINER,
+        SECURITY_TOKEN_TYPE);
+    if ("insecure".equals(tokenType)) {
+      codec = new BasicSecurityTokenCodec();
+    } else if ("secure".equals(tokenType)) {
+      codec = new BlobCrypterSecurityTokenCodec(config);
+    } else {
+      throw new RuntimeException("Unknown security token type specified in "
+          + ContainerConfig.DEFAULT_CONTAINER + " container configuration. "
+          + SECURITY_TOKEN_TYPE + ": " + tokenType);
+    }
+  }
+
+  public SecurityToken createToken(Map<String, String> tokenParameters)
+      throws SecurityTokenException {
+    TestSecurityTokenCodec testSecurityToken = new TestSecurityTokenCodec();
+    return testSecurityToken;
+  }
+
+  public String encodeToken(SecurityToken token) throws SecurityTokenException 
{
+    if (token != null) {
+      return Joiner.on(":").join(Utf8UrlCoder.encode(token.getOwnerId()),
+          Utf8UrlCoder.encode(token.getViewerId()),
+          Utf8UrlCoder.encode(token.getAppId()),
+          Utf8UrlCoder.encode(token.getDomain()),
+          Utf8UrlCoder.encode(token.getAppUrl()),
+          Long.toString(token.getModuleId()),
+          Utf8UrlCoder.encode(token.getContainer()));
+    }
+    return null;
+  }
+
+  public Long getTokenExpiration(SecurityToken token)
+      throws SecurityTokenException {
+    return codec.getTokenExpiration(token);
+  }
+}

Added: 
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/TestSecurityTokenCodec.java
URL: 
http://svn.apache.org/viewvc/shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/TestSecurityTokenCodec.java?rev=1069590&view=auto
==============================================================================
--- 
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/TestSecurityTokenCodec.java
 (added)
+++ 
shindig/trunk/java/server/src/main/java/org/apache/shindig/sample/commoncontainer/auth/TestSecurityTokenCodec.java
 Thu Feb 10 22:21:57 2011
@@ -0,0 +1,99 @@
+/*
+ * 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.sample.commoncontainer.auth;
+
+import org.apache.shindig.auth.AbstractSecurityToken;
+import org.apache.shindig.auth.AuthenticationMode;
+import org.apache.shindig.auth.SecurityToken;
+import org.apache.shindig.config.ContainerConfig;
+
+/**
+ * A stub token, with viewer, owner and other test values needed to test the 
common container sample
+ */
+public class TestSecurityTokenCodec extends AbstractSecurityToken implements
+    SecurityToken {
+  private final String container;
+  private final long moduleId;
+  private final String appUrl;
+  private final Long expiresAt;
+
+  public TestSecurityTokenCodec() {
+    this(ContainerConfig.DEFAULT_CONTAINER);
+  }
+
+  public TestSecurityTokenCodec(String container) {
+    this(container, 0L, "http://shindig.commoncontainer.sampleURL";, null);
+  }
+
+  public TestSecurityTokenCodec(String container, long moduleId,
+      String appUrl, Long expiresAt) {
+    this.container = container;
+    this.moduleId = moduleId;
+    this.appUrl = appUrl;
+    this.expiresAt = expiresAt;
+  }
+
+  public boolean isAnonymous() {
+    return true;
+  }
+
+  public String getOwnerId() {
+    return "john.doe";
+  }
+
+  public String getViewerId() {
+    return "john.doe";
+  }
+
+  public String getAppId() {
+    return "appid";
+  }
+
+  public String getDomain() {
+    return "sampleDomain";
+  }
+
+  public String getContainer() {
+    return "default";
+  }
+
+  public String getAppUrl() {
+    return "http://shindig.commoncontainer.sampleURL";;
+  }
+
+  public long getModuleId() {
+    return 0;
+  }
+
+  public Long getExpiresAt() {
+    return null;
+  }
+
+  public String getUpdatedToken() {
+    return "";
+  }
+
+  public String getAuthenticationMode() {
+    return AuthenticationMode.UNAUTHENTICATED.name();
+  }
+
+  public String getTrustedJson() {
+    return "";
+  }
+}


Reply via email to