You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by zh...@apache.org on 2010/07/22 04:36:15 UTC
svn commit: r966481 - in /shindig/trunk: ./
java/common/src/main/java/org/apache/shindig/auth/
java/common/src/main/java/org/apache/shindig/protocol/
java/common/src/test/java/org/apache/shindig/auth/
java/common/src/test/java/org/apache/shindig/common...
Author: zhoresh
Date: Thu Jul 22 02:36:14 2010
New Revision: 966481
URL: http://svn.apache.org/viewvc?rev=966481&view=rev
Log:
Rename of Decoder to Codec
Patch by mhermanto http://codereview.appspot.com/1864043/show
Added:
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BasicSecurityTokenCodec.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodec.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/DefaultSecurityTokenCodec.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenCodec.java
shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodecTest.java
shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenCodecTest.java
Removed:
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BasicSecurityTokenDecoder.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityTokenDecoder.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/DefaultSecurityTokenDecoder.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenDecoder.java
shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenDecoderTest.java
shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenDecoderTest.java
Modified:
shindig/trunk/UPGRADING
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityToken.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityToken.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenException.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/UrlParameterAuthenticationHandler.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServletFetcher.java
shindig/trunk/java/common/src/test/java/org/apache/shindig/common/testing/FakeGadgetToken.java
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/ShindigAuthConfigContributor.java
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetsHandler.java
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/GadgetsHandlerTest.java
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManagerTest.java
shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
Modified: shindig/trunk/UPGRADING
URL: http://svn.apache.org/viewvc/shindig/trunk/UPGRADING?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/UPGRADING (original)
+++ shindig/trunk/UPGRADING Thu Jul 22 02:36:14 2010
@@ -123,6 +123,12 @@ The long value annotated with the name "
been moved to shindig/common/conf/shindig.properties. Guice 2.0 can inject Long values from Strings
automatically.
+* Rename SecurityTokenDecoder to SecurityTokenCodec
+
+This class is renamed to provide a single place to capture both encoding and decoding work
+for gadget security tokens. This also affects classes previously implementing SecurityTokenDecoder
+and previously extending DefaultSecurityTokenDecoder.
+
== PHP Changes ==
TBD
Added: shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BasicSecurityTokenCodec.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BasicSecurityTokenCodec.java?rev=966481&view=auto
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BasicSecurityTokenCodec.java (added)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BasicSecurityTokenCodec.java Thu Jul 22 02:36:14 2010
@@ -0,0 +1,105 @@
+/*
+ * 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.auth;
+
+import org.apache.shindig.common.crypto.BlobCrypterException;
+import org.apache.shindig.common.util.Utf8UrlCoder;
+import org.apache.commons.lang.StringUtils;
+
+import com.google.common.base.Joiner;
+import com.google.inject.Singleton;
+
+import java.util.Map;
+
+/**
+ * A SecurityTokenCodec implementation that just provides dummy data to satisfy
+ * tests and API calls. Do not use this for any security applications.
+ */
+@Singleton
+public class BasicSecurityTokenCodec implements SecurityTokenCodec {
+
+ private static final int OWNER_INDEX = 0;
+ private static final int VIEWER_INDEX = 1;
+ private static final int APP_ID_INDEX = 2;
+ private static final int DOMAIN_INDEX = 3;
+ private static final int APP_URL_INDEX = 4;
+ private static final int MODULE_ID_INDEX = 5;
+ private static final int CONTAINER_ID_INDEX = 6;
+ private static final int TOKEN_COUNT = CONTAINER_ID_INDEX + 1;
+
+ /**
+ * Encodes a token using the a plaintext dummy format.
+ * @param token token to encode
+ * @return token with values separated by colons
+ */
+ public String encodeToken(SecurityToken token) {
+ 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()));
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * Returns a token with some faked out values.
+ */
+ public SecurityToken createToken(Map<String, String> parameters)
+ throws SecurityTokenException {
+
+ final String token = parameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME);
+ if (token == null || token.trim().length() == 0) {
+ // No token is present, assume anonymous access
+ return new AnonymousSecurityToken();
+ }
+
+ try {
+ String[] tokens = StringUtils.split(token, ':');
+ if (tokens.length != TOKEN_COUNT) {
+ throw new SecurityTokenException("Malformed security token");
+ }
+
+ return new BasicSecurityToken(
+ Utf8UrlCoder.decode(tokens[OWNER_INDEX]),
+ Utf8UrlCoder.decode(tokens[VIEWER_INDEX]),
+ Utf8UrlCoder.decode(tokens[APP_ID_INDEX]),
+ Utf8UrlCoder.decode(tokens[DOMAIN_INDEX]),
+ Utf8UrlCoder.decode(tokens[APP_URL_INDEX]),
+ Utf8UrlCoder.decode(tokens[MODULE_ID_INDEX]),
+ Utf8UrlCoder.decode(tokens[CONTAINER_ID_INDEX]),
+ parameters.get(SecurityTokenCodec.ACTIVE_URL_NAME),
+ null);
+ } catch (BlobCrypterException e) {
+ throw new SecurityTokenException(e);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new SecurityTokenException(e);
+ }
+ }
+
+ /**
+ * Creates a signer with 24 hour token expiry
+ */
+ public BasicSecurityTokenCodec() {
+ }
+}
Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityToken.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityToken.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityToken.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityToken.java Thu Jul 22 02:36:14 2010
@@ -70,7 +70,7 @@ public class BlobCrypterSecurityToken ex
}
/**
- * Decrypt and verify a token. Note this is not public, use BlobCrypterSecurityTokenDecoder
+ * Decrypt and verify a token. Note this is not public, use BlobCrypterSecurityTokenCodec
* instead.
*
* @param crypter crypter to use for decryption
Added: 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=966481&view=auto
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodec.java (added)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodec.java Thu Jul 22 02:36:14 2010
@@ -0,0 +1,134 @@
+/*
+ * 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.auth;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.shindig.common.crypto.BasicBlobCrypter;
+import org.apache.shindig.common.crypto.BlobCrypter;
+import org.apache.shindig.common.crypto.BlobCrypterException;
+import org.apache.shindig.config.ContainerConfig;
+
+import com.google.common.collect.Maps;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Provides security token decoding services. Configuration is via containers.js. Each container
+ * should specify (or inherit)
+ *
+ * securityTokenKeyFile: path to file containing a key to use for verifying tokens.
+ * signedFetchDomain: oauth_consumer_key value to use for signed fetch using default key.
+ *
+ * Creating a key is best done with a command line like this:
+ * <pre>
+ * dd if=/dev/random bs=32 count=1 | openssl base64 > /tmp/key.txt
+ * </pre>
+ * Wire format is "<container>:<encrypted-and-signed-token>"
+ */
+@Singleton
+public class BlobCrypterSecurityTokenCodec implements SecurityTokenCodec {
+
+ public static final String SECURITY_TOKEN_KEY_FILE = "gadgets.securityTokenKeyFile";
+
+ public static final String SIGNED_FETCH_DOMAIN = "gadgets.signedFetchDomain";
+
+ /**
+ * Keys are container ids, values are crypters
+ */
+ protected final Map<String, BlobCrypter> crypters = Maps.newHashMap();
+
+ /**
+ * Keys are container ids, values are domains used for signed fetch.
+ */
+ protected final Map<String, String> domains = Maps.newHashMap();
+
+ @Inject
+ public BlobCrypterSecurityTokenCodec(ContainerConfig config) {
+ try {
+ for (String container : config.getContainers()) {
+ String keyFile = config.getString(container, SECURITY_TOKEN_KEY_FILE);
+ if (keyFile != null) {
+ BlobCrypter crypter = loadCrypterFromFile(new File(keyFile));
+ crypters.put(container, crypter);
+ }
+ String domain = config.getString(container, SIGNED_FETCH_DOMAIN);
+ domains.put(container, domain);
+ }
+ } catch (IOException e) {
+ // Someone specified securityTokenKeyFile, but we couldn't load the key. That merits killing
+ // the server.
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Load a BlobCrypter from the specified file. Override this if you have your own
+ * BlobCrypter implementation.
+ */
+ protected BlobCrypter loadCrypterFromFile(File file) throws IOException {
+ return new BasicBlobCrypter(file);
+ }
+
+ /**
+ * Decrypt and verify the provided security token.
+ */
+ public SecurityToken createToken(Map<String, String> tokenParameters)
+ throws SecurityTokenException {
+ String token = tokenParameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME);
+ if (StringUtils.isBlank(token)) {
+ // No token is present, assume anonymous access
+ return new AnonymousSecurityToken();
+ }
+ String[] fields = StringUtils.split(token, ':');
+ if (fields.length != 2) {
+ throw new SecurityTokenException("Invalid security token " + token);
+ }
+ String container = fields[0];
+ BlobCrypter crypter = crypters.get(container);
+ if (crypter == null) {
+ throw new SecurityTokenException("Unknown container " + token);
+ }
+ String domain = domains.get(container);
+ String activeUrl = tokenParameters.get(SecurityTokenCodec.ACTIVE_URL_NAME);
+ String crypted = fields[1];
+ try {
+ return BlobCrypterSecurityToken.decrypt(crypter, container, domain, crypted, activeUrl);
+ } catch (BlobCrypterException e) {
+ throw new SecurityTokenException(e);
+ }
+ }
+
+ public String encodeToken(SecurityToken token) throws SecurityTokenException {
+ if (! (token instanceof BlobCrypterSecurityToken)) {
+ throw new SecurityTokenException("Can only encode BlogCrypterSecurityTokens");
+ }
+
+ BlobCrypterSecurityToken t = (BlobCrypterSecurityToken)token;
+
+ try {
+ return t.encrypt();
+ } catch (BlobCrypterException e) {
+ throw new SecurityTokenException(e);
+ }
+ }
+}
Added: shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/DefaultSecurityTokenCodec.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/DefaultSecurityTokenCodec.java?rev=966481&view=auto
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/DefaultSecurityTokenCodec.java (added)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/DefaultSecurityTokenCodec.java Thu Jul 22 02:36:14 2010
@@ -0,0 +1,75 @@
+/*
+ * 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.auth;
+
+import org.apache.shindig.config.ContainerConfig;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+import java.util.Map;
+
+/**
+ * Default implementation of security tokens. Decides based on default container configuration
+ * whether to use real crypto for security tokens or to use a simple insecure implementation that
+ * is useful for testing.
+ *
+ * Example configuration in container.js for insecure security tokens:
+ * gadgets.securityTokenType = insecure
+ *
+ * Example configuration in container.js for blob crypter based security tokens:
+ * gadgets.securityTokenType = secure
+ *
+ * The insecure implementation is BasicSecurityTokenCodec.
+ *
+ * The secure implementation is BlobCrypterSecurityTokenCodec.
+ */
+@Singleton
+public class DefaultSecurityTokenCodec implements SecurityTokenCodec {
+
+ private static final String SECURITY_TOKEN_TYPE = "gadgets.securityTokenType";
+
+ private final SecurityTokenCodec codec;
+
+ @Inject
+ public DefaultSecurityTokenCodec(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 {
+ return codec.createToken(tokenParameters);
+ }
+
+ public String encodeToken(SecurityToken token) throws SecurityTokenException {
+ if (token == null) {
+ return null;
+ }
+ return codec.encodeToken(token);
+ }
+}
Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityToken.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityToken.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityToken.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityToken.java Thu Jul 22 02:36:14 2010
@@ -20,7 +20,7 @@ package org.apache.shindig.auth;
/**
* An abstract representation of a signing token.
- * Use in conjunction with @code SecurityTokenDecoder.
+ * Use in conjunction with @code SecurityTokenCodec.
*/
public interface SecurityToken {
Added: shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenCodec.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenCodec.java?rev=966481&view=auto
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenCodec.java (added)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenCodec.java Thu Jul 22 02:36:14 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.auth;
+
+import com.google.inject.ImplementedBy;
+
+import java.util.Map;
+
+/**
+ * Handles verification of gadget security tokens.
+ */
+@ImplementedBy(DefaultSecurityTokenCodec.class)
+public interface SecurityTokenCodec {
+
+ /**
+ * The security token value must be passed on a map value referenced by this key. Additional
+ * parameters can be passed as seen fit.
+ */
+ String SECURITY_TOKEN_NAME = "token";
+
+ /**
+ * Active URL for the request. Must include protocol, host, and port. May include path
+ * and may include query.
+ */
+ String ACTIVE_URL_NAME = "activeUrl";
+
+ /**
+ * Decrypts and verifies a gadget security token to return a gadget token.
+ *
+ * @param tokenParameters Map containing a entry 'token' in wire format (probably encrypted.)
+ * @return the decrypted and verified token.
+ * @throws SecurityTokenException If tokenString is not a valid token
+ */
+ SecurityToken createToken(Map<String, String> tokenParameters)
+ throws SecurityTokenException;
+
+ String encodeToken(SecurityToken token) throws SecurityTokenException;
+}
Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenException.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenException.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenException.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenException.java Thu Jul 22 02:36:14 2010
@@ -19,7 +19,7 @@
package org.apache.shindig.auth;
/**
- * Exceptions thrown by SecurityTokenDecoder implementations.
+ * Exceptions thrown by SecurityTokenCodec implementations.
*/
public class SecurityTokenException extends Exception {
public SecurityTokenException(String message) {
Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/UrlParameterAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/UrlParameterAuthenticationHandler.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/UrlParameterAuthenticationHandler.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/UrlParameterAuthenticationHandler.java Thu Jul 22 02:36:14 2010
@@ -34,12 +34,12 @@ import javax.servlet.http.HttpServletReq
public class UrlParameterAuthenticationHandler implements AuthenticationHandler {
private static final String SECURITY_TOKEN_PARAM = "st";
- private final SecurityTokenDecoder securityTokenDecoder;
+ private final SecurityTokenCodec securityTokenCodec;
private static final Pattern COMMAWHITESPACE = Pattern.compile("\\s*,\\s*");
@Inject
- public UrlParameterAuthenticationHandler(SecurityTokenDecoder securityTokenDecoder) {
- this.securityTokenDecoder = securityTokenDecoder;
+ public UrlParameterAuthenticationHandler(SecurityTokenCodec securityTokenCodec) {
+ this.securityTokenCodec = securityTokenCodec;
}
public String getName() {
@@ -50,13 +50,13 @@ public class UrlParameterAuthenticationH
throws InvalidAuthenticationException {
Map<String, String> parameters = getMappedParameters(request);
try {
- if (parameters.get(SecurityTokenDecoder.SECURITY_TOKEN_NAME) == null) {
+ if (parameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME) == null) {
return null;
}
- return securityTokenDecoder.createToken(parameters);
+ return securityTokenCodec.createToken(parameters);
} catch (SecurityTokenException e) {
throw new InvalidAuthenticationException("Malformed security token " +
- parameters.get(SecurityTokenDecoder.SECURITY_TOKEN_NAME), e);
+ parameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME), e);
}
}
@@ -64,8 +64,8 @@ public class UrlParameterAuthenticationH
return null;
}
- protected SecurityTokenDecoder getSecurityTokenDecoder() {
- return this.securityTokenDecoder;
+ protected SecurityTokenCodec getSecurityTokenCodec() {
+ return this.securityTokenCodec;
}
// From OAuthMessage
@@ -102,8 +102,8 @@ public class UrlParameterAuthenticationH
}
}
- params.put(SecurityTokenDecoder.SECURITY_TOKEN_NAME, token);
- params.put(SecurityTokenDecoder.ACTIVE_URL_NAME, getActiveUrl(request));
+ params.put(SecurityTokenCodec.SECURITY_TOKEN_NAME, token);
+ params.put(SecurityTokenCodec.ACTIVE_URL_NAME, getActiveUrl(request));
return params;
}
Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServletFetcher.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServletFetcher.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServletFetcher.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServletFetcher.java Thu Jul 22 02:36:14 2010
@@ -17,7 +17,7 @@
*/
package org.apache.shindig.protocol;
-import org.apache.shindig.auth.SecurityTokenDecoder;
+import org.apache.shindig.auth.SecurityTokenCodec;
import org.apache.shindig.common.servlet.ParameterFetcher;
import com.google.common.collect.ImmutableMap;
@@ -32,7 +32,7 @@ import java.util.Map;
public class DataServiceServletFetcher implements ParameterFetcher {
public Map<String, String> fetch(HttpServletRequest req) {
- return ImmutableMap.of(SecurityTokenDecoder.SECURITY_TOKEN_NAME, req.getParameter("st"));
+ return ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, req.getParameter("st"));
}
}
Added: shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodecTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodecTest.java?rev=966481&view=auto
==============================================================================
--- shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodecTest.java (added)
+++ shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenCodecTest.java Thu Jul 22 02:36:14 2010
@@ -0,0 +1,235 @@
+/*
+ * 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.auth;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.shindig.common.crypto.BasicBlobCrypter;
+import org.apache.shindig.common.crypto.BlobCrypter;
+import org.apache.shindig.common.util.CharsetUtil;
+import org.apache.shindig.common.util.FakeTimeSource;
+import org.apache.shindig.config.AbstractContainerConfig;
+import org.apache.shindig.config.ContainerConfig;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Tests for BlobCrypterSecurityTokenCodec
+ */
+public class BlobCrypterSecurityTokenCodecTest {
+
+ private BlobCrypterSecurityTokenCodec codec;
+ private final FakeTimeSource timeSource = new FakeTimeSource();
+
+ @Before
+ public void setUp() throws Exception {
+ ContainerConfig config = new AbstractContainerConfig() {
+ @Override
+ public Object getProperty(String container, String name) {
+ if (BlobCrypterSecurityTokenCodec.SECURITY_TOKEN_KEY_FILE.equals(name)) {
+ return getContainerKey(container);
+ }
+ if (BlobCrypterSecurityTokenCodec.SIGNED_FETCH_DOMAIN.equals(name)) {
+ return container + ".com";
+ }
+ throw new RuntimeException("Mock not smart enough, unknown name " + name);
+ }
+
+ @Override
+ public Collection<String> getContainers() {
+ return Lists.newArrayList("container", "example");
+ }
+ };
+ codec = new CodecWithLoadStubbedOut(config);
+ }
+
+ protected String getContainerKey(String container) {
+ return "KEY FOR CONTAINER " + container;
+ }
+
+ protected BlobCrypter getBlobCrypter(String fileName) {
+ BasicBlobCrypter c = new BasicBlobCrypter(CharsetUtil.getUtf8Bytes(fileName));
+ c.timeSource = timeSource;
+ return c;
+ }
+
+ /**
+ * Stubs out loading the key file.
+ */
+ private class CodecWithLoadStubbedOut extends BlobCrypterSecurityTokenCodec {
+
+ public CodecWithLoadStubbedOut(ContainerConfig config) {
+ super(config);
+ }
+
+ /**
+ * @return a crypter based on the name of the file passed in, rather than the contents
+ */
+ @Override
+ protected BlobCrypter loadCrypterFromFile(File file) throws IOException {
+ if (file.getPath().contains("fail")) {
+ throw new IOException("Load failed: " + file);
+ }
+ return getBlobCrypter(file.getPath());
+ }
+ }
+
+ @Test
+ public void testCreateToken() throws Exception {
+ BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(
+ getBlobCrypter(getContainerKey("container")), "container", null);
+ t.setAppUrl("http://www.example.com/gadget.xml");
+ t.setModuleId(12345L);
+ t.setOwnerId("owner");
+ t.setViewerId("viewer");
+ t.setTrustedJson("trusted");
+ String encrypted = t.encrypt();
+
+ SecurityToken t2 = codec.createToken(
+ ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted));
+
+ assertEquals("http://www.example.com/gadget.xml", t2.getAppId());
+ assertEquals("http://www.example.com/gadget.xml", t2.getAppUrl());
+ assertEquals("container.com", t2.getDomain());
+ assertEquals(12345L, t2.getModuleId());
+ assertEquals("owner", t2.getOwnerId());
+ assertEquals("viewer", t2.getViewerId());
+ assertEquals("trusted", t2.getTrustedJson());
+ }
+
+ @Test
+ public void testUnknownContainer() throws Exception {
+ BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(
+ getBlobCrypter(getContainerKey("container")), "container", null);
+ t.setAppUrl("http://www.example.com/gadget.xml");
+ t.setModuleId(12345L);
+ t.setOwnerId("owner");
+ t.setViewerId("viewer");
+ t.setTrustedJson("trusted");
+ String encrypted = t.encrypt();
+ encrypted = encrypted.replace("container:", "other:");
+
+ try {
+ codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted));
+ fail("should have reported that container was unknown");
+ } catch (SecurityTokenException e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("Unknown container"));
+ }
+ }
+
+ @Test
+ public void testWrongContainer() throws Exception {
+ BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(
+ getBlobCrypter(getContainerKey("container")), "container", null);
+ t.setAppUrl("http://www.example.com/gadget.xml");
+ t.setModuleId(12345L);
+ t.setOwnerId("owner");
+ t.setViewerId("viewer");
+ t.setTrustedJson("trusted");
+ String encrypted = t.encrypt();
+ encrypted = encrypted.replace("container:", "example:");
+
+ try {
+ codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted));
+ fail("should have tried to decrypt with wrong key");
+ } catch (SecurityTokenException e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("Invalid token signature"));
+ }
+ }
+
+ @Test
+ public void testExpired() throws Exception {
+ BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(
+ getBlobCrypter(getContainerKey("container")), "container", null);
+ t.setAppUrl("http://www.example.com/gadget.xml");
+ t.setModuleId(12345L);
+ t.setOwnerId("owner");
+ t.setViewerId("viewer");
+ t.setTrustedJson("trusted");
+ String encrypted = t.encrypt();
+
+ timeSource.incrementSeconds(3600 + 181); // one hour plus clock skew
+ try {
+ codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted));
+ fail("should have expired");
+ } catch (SecurityTokenException e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("Blob expired"));
+ }
+ }
+
+ @Test
+ public void testMalformed() throws Exception {
+ try {
+ codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, "foo"));
+ fail("should have tried to decrypt with wrong key");
+ } catch (SecurityTokenException e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("Invalid security token foo"));
+ }
+ }
+
+ @Test
+ public void testAnonymous() throws Exception {
+ SecurityToken t = codec.createToken(
+ ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, " "));
+ assertTrue(t.isAnonymous());
+
+ Map<String, String> empty = ImmutableMap.of();
+ t = codec.createToken(empty);
+ assertTrue(t.isAnonymous());
+ }
+
+ @Test
+ public void testLoadFailure() throws Exception {
+ ContainerConfig config = new AbstractContainerConfig() {
+ @Override
+ public Object getProperty(String container, String name) {
+ if (BlobCrypterSecurityTokenCodec.SECURITY_TOKEN_KEY_FILE.equals(name)) {
+ return getContainerKey(container);
+ }
+ if (BlobCrypterSecurityTokenCodec.SIGNED_FETCH_DOMAIN.equals(name)) {
+ return container + ".com";
+ }
+ throw new RuntimeException("Mock not smart enough, unknown name " + name);
+ }
+
+ @Override
+ public Collection<String> getContainers() {
+ return Lists.newArrayList("container", "example", "failure");
+ }
+ };
+
+ try {
+ new CodecWithLoadStubbedOut(config);
+ fail("Should have failed to load crypter");
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("Load failed"));
+ }
+ }
+}
Added: shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenCodecTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenCodecTest.java?rev=966481&view=auto
==============================================================================
--- shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenCodecTest.java (added)
+++ shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenCodecTest.java Thu Jul 22 02:36:14 2010
@@ -0,0 +1,111 @@
+/*
+ * 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.auth;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.shindig.config.AbstractContainerConfig;
+import org.apache.shindig.config.ContainerConfigException;
+
+import com.google.common.collect.Lists;
+
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Tests of DefaultSecurityTokenCodec
+ */
+public class DefaultSecurityTokenCodecTest {
+
+ private static class FakeContainerConfig extends AbstractContainerConfig {
+ private final String tokenType;
+
+ public FakeContainerConfig(String tokenType) throws ContainerConfigException {
+ this.tokenType = tokenType;
+ }
+
+ @Override
+ public Object getProperty(String container, String parameter) {
+ if ("gadgets.securityTokenType".equals(parameter)) {
+ if ("default".equals(container)) {
+ return tokenType;
+ }
+ } else if ("gadgets.securityTokenKeyFile".equals(parameter)) {
+ return "container key file: " + container;
+ }
+ return null;
+ }
+
+ @Override
+ public Collection<String> getContainers() {
+ return Lists.newArrayList("somecontainer");
+ }
+ }
+
+ @Test
+ public void testBasicDecoder() throws Exception {
+ DefaultSecurityTokenCodec codec = new DefaultSecurityTokenCodec(
+ new FakeContainerConfig("insecure"));
+ String token = "o:v:app:domain:appurl:12345:container";
+ Map<String, String> parameters = Collections.singletonMap(
+ SecurityTokenCodec.SECURITY_TOKEN_NAME, token);
+ SecurityToken st = codec.createToken(parameters);
+ assertEquals("o", st.getOwnerId());
+ assertEquals("v", st.getViewerId());
+ assertEquals("appurl", st.getAppUrl());
+ assertEquals("container", st.getContainer());
+ }
+
+ @Test
+ public void testInvalidDecoder() throws Exception {
+ try {
+ new DefaultSecurityTokenCodec(new FakeContainerConfig("garbage"));
+ fail("Should have thrown");
+ } catch (RuntimeException e) {
+ assertTrue("exception should contain garbage: " + e, e.getMessage().contains("garbage"));
+ }
+ }
+
+ @Test
+ public void testNullDecoder() throws Exception {
+ try {
+ new DefaultSecurityTokenCodec(new FakeContainerConfig(null));
+ fail("Should have thrown");
+ } catch (RuntimeException e) {
+ assertTrue("exception should contain null: " + e, e.getMessage().contains("null"));
+ }
+ }
+
+ @Test
+ public void testRealDecoder() throws Exception {
+ // Just verifies that "secure" tokens get routed to the right decoder class.
+ try {
+ new DefaultSecurityTokenCodec(new FakeContainerConfig("secure"));
+ fail("Should have thrown");
+ } catch (RuntimeException e) {
+ assertTrue("root cause should have been FileNotFoundException: " + e,
+ e.getMessage().contains("FileNotFoundException: container key file: somecontainer"));
+ }
+ }
+}
Modified: shindig/trunk/java/common/src/test/java/org/apache/shindig/common/testing/FakeGadgetToken.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/testing/FakeGadgetToken.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/common/src/test/java/org/apache/shindig/common/testing/FakeGadgetToken.java (original)
+++ shindig/trunk/java/common/src/test/java/org/apache/shindig/common/testing/FakeGadgetToken.java Thu Jul 22 02:36:14 2010
@@ -21,7 +21,7 @@ package org.apache.shindig.common.testin
import org.apache.shindig.auth.AbstractSecurityToken;
import org.apache.shindig.auth.AuthenticationMode;
import org.apache.shindig.auth.SecurityToken;
-import org.apache.shindig.auth.SecurityTokenDecoder;
+import org.apache.shindig.auth.SecurityTokenCodec;
import com.google.common.collect.Maps;
import org.apache.shindig.auth.SecurityTokenException;
@@ -208,11 +208,11 @@ public class FakeGadgetToken extends Abs
}
/**
- * SecurityTokenDecoder for testing - this allows passing around a
+ * SecurityTokenCodec for testing - this allows passing around a
* security token of format key=value&key2=value2, where key is one of:
* ownerId, viewerId, domain, appUrl, appId, trustedJson, module
*/
- public static class Decoder implements SecurityTokenDecoder {
+ public static class Codec implements SecurityTokenCodec {
public SecurityToken createToken(Map<String, String> tokenParameters) {
return FakeGadgetToken.createToken(tokenParameters);
}
Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/ShindigAuthConfigContributor.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/ShindigAuthConfigContributor.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/ShindigAuthConfigContributor.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/ShindigAuthConfigContributor.java Thu Jul 22 02:36:14 2010
@@ -24,7 +24,7 @@ import com.google.inject.Singleton;
import org.apache.shindig.auth.AnonymousSecurityToken;
import org.apache.shindig.auth.SecurityToken;
-import org.apache.shindig.auth.SecurityTokenDecoder;
+import org.apache.shindig.auth.SecurityTokenCodec;
import org.apache.shindig.auth.SecurityTokenException;
import org.apache.shindig.gadgets.Gadget;
import org.apache.shindig.gadgets.GadgetContext;
@@ -35,10 +35,10 @@ import java.util.Map;
@Singleton
public class ShindigAuthConfigContributor implements ConfigContributor {
- private SecurityTokenDecoder securityTokenCodec;
+ private SecurityTokenCodec securityTokenCodec;
@Inject
- public ShindigAuthConfigContributor(SecurityTokenDecoder codec) {
+ public ShindigAuthConfigContributor(SecurityTokenCodec codec) {
this.securityTokenCodec = codec;
}
Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetsHandler.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetsHandler.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetsHandler.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetsHandler.java Thu Jul 22 02:36:14 2010
@@ -25,7 +25,7 @@ import com.google.common.collect.Immutab
import com.google.inject.Inject;
import org.apache.shindig.auth.SecurityToken;
-import org.apache.shindig.auth.SecurityTokenDecoder;
+import org.apache.shindig.auth.SecurityTokenCodec;
import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.Gadget;
import org.apache.shindig.gadgets.GadgetContext;
@@ -71,18 +71,18 @@ public class GadgetsHandler {
protected final ExecutorService executor;
protected final Processor processor;
protected final IframeUriManager iframeUriManager;
- protected final SecurityTokenDecoder securityTokenDecoder;
+ protected final SecurityTokenCodec securityTokenCodec;
@Inject
public GadgetsHandler(
ExecutorService executor,
Processor processor,
IframeUriManager iframeUriManager,
- SecurityTokenDecoder securityTokenDecoder) {
+ SecurityTokenCodec securityTokenCodec) {
this.executor = executor;
this.processor = processor;
this.iframeUriManager = iframeUriManager;
- this.securityTokenDecoder = securityTokenDecoder;
+ this.securityTokenCodec = securityTokenCodec;
}
@Operation(httpMethods = {"POST", "GET"}, path = "metadata.get")
@@ -183,7 +183,7 @@ public class GadgetsHandler {
return new Callable<TokenResponse>() {
public TokenResponse call() throws Exception {
try {
- String token = securityTokenDecoder.encodeToken(context.getToken());
+ String token = securityTokenCodec.encodeToken(context.getToken());
return new TokenResponse(context.getUrl().toString(), token);
} catch (Exception e) {
// Note: this error message is publicly visible in JSON-RPC response.
Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java Thu Jul 22 02:36:14 2010
@@ -24,7 +24,7 @@ import com.google.inject.Inject;
import com.google.inject.name.Named;
import org.apache.shindig.auth.SecurityToken;
-import org.apache.shindig.auth.SecurityTokenDecoder;
+import org.apache.shindig.auth.SecurityTokenCodec;
import org.apache.shindig.auth.SecurityTokenException;
import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.uri.UriBuilder;
@@ -56,14 +56,14 @@ public class DefaultIframeUriManager imp
private final ContainerConfig config;
private final LockedDomainPrefixGenerator ldGen;
- private final SecurityTokenDecoder securityTokenCodec;
+ private final SecurityTokenCodec securityTokenCodec;
private final List<String> ldSuffixes;
@Inject
public DefaultIframeUriManager(ContainerConfig config,
LockedDomainPrefixGenerator ldGen,
- SecurityTokenDecoder securityTokenCodec) {
+ SecurityTokenCodec securityTokenCodec) {
this.config = config;
this.ldGen = ldGen;
this.securityTokenCodec = securityTokenCodec;
Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/GadgetsHandlerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/GadgetsHandlerTest.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/GadgetsHandlerTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/GadgetsHandlerTest.java Thu Jul 22 02:36:14 2010
@@ -21,8 +21,7 @@ import com.google.common.collect.Immutab
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
-
-import org.apache.shindig.auth.SecurityTokenDecoder;
+import org.apache.shindig.auth.SecurityTokenCodec;
import org.apache.shindig.auth.SecurityTokenException;
import org.apache.shindig.common.EasyMockTestCase;
import org.apache.shindig.common.JsonAssert;
@@ -72,9 +71,9 @@ public class GadgetsHandlerTest extends
token.setAppUrl("http://www.example.com/gadget.xml");
}
- private void registerGadgetsHandler(SecurityTokenDecoder decoder) {
+ private void registerGadgetsHandler(SecurityTokenCodec codec) {
GadgetsHandler handler =
- new GadgetsHandler(new TestExecutorService(), processor, urlGenerator, decoder);
+ new GadgetsHandler(new TestExecutorService(), processor, urlGenerator, codec);
registry = new DefaultHandlerRegistry(
injector, converter, new HandlerExecutionListener.NoOpHandler());
registry.addHandlers(ImmutableSet.<Object> of(handler));
@@ -173,11 +172,11 @@ public class GadgetsHandlerTest extends
@Test
public void testTokenOneGadget() throws Exception {
- SecurityTokenDecoder decoder = EasyMock.createMock(SecurityTokenDecoder.class);
- EasyMock.expect(decoder.encodeToken(token)).andReturn(TOKEN);
- replay(decoder);
+ SecurityTokenCodec codec = EasyMock.createMock(SecurityTokenCodec.class);
+ EasyMock.expect(codec.encodeToken(token)).andReturn(TOKEN);
+ replay(codec);
- registerGadgetsHandler(decoder);
+ registerGadgetsHandler(codec);
JSONObject request = makeTokenRequest(GADGET1_URL);
RpcHandler operation = registry.getRpcHandler(request);
Object responseObj = operation.execute(emptyFormItems, token, converter).get();
@@ -203,11 +202,11 @@ public class GadgetsHandlerTest extends
@Test
public void testTokenOneGadgetFailure() throws Exception {
- SecurityTokenDecoder decoder = EasyMock.createMock(SecurityTokenDecoder.class);
- EasyMock.expect(decoder.encodeToken(token)).andThrow(new SecurityTokenException("blah"));
- replay(decoder);
+ SecurityTokenCodec codec = EasyMock.createMock(SecurityTokenCodec.class);
+ EasyMock.expect(codec.encodeToken(token)).andThrow(new SecurityTokenException("blah"));
+ replay(codec);
- registerGadgetsHandler(decoder);
+ registerGadgetsHandler(codec);
JSONObject request = makeTokenRequest(GADGET1_URL);
RpcHandler operation = registry.getRpcHandler(request);
Object responseObj = operation.execute(emptyFormItems, token, converter).get();
@@ -235,12 +234,12 @@ public class GadgetsHandlerTest extends
@Test
public void testTokenMultipleGadgetsWithSuccessAndFailure() throws Exception {
- SecurityTokenDecoder decoder = EasyMock.createMock(SecurityTokenDecoder.class);
- EasyMock.expect(decoder.encodeToken(token)).andReturn(TOKEN);
- EasyMock.expect(decoder.encodeToken(token)).andThrow(new SecurityTokenException("blah"));
- replay(decoder);
+ SecurityTokenCodec codec = EasyMock.createMock(SecurityTokenCodec.class);
+ EasyMock.expect(codec.encodeToken(token)).andReturn(TOKEN);
+ EasyMock.expect(codec.encodeToken(token)).andThrow(new SecurityTokenException("blah"));
+ replay(codec);
- registerGadgetsHandler(decoder);
+ registerGadgetsHandler(codec);
JSONObject request = makeTokenRequest(GADGET1_URL, GADGET2_URL);
RpcHandler operation = registry.getRpcHandler(request);
Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManagerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManagerTest.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManagerTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManagerTest.java Thu Jul 22 02:36:14 2010
@@ -40,8 +40,8 @@ import static org.junit.Assert.assertTru
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import org.apache.shindig.auth.BasicSecurityTokenDecoder;
-import org.apache.shindig.auth.SecurityTokenDecoder;
+import org.apache.shindig.auth.BasicSecurityTokenCodec;
+import org.apache.shindig.auth.SecurityTokenCodec;
import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.uri.UriBuilder;
import org.apache.shindig.config.ContainerConfig;
@@ -69,7 +69,7 @@ public class DefaultIframeUriManagerTest
}
};
- private static final SecurityTokenDecoder tokenCodec = new BasicSecurityTokenDecoder();
+ private static final SecurityTokenCodec tokenCodec = new BasicSecurityTokenCodec();
@Test
public void typeHtmlBasicOptions() {
Modified: shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java?rev=966481&r1=966480&r2=966481&view=diff
==============================================================================
--- shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java (original)
+++ shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java Thu Jul 22 02:36:14 2010
@@ -18,7 +18,7 @@
package org.apache.shindig.server.endtoend;
import org.apache.shindig.auth.BasicSecurityToken;
-import org.apache.shindig.auth.BasicSecurityTokenDecoder;
+import org.apache.shindig.auth.BasicSecurityTokenCodec;
import org.apache.shindig.auth.SecurityToken;
import org.apache.shindig.common.JsonAssert;
import org.apache.shindig.common.crypto.BlobCrypterException;
@@ -398,8 +398,8 @@ public class EndToEndTest {
String gadgetUrl = EndToEndServer.SERVER_URL + '/' + testName;
String url = EndToEndServer.GADGET_BASEURL + "?url=" + URLEncoder.encode(gadgetUrl, "UTF-8");
- BasicSecurityTokenDecoder decoder = new BasicSecurityTokenDecoder();
- url += "&st=" + URLEncoder.encode(decoder.encodeToken(token), "UTF-8");
+ BasicSecurityTokenCodec codec = new BasicSecurityTokenCodec();
+ url += "&st=" + URLEncoder.encode(codec.encodeToken(token), "UTF-8");
if (testMethod != null) {
url += "&testMethod=" + URLEncoder.encode(testMethod, "UTF-8");
}