You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by rb...@apache.org on 2012/05/09 00:19:06 UTC
svn commit: r1335800 - in /shindig/trunk/java: common/conf/
common/src/main/java/org/apache/shindig/auth/
social-api/src/main/java/org/apache/shindig/social/core/config/
social-api/src/main/java/org/apache/shindig/social/sample/spi/
social-api/src/test...
Author: rbaxter85
Date: Tue May 8 22:19:05 2012
New Revision: 1335800
URL: http://svn.apache.org/viewvc?rev=1335800&view=rev
Log:
SHINDIG-1769
Person API should handle "-1" as a user id
Modified:
shindig/trunk/java/common/conf/shindig.properties
shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/AnonymousSecurityToken.java
shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java
shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
Modified: shindig/trunk/java/common/conf/shindig.properties
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/conf/shindig.properties?rev=1335800&r1=1335799&r2=1335800&view=diff
==============================================================================
--- shindig/trunk/java/common/conf/shindig.properties (original)
+++ shindig/trunk/java/common/conf/shindig.properties Tue May 8 22:19:05 2012
@@ -200,4 +200,7 @@ shindig.closure.compile.level=simple
# 5 * 60 * 60 * 1000 * 24 = 432000000 = 5 days
shindig.oauth2.authCodeExpiration=300000
shindig.oauth2.accessTokenExpiration=18000000
-shindig.oauth2.refreshTokenExpiration=432000000
\ No newline at end of file
+shindig.oauth2.refreshTokenExpiration=432000000
+
+# Allows unauthenticated requests to Shindig
+shindig.allowUnauthenticated=true
\ No newline at end of file
Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/AnonymousSecurityToken.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/AnonymousSecurityToken.java?rev=1335800&r1=1335799&r2=1335800&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/AnonymousSecurityToken.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/auth/AnonymousSecurityToken.java Tue May 8 22:19:05 2012
@@ -27,6 +27,12 @@ import org.apache.shindig.config.Contain
* A special class of Token representing the anonymous viewer/owner
*/
public class AnonymousSecurityToken extends AbstractSecurityToken implements SecurityToken {
+
+ /**
+ * The user ID for anonymous users.
+ */
+ public static final String ANONYMOUS_ID = "-1";
+
private static final EnumSet<Keys> MAP_KEYS = EnumSet.of(
Keys.OWNER, Keys.VIEWER, Keys.APP_URL, Keys.MODULE_ID, Keys.EXPIRES, Keys.TRUSTED_JSON
);
@@ -41,8 +47,8 @@ public class AnonymousSecurityToken exte
public AnonymousSecurityToken(String container, Long moduleId, String appUrl, Long expiresAt) {
setContainer(container).setModuleId(moduleId).setAppUrl(appUrl).setExpiresAt(expiresAt)
- .setOwnerId("-1")
- .setViewerId("-1")
+ .setOwnerId(ANONYMOUS_ID)
+ .setViewerId(ANONYMOUS_ID)
.setDomain("*")
.setTrustedJson("");
}
Modified: shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java?rev=1335800&r1=1335799&r2=1335800&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java (original)
+++ shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java Tue May 8 22:19:05 2012
@@ -64,10 +64,6 @@ public class SocialApiGuiceModule extend
bind(ParameterFetcher.class).annotatedWith(Names.named("DataServiceServlet"))
.to(DataServiceServletFetcher.class);
- bind(Boolean.class)
- .annotatedWith(Names.named(AnonymousAuthenticationHandler.ALLOW_UNAUTHENTICATED))
- .toInstance(Boolean.TRUE);
-
bind(XStreamConfiguration.class).to(XStream081Configuration.class);
bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.xml")).to(
BeanXStreamConverter.class);
Modified: shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java?rev=1335800&r1=1335799&r2=1335800&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java (original)
+++ shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java Tue May 8 22:19:05 2012
@@ -29,6 +29,7 @@ import java.util.concurrent.Future;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
+import org.apache.shindig.auth.AnonymousSecurityToken;
import org.apache.shindig.auth.SecurityToken;
import org.apache.shindig.common.servlet.Authority;
import org.apache.shindig.common.util.ImmediateFuture;
@@ -38,6 +39,8 @@ import org.apache.shindig.protocol.Proto
import org.apache.shindig.protocol.RestfulCollection;
import org.apache.shindig.protocol.conversion.BeanConverter;
import org.apache.shindig.protocol.model.SortOrder;
+import org.apache.shindig.social.core.model.NameImpl;
+import org.apache.shindig.social.core.model.PersonImpl;
import org.apache.shindig.social.opensocial.model.Activity;
import org.apache.shindig.social.opensocial.model.ActivityEntry;
import org.apache.shindig.social.opensocial.model.Album;
@@ -137,6 +140,11 @@ public class JsonDbOpensocialService imp
*/
private static final String ACTIVITYSTREAMS_TABLE = "activityEntries";
+ /**
+ * Anonymous name.
+ */
+ private static final String ANONYMOUS_NAME = "Anonymous";
+
private Authority authority;
/**
@@ -361,6 +369,13 @@ public class JsonDbOpensocialService imp
/** {@inheritDoc} */
public Future<Person> getPerson(UserId id, Set<String> fields, SecurityToken token)
throws ProtocolException {
+ if (id != null && AnonymousSecurityToken.ANONYMOUS_ID.equals(id.getUserId())) {
+ Person anonymous = new PersonImpl();
+ anonymous.setId(AnonymousSecurityToken.ANONYMOUS_ID);
+ anonymous.setName(new NameImpl(ANONYMOUS_NAME));
+ anonymous.setNickname(ANONYMOUS_NAME);
+ return ImmediateFuture.newInstance(anonymous);
+ }
try {
JSONArray people = db.getJSONArray(PEOPLE_TABLE);
Modified: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java?rev=1335800&r1=1335799&r2=1335800&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java (original)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java Tue May 8 22:19:05 2012
@@ -17,6 +17,7 @@
*/
package org.apache.shindig.social.opensocial.service;
+import org.apache.shindig.auth.AnonymousSecurityToken;
import org.apache.shindig.common.EasyMockTestCase;
import org.apache.shindig.common.testing.FakeGadgetToken;
import org.apache.shindig.common.util.ImmediateFuture;
@@ -69,6 +70,7 @@ public class PersonHandlerTest extends E
private static final Set<UserId> JOHN_DOE =
ImmutableSet.of(new UserId(UserId.Type.userId, "john.doe"));
+ private static final UserId ANONYMOUS = new UserId(UserId.Type.userId, AnonymousSecurityToken.ANONYMOUS_ID);
private static CollectionOptions DEFAULT_OPTIONS = new CollectionOptions();
protected ContainerConfig containerConfig;
@@ -219,6 +221,21 @@ public class PersonHandlerTest extends E
}
@Test
+ public void testHandleAnonymousUser() throws Exception {
+ String path = "/people/-1";
+ RestHandler operation = registry.getRestHandler(path, "GET");
+
+ Person data = new PersonImpl();
+ expect(personService.getPerson(eq(ANONYMOUS),
+ eq(DEFAULT_FIELDS), eq(token))).andReturn(ImmediateFuture.newInstance(data));
+
+ replay();
+ assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(),
+ null, token, converter).get());
+ verify();
+ }
+
+ @Test
public void testHandleGetPlural() throws Exception {
String path = "/people/john.doe,jane.doe/@self";
RestHandler operation = registry.getRestHandler(path, "GET");
Modified: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java?rev=1335800&r1=1335799&r2=1335800&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java (original)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java Tue May 8 22:19:05 2012
@@ -22,6 +22,7 @@ import java.util.Collections;
import javax.servlet.http.HttpServletResponse;
+import org.apache.shindig.auth.AnonymousSecurityToken;
import org.apache.shindig.auth.SecurityToken;
import org.apache.shindig.common.testing.FakeGadgetToken;
import org.apache.shindig.protocol.DataCollection;
@@ -30,6 +31,8 @@ import org.apache.shindig.protocol.Restf
import org.apache.shindig.protocol.model.FilterOperation;
import org.apache.shindig.protocol.model.SortOrder;
import org.apache.shindig.social.SocialApiTestsGuiceModule;
+import org.apache.shindig.social.core.model.NameImpl;
+import org.apache.shindig.social.core.model.PersonImpl;
import org.apache.shindig.social.opensocial.model.Activity;
import org.apache.shindig.social.opensocial.model.ActivityEntry;
import org.apache.shindig.social.opensocial.model.Person;
@@ -37,13 +40,12 @@ import org.apache.shindig.social.opensoc
import org.apache.shindig.social.opensocial.spi.GroupId;
import org.apache.shindig.social.opensocial.spi.PersonService;
import org.apache.shindig.social.opensocial.spi.UserId;
+import org.json.JSONArray;
+import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.json.JSONArray;
-import org.json.JSONObject;
-
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
@@ -58,6 +60,7 @@ public class JsonDbOpensocialServiceTest
private static final UserId CANON_USER = new UserId(UserId.Type.userId, "canonical");
private static final UserId JOHN_DOE = new UserId(UserId.Type.userId, "john.doe");
private static final UserId JANE_DOE = new UserId(UserId.Type.userId, "jane.doe");
+ private static final UserId ANONYMOUS = new UserId(UserId.Type.userId, AnonymousSecurityToken.ANONYMOUS_ID);
private static final GroupId SELF_GROUP = new GroupId(GroupId.Type.self, null);
private static final String APP_ID = "1";
@@ -84,6 +87,14 @@ public class JsonDbOpensocialServiceTest
}
@Test
+ public void testGetAnonymousUser() throws Exception {
+ Person person = db.getPerson(ANONYMOUS, Person.Field.DEFAULT_FIELDS, token).get();
+ assertEquals("-1", person.getId());
+ assertEquals("Anonymous", person.getName().getFormatted());
+ assertEquals("Anonymous", person.getNickname());
+ }
+
+ @Test
public void testGetPersonAllFields() throws Exception {
Person person = db
.getPerson(CANON_USER, Person.Field.ALL_FIELDS, token).get();