You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2010/06/23 08:23:59 UTC

svn commit: r957119 [6/6] - in /shindig/branches/2.0.x: ./ assembly/src/main/assembly/ config/ extras/src/main/java/org/apache/shindig/extras/as/sample/ extras/src/main/javascript/features-extras/ features/ features/src/main/javascript/features/ featur...

Modified: shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/OAuthAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/OAuthAuthenticationHandler.java?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/OAuthAuthenticationHandler.java (original)
+++ shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/core/oauth/OAuthAuthenticationHandler.java Wed Jun 23 06:23:54 2010
@@ -70,7 +70,7 @@ public class OAuthAuthenticationHandler 
   }
 
   public SecurityToken getSecurityTokenFromRequest(HttpServletRequest request)
-      throws InvalidAuthenticationException {
+    throws InvalidAuthenticationException {
     OAuthMessage message = OAuthServlet.getMessage(request, null);
     if (StringUtils.isEmpty(getParameter(message, OAuth.OAUTH_SIGNATURE))) {
       // Is not an oauth request
@@ -88,15 +88,15 @@ public class OAuthAuthenticationHandler 
   }
 
   protected SecurityToken verifyMessage(OAuthMessage message)
-      throws OAuthProblemException {
+    throws OAuthProblemException {
     OAuthEntry entry = getOAuthEntry(message);
     OAuthConsumer authConsumer = getConsumer(message);
 
     OAuthAccessor accessor = new OAuthAccessor(authConsumer);
 
     if (entry != null) {
-      accessor.tokenSecret = entry.tokenSecret;
-      accessor.accessToken = entry.token;
+      accessor.tokenSecret = entry.getTokenSecret();
+      accessor.accessToken = entry.getToken();
     }
 
     try {
@@ -129,7 +129,7 @@ public class OAuthAuthenticationHandler 
         OAuthProblemException e = new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
         e.setParameter(OAuth.Problems.OAUTH_PROBLEM_ADVICE, "cannot find token");
         throw e;
-      } else if (entry.type != OAuthEntry.Type.ACCESS) {
+      } else if (entry.getType() != OAuthEntry.Type.ACCESS) {
         OAuthProblemException e = new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
         e.setParameter(OAuth.Problems.OAUTH_PROBLEM_ADVICE, "token is not an access token");
         throw e;
@@ -150,10 +150,10 @@ public class OAuthAuthenticationHandler 
   }
 
   protected SecurityToken getTokenFromVerifiedRequest(OAuthMessage message, OAuthEntry entry,
-      OAuthConsumer authConsumer) throws OAuthProblemException {
+                                                      OAuthConsumer authConsumer) throws OAuthProblemException {
     if (entry != null) {
-      return new OAuthSecurityToken(entry.userId, entry.callbackUrl, entry.appId,
-          entry.domain, entry.container, entry.expiresAt().getTime());
+      return new OAuthSecurityToken(entry.getUserId(), entry.getCallbackUrl(), entry.getAppId(),
+                                    entry.getDomain(), entry.getContainer(), entry.expiresAt().getTime());
     } else {
       String userId = getParameter(message, REQUESTOR_ID_PARAM);
       return store.getSecurityTokenForConsumerRequest(authConsumer.consumerKey, userId);
@@ -175,12 +175,12 @@ public class OAuthAuthenticationHandler 
   }
 
   public static void verifyBodyHash(HttpServletRequest request, String oauthBodyHash)
-      throws InvalidAuthenticationException {
+    throws InvalidAuthenticationException {
     // we are doing body hash signing which is not permitted for form-encoded data
     if (request.getContentType() != null && request.getContentType().contains(OAuth.FORM_ENCODED)) {
       throw new AuthenticationHandler.InvalidAuthenticationException(
-          "Cannot use oauth_body_hash with a Content-Type of application/x-www-form-urlencoded",
-          null);
+        "Cannot use oauth_body_hash with a Content-Type of application/x-www-form-urlencoded",
+        null);
     } else {
       try {
         byte[] rawBody = readBody(request);

Modified: shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Address.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Address.java?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Address.java (original)
+++ shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Address.java Wed Jun 23 06:23:54 2010
@@ -63,7 +63,7 @@ public interface Address {
     /** the field name for primary. */
     PRIMARY("primary");
 
-    private static final Map<String, Field> lookup = Maps.uniqueIndex(EnumSet.allOf(Field.class), 
+    private static final Map<String, Field> LOOKUP = Maps.uniqueIndex(EnumSet.allOf(Field.class), 
         Functions.toStringFunction());
 
     /**
@@ -91,7 +91,7 @@ public interface Address {
     }
 
     public static Field getField(String jsonString) {
-      return lookup.get(jsonString);
+      return LOOKUP.get(jsonString);
     }
   }
 

Modified: shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java (original)
+++ shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java Wed Jun 23 06:23:54 2010
@@ -209,7 +209,7 @@ public interface Person {
      * a Map to convert json string to Field representations.
      */
 
-    private static final Map<String,Field> lookup = Maps.uniqueIndex(EnumSet.allOf(Field.class), 
+    private static final Map<String,Field> LOOKUP = Maps.uniqueIndex(EnumSet.allOf(Field.class), 
         Functions.toStringFunction());
 
     /**
@@ -220,7 +220,7 @@ public interface Person {
     /**
      * The set of all fields.
      */
-    public static final Set<String> ALL_FIELDS = lookup.keySet();
+    public static final Set<String> ALL_FIELDS = LOOKUP.keySet();
 
     /**
      * The set of default fields returned fields.
@@ -250,7 +250,7 @@ public interface Person {
     }
 
     public static Field getField(String jsonString) {
-      return lookup.get(jsonString);
+      return LOOKUP.get(jsonString);
     }
 
     /**
@@ -260,7 +260,7 @@ public interface Person {
      * @return The corresponding person field.
      */
     public static Person.Field fromUrlString(String urlString) {
-      return lookup.get(urlString);
+      return LOOKUP.get(urlString);
     }
   }
 

Modified: shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/oauth/OAuthEntry.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/oauth/OAuthEntry.java?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/oauth/OAuthEntry.java (original)
+++ shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/opensocial/oauth/OAuthEntry.java Wed Jun 23 06:23:54 2010
@@ -35,29 +35,30 @@ public class OAuthEntry implements Seria
     REQUEST, ACCESS, DISABLED
   }
 
-  public String appId;
-  public String callbackUrl;
-  public boolean callbackUrlSigned; // true if consumer supports OAuth 1.0a
-  public String userId;
-  public String token;
-  public String tokenSecret;
-
-  public boolean authorized;
-
-  public String consumerKey;
-
-  public Type type;
-  public Date issueTime;
-
-  public String domain;
-  public String container;
-  public String oauthVersion;
-  
-  public String callbackToken;
-  public int callbackTokenAttempts;
+  private String appId;
+  private String callbackUrl;
+  private boolean callbackUrlSigned; // true if consumer supports OAuth 1.0a
+  private String userId;
+  private String token;
+  private String tokenSecret;
+
+  private boolean authorized;
+
+  private String consumerKey;
+
+  private Type type;
+  private Date issueTime;
+
+  private String domain;
+  private String container;
+  private String oauthVersion;
+
+  private String callbackToken;
+  private int callbackTokenAttempts;
 
   public OAuthEntry() {}
 
+
   /**
    * A copy constructor
    * @param old the OAuthEntry to duplicate
@@ -88,14 +89,194 @@ public class OAuthEntry implements Seria
   public Date expiresAt() {
     long expirationTime = issueTime.getTime();
     switch (type) {
-      case REQUEST:
-        expirationTime += FIVE_MINUTES;
-        break;
-      case ACCESS:
-        expirationTime += ONE_YEAR;
-        break;
+    case REQUEST:
+      expirationTime += FIVE_MINUTES;
+      break;
+    case ACCESS:
+      expirationTime += ONE_YEAR;
+      break;
     }
 
     return new Date(expirationTime);
   }
+
+
+  public String getAppId()
+  {
+    return appId;
+  }
+
+
+  public String getCallbackUrl()
+  {
+    return callbackUrl;
+  }
+
+
+  public boolean isCallbackUrlSigned()
+  {
+    return callbackUrlSigned;
+  }
+
+
+  public String getUserId()
+  {
+    return userId;
+  }
+
+
+  public String getToken()
+  {
+    return token;
+  }
+
+
+  public String getTokenSecret()
+  {
+    return tokenSecret;
+  }
+
+
+  public boolean isAuthorized()
+  {
+    return authorized;
+  }
+
+
+  public String getConsumerKey()
+  {
+    return consumerKey;
+  }
+
+
+  public Type getType()
+  {
+    return type;
+  }
+
+
+  public Date getIssueTime()
+  {
+    return issueTime;
+  }
+
+
+  public String getDomain()
+  {
+    return domain;
+  }
+
+
+  public String getContainer()
+  {
+    return container;
+  }
+
+
+  public String getOauthVersion()
+  {
+    return oauthVersion;
+  }
+
+
+  public String getCallbackToken()
+  {
+    return callbackToken;
+  }
+
+
+  public int getCallbackTokenAttempts()
+  {
+    return callbackTokenAttempts;
+  }
+
+
+  public void setAppId(String appId)
+  {
+    this.appId = appId;
+  }
+
+
+  public void setCallbackUrl(String callbackUrl)
+  {
+    this.callbackUrl = callbackUrl;
+  }
+
+
+  public void setCallbackUrlSigned(boolean callbackUrlSigned)
+  {
+    this.callbackUrlSigned = callbackUrlSigned;
+  }
+
+
+  public void setUserId(String userId)
+  {
+    this.userId = userId;
+  }
+
+
+  public void setToken(String token)
+  {
+    this.token = token;
+  }
+
+
+  public void setTokenSecret(String tokenSecret)
+  {
+    this.tokenSecret = tokenSecret;
+  }
+
+
+  public void setAuthorized(boolean authorized)
+  {
+    this.authorized = authorized;
+  }
+
+
+  public void setConsumerKey(String consumerKey)
+  {
+    this.consumerKey = consumerKey;
+  }
+
+
+  public void setType(Type type)
+  {
+    this.type = type;
+  }
+
+
+  public void setIssueTime(Date issueTime)
+  {
+    this.issueTime = issueTime;
+  }
+
+
+  public void setDomain(String domain)
+  {
+    this.domain = domain;
+  }
+
+
+  public void setContainer(String container)
+  {
+    this.container = container;
+  }
+
+
+  public void setOauthVersion(String oauthVersion)
+  {
+    this.oauthVersion = oauthVersion;
+  }
+
+
+  public void setCallbackToken(String callbackToken)
+  {
+    this.callbackToken = callbackToken;
+  }
+
+
+  public void setCallbackTokenAttempts(int callbackTokenAttempts)
+  {
+    this.callbackTokenAttempts = callbackTokenAttempts;
+  }
 }

Modified: shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/SampleModule.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/SampleModule.java?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/SampleModule.java (original)
+++ shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/SampleModule.java Wed Jun 23 06:23:54 2010
@@ -26,7 +26,6 @@ import org.apache.shindig.social.sample.
 import org.apache.shindig.social.sample.spi.JsonDbOpensocialService;
 
 import com.google.inject.AbstractModule;
-import com.google.inject.multibindings.Multibinder;
 import com.google.inject.name.Names;
 
 /**

Modified: shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/oauth/SampleOAuthDataStore.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/oauth/SampleOAuthDataStore.java?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/oauth/SampleOAuthDataStore.java (original)
+++ shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/oauth/SampleOAuthDataStore.java Wed Jun 23 06:23:54 2010
@@ -75,7 +75,7 @@ public class SampleOAuthDataStore implem
       String consumerSecret = app.getString("consumerSecret");
 
       if (consumerSecret == null)
-          return null;
+        return null;
 
       // null below is for the callbackUrl, which we don't have in the db
       OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, consumerSecret, SERVICE_PROVIDER);
@@ -89,49 +89,49 @@ public class SampleOAuthDataStore implem
       return consumer;
 
     } catch (JSONException e) {
-       return null;
+      return null;
     }
   }
 
   // Generate a valid requestToken for the given consumerKey
   public OAuthEntry generateRequestToken(String consumerKey, String oauthVersion,
-      String signedCallbackUrl) {
+                                         String signedCallbackUrl) {
     OAuthEntry entry = new OAuthEntry();
-    entry.appId = consumerKey;
-    entry.consumerKey = consumerKey;
-    entry.domain = "samplecontainer.com";
-    entry.container = "default";
-
-    entry.token = UUID.randomUUID().toString();
-    entry.tokenSecret = UUID.randomUUID().toString();
-      
-    entry.type = OAuthEntry.Type.REQUEST;
-    entry.issueTime = new Date();
-    entry.oauthVersion = oauthVersion;
+    entry.setAppId(consumerKey);
+    entry.setConsumerKey(consumerKey);
+    entry.setDomain("samplecontainer.com");
+    entry.setContainer("default");
+
+    entry.setToken(UUID.randomUUID().toString());
+    entry.setTokenSecret(UUID.randomUUID().toString());
+
+    entry.setType(OAuthEntry.Type.REQUEST);
+    entry.setIssueTime(new Date());
+    entry.setOauthVersion(oauthVersion);
     if (signedCallbackUrl != null) {
-      entry.callbackUrlSigned = true;
-      entry.callbackUrl = signedCallbackUrl;
+      entry.setCallbackUrlSigned(true);
+      entry.setCallbackUrl(signedCallbackUrl);
     }
 
-    oauthEntries.put(entry.token, entry);
+    oauthEntries.put(entry.getToken(), entry);
     return entry;
   }
 
   // Turns the request token into an access token
   public OAuthEntry convertToAccessToken(OAuthEntry entry) {
     Preconditions.checkNotNull(entry);
-    Preconditions.checkState(entry.type == OAuthEntry.Type.REQUEST, "Token must be a request token");
+    Preconditions.checkState(entry.getType() == OAuthEntry.Type.REQUEST, "Token must be a request token");
 
     OAuthEntry accessEntry = new OAuthEntry(entry);
 
-    accessEntry.token = UUID.randomUUID().toString();
-    accessEntry.tokenSecret = UUID.randomUUID().toString();
+    accessEntry.setToken(UUID.randomUUID().toString());
+    accessEntry.setTokenSecret(UUID.randomUUID().toString());
 
-    accessEntry.type = OAuthEntry.Type.ACCESS;
-    accessEntry.issueTime = new Date();
+    accessEntry.setType(OAuthEntry.Type.ACCESS);
+    accessEntry.setIssueTime(new Date());
 
-    oauthEntries.remove(entry.token);
-    oauthEntries.put(accessEntry.token, accessEntry);
+    oauthEntries.remove(entry.getToken());
+    oauthEntries.put(accessEntry.getToken(), accessEntry);
 
     return accessEntry;
   }
@@ -139,27 +139,27 @@ public class SampleOAuthDataStore implem
   // Authorize the request token for the given user id
   public void authorizeToken(OAuthEntry entry, String userId) {
     Preconditions.checkNotNull(entry);
-    entry.authorized = true;
-    entry.userId = Preconditions.checkNotNull(userId);
-    if (entry.callbackUrlSigned) {
-      entry.callbackToken = Crypto.getRandomDigits(CALLBACK_TOKEN_LENGTH);
+    entry.setAuthorized(true);
+    entry.setUserId(Preconditions.checkNotNull(userId));
+    if (entry.isCallbackUrlSigned()) {
+      entry.setCallbackToken(Crypto.getRandomDigits(CALLBACK_TOKEN_LENGTH));
     }
   }
 
   public void disableToken(OAuthEntry entry) {
     Preconditions.checkNotNull(entry);
-    ++entry.callbackTokenAttempts;
-    if (!entry.callbackUrlSigned || entry.callbackTokenAttempts >= CALLBACK_TOKEN_ATTEMPTS) {
-      entry.type = OAuthEntry.Type.DISABLED;
+    entry.setCallbackTokenAttempts(entry.getCallbackTokenAttempts() + 1);
+    if (!entry.isCallbackUrlSigned() || entry.getCallbackTokenAttempts() >= CALLBACK_TOKEN_ATTEMPTS) {
+      entry.setType(OAuthEntry.Type.DISABLED);
     }
 
-    oauthEntries.put(entry.token, entry);
+    oauthEntries.put(entry.getToken(), entry);
   }
 
   public void removeToken(OAuthEntry entry) {
     Preconditions.checkNotNull(entry);
 
-    oauthEntries.remove(entry.token);
+    oauthEntries.remove(entry.getToken());
   }
 
   // Return the proper security token for a 2 legged oauth request that has been validated
@@ -170,7 +170,7 @@ public class SampleOAuthDataStore implem
     String container = "default";
 
     return new OAuthSecurityToken(userId, null, consumerKey, domain, container, null,
-        AuthenticationMode.OAUTH_CONSUMER_REQUEST.name());
-    
+                                  AuthenticationMode.OAUTH_CONSUMER_REQUEST.name());
+
   }
 }

Modified: shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/oauth/SampleOAuthServlet.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/oauth/SampleOAuthServlet.java?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/oauth/SampleOAuthServlet.java (original)
+++ shindig/branches/2.0.x/java/social-api/src/main/java/org/apache/shindig/social/sample/oauth/SampleOAuthServlet.java Wed Jun 23 06:23:54 2010
@@ -17,28 +17,35 @@
  */
 package org.apache.shindig.social.sample.oauth;
 
-import com.google.inject.Inject;
-import com.google.inject.name.Named;
-
-import net.oauth.*;
-import net.oauth.OAuth.Parameter;
-import net.oauth.server.OAuthServlet;
-
-import org.apache.shindig.auth.OAuthConstants;
-import org.apache.shindig.common.servlet.HttpUtil;
-import org.apache.shindig.common.servlet.InjectedServlet;
-import org.apache.shindig.social.opensocial.oauth.OAuthEntry;
-import org.apache.shindig.social.opensocial.oauth.OAuthDataStore;
-
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.net.URISyntaxException;
 import java.util.List;
+
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.shindig.common.servlet.HttpUtil;
+import org.apache.shindig.common.servlet.InjectedServlet;
+import org.apache.shindig.social.opensocial.oauth.OAuthDataStore;
+import org.apache.shindig.social.opensocial.oauth.OAuthEntry;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+import net.oauth.OAuth;
+import net.oauth.OAuthAccessor;
+import net.oauth.OAuthConsumer;
+import net.oauth.OAuthException;
+import net.oauth.OAuthMessage;
+import net.oauth.OAuthProblemException;
+import net.oauth.OAuthValidator;
+import net.oauth.SimpleOAuthValidator;
+import net.oauth.OAuth.Parameter;
+import net.oauth.server.OAuthServlet;
+
 /**
  * This is a sample class that demonstrates how oauth tokens can be handed out and authorized.
  * This is most certainly not production code. Your server should have clear ui, require user
@@ -49,8 +56,6 @@ public class SampleOAuthServlet extends 
   public static final OAuthValidator VALIDATOR = new SimpleOAuthValidator();
   private OAuthDataStore dataStore;
   private String oauthAuthorizeAction;
-  private boolean enableOAuth10;
-  private boolean enableSignedCallbacks;
 
   @Inject
   public void setDataStore(OAuthDataStore dataStore) {
@@ -58,19 +63,19 @@ public class SampleOAuthServlet extends 
   }
 
   @Inject void setAuthorizeAction(@Named("shindig.oauth.authorize-action") String authorizeAction) {
-     this.oauthAuthorizeAction = authorizeAction;
+    this.oauthAuthorizeAction = authorizeAction;
   }
 
   @Override
   protected void doPost(HttpServletRequest servletRequest,
-      HttpServletResponse servletResponse) throws ServletException, IOException {
+                        HttpServletResponse servletResponse) throws ServletException, IOException {
 
     doGet(servletRequest, servletResponse);
   }
 
   @Override
   protected void doGet(HttpServletRequest servletRequest,
-      HttpServletResponse servletResponse) throws ServletException, IOException {
+                       HttpServletResponse servletResponse) throws ServletException, IOException {
     HttpUtil.setNoCache(servletResponse);
     String path = servletRequest.getPathInfo();
 
@@ -94,7 +99,7 @@ public class SampleOAuthServlet extends 
 
   // Hand out a request token if the consumer key and secret are valid
   private void createRequestToken(HttpServletRequest servletRequest,
-      HttpServletResponse servletResponse) throws IOException, OAuthException, URISyntaxException {
+                                  HttpServletResponse servletResponse) throws IOException, OAuthException, URISyntaxException {
     OAuthMessage requestMessage = OAuthServlet.getMessage(servletRequest, null);
 
     String consumerKey = requestMessage.getConsumerKey();
@@ -123,10 +128,10 @@ public class SampleOAuthServlet extends 
 
     // generate request_token and secret
     OAuthEntry entry = dataStore.generateRequestToken(consumerKey,
-        requestMessage.getParameter(OAuth.OAUTH_VERSION), callback);
+                                                      requestMessage.getParameter(OAuth.OAUTH_VERSION), callback);
 
-    List<Parameter> responseParams = OAuth.newList(OAuth.OAUTH_TOKEN, entry.token,
-        OAuth.OAUTH_TOKEN_SECRET, entry.tokenSecret);
+    List<Parameter> responseParams = OAuth.newList(OAuth.OAUTH_TOKEN, entry.getToken(),
+                                                   OAuth.OAUTH_TOKEN_SECRET, entry.getTokenSecret());
     if (callback != null) {
       responseParams.add(new Parameter(OAuth.OAUTH_CALLBACK_CONFIRMED, "true"));
     }
@@ -137,7 +142,7 @@ public class SampleOAuthServlet extends 
   /////////////////////
   // deal with authorization request
   private void authorizeRequestToken(HttpServletRequest servletRequest,
-      HttpServletResponse servletResponse) throws ServletException, IOException, OAuthException, URISyntaxException {
+                                     HttpServletResponse servletResponse) throws ServletException, IOException, OAuthException, URISyntaxException {
 
     OAuthMessage requestMessage = OAuthServlet.getMessage(servletRequest, null);
 
@@ -153,7 +158,7 @@ public class SampleOAuthServlet extends 
       return;
     }
 
-    OAuthConsumer consumer = dataStore.getConsumer(entry.consumerKey);
+    OAuthConsumer consumer = dataStore.getConsumer(entry.getConsumerKey());
 
     // Extremely rare case where consumer dissappears
     if (consumer == null) {
@@ -162,15 +167,15 @@ public class SampleOAuthServlet extends 
     }
 
     // The token is disabled if you try to convert to an access token prior to authorization
-    if (entry.type == OAuthEntry.Type.DISABLED) {
+    if (entry.getType() == OAuthEntry.Type.DISABLED) {
       servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "This token is disabled, please reinitate login");
       return;
     }
 
-    String callback = entry.callbackUrl;
+    String callback = entry.getCallbackUrl();
 
     // Redirect to a UI flow if the token is not authorized
-    if (!entry.authorized) {
+    if (!entry.isAuthorized()) {
       // TBD -- need to decode encrypted payload somehow..
       if (this.oauthAuthorizeAction.startsWith("http")) {
         // Redirect to authorization page with params
@@ -183,7 +188,7 @@ public class SampleOAuthServlet extends 
         servletRequest.setAttribute("OAUTH_ENTRY",  entry);
         servletRequest.setAttribute("CALLBACK", callback);
 
-        servletRequest.setAttribute("TOKEN", entry.token);
+        servletRequest.setAttribute("TOKEN", entry.getToken());
         servletRequest.setAttribute("CONSUMER", consumer);
 
         servletRequest.getRequestDispatcher(oauthAuthorizeAction).forward(servletRequest,servletResponse);
@@ -199,17 +204,17 @@ public class SampleOAuthServlet extends 
       servletResponse.setContentType("text/plain");
       PrintWriter out = servletResponse.getWriter();
       out.write("Token successfully authorized.\n");      
-      if (entry.callbackToken != null) {
+      if (entry.getCallbackToken() != null) {
         // Usability fail.
-        out.write("Please enter code " + entry.callbackToken + " at the consumer.");
+        out.write("Please enter code " + entry.getCallbackToken() + " at the consumer.");
       }
     } else {
-      callback = OAuth.addParameters(callback, OAuth.OAUTH_TOKEN, entry.token);
+      callback = OAuth.addParameters(callback, OAuth.OAUTH_TOKEN, entry.getToken());
       // Add user_id to the callback
-      callback = OAuth.addParameters(callback, "user_id", entry.userId);
-      if (entry.callbackToken != null) {
+      callback = OAuth.addParameters(callback, "user_id", entry.getUserId());
+      if (entry.getCallbackToken() != null) {
         callback = OAuth.addParameters(callback, OAuth.OAUTH_VERIFIER,
-            entry.callbackToken);
+                                       entry.getCallbackToken());
       }
 
       servletResponse.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
@@ -220,22 +225,22 @@ public class SampleOAuthServlet extends 
   // Hand out an access token if the consumer key and secret are valid and the user authorized
   // the requestToken
   private void createAccessToken(HttpServletRequest servletRequest,
-      HttpServletResponse servletResponse) throws ServletException, IOException, OAuthException, URISyntaxException {
+                                 HttpServletResponse servletResponse) throws ServletException, IOException, OAuthException, URISyntaxException {
     OAuthMessage requestMessage = OAuthServlet.getMessage(servletRequest, null);
 
     OAuthEntry entry = getValidatedEntry(requestMessage);
     if (entry == null)
       throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
 
-    if (entry.callbackToken != null) {
+    if (entry.getCallbackToken() != null) {
       // We're using the fixed protocol
       String clientCallbackToken = requestMessage.getParameter(OAuth.OAUTH_VERIFIER);
-      if (!entry.callbackToken.equals(clientCallbackToken)) {
+      if (!entry.getCallbackToken().equals(clientCallbackToken)) {
         dataStore.disableToken(entry);
         servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "This token is not authorized");
         return;
       }
-    } else if (!entry.authorized) {
+    } else if (!entry.isAuthorized()) {
       // Old protocol.  Catch consumers trying to convert a token to one that's not authorized
       dataStore.disableToken(entry); 
       servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "This token is not authorized");
@@ -246,20 +251,20 @@ public class SampleOAuthServlet extends 
     OAuthEntry accessEntry = dataStore.convertToAccessToken(entry);
 
     sendResponse(servletResponse, OAuth.newList(
-        OAuth.OAUTH_TOKEN, accessEntry.token,
-        OAuth.OAUTH_TOKEN_SECRET, accessEntry.tokenSecret,
-        "user_id", entry.userId));
+                   OAuth.OAUTH_TOKEN, accessEntry.getToken(),
+                   OAuth.OAUTH_TOKEN_SECRET, accessEntry.getTokenSecret(),
+                   "user_id", entry.getUserId()));
   }
 
 
   private OAuthEntry getValidatedEntry(OAuthMessage requestMessage)
-      throws IOException, ServletException, OAuthException, URISyntaxException {
+    throws IOException, ServletException, OAuthException, URISyntaxException {
 
     OAuthEntry entry = dataStore.getEntry(requestMessage.getToken());
     if (entry == null)
       throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
 
-    if (entry.type != OAuthEntry.Type.REQUEST)
+    if (entry.getType() != OAuthEntry.Type.REQUEST)
       throw new OAuthProblemException(OAuth.Problems.TOKEN_USED);
 
     if (entry.isExpired())
@@ -273,9 +278,9 @@ public class SampleOAuthServlet extends 
       throw e;
     }
 
-    String consumerKey = entry.consumerKey;
+    String consumerKey = entry.getConsumerKey();
     if (!consumerKey.equals(requestMessage.getConsumerKey()))
-        throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_REFUSED);
+      throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_REFUSED);
 
     OAuthConsumer consumer = dataStore.getConsumer(consumerKey);
 
@@ -284,8 +289,8 @@ public class SampleOAuthServlet extends 
     
     OAuthAccessor accessor = new OAuthAccessor(consumer);
 
-    accessor.requestToken = entry.token;
-    accessor.tokenSecret = entry.tokenSecret;
+    accessor.requestToken = entry.getToken();
+    accessor.tokenSecret = entry.getTokenSecret();
 
     VALIDATOR.validateMessage(requestMessage, accessor);
 
@@ -293,7 +298,7 @@ public class SampleOAuthServlet extends 
   }
 
   private void sendResponse(HttpServletResponse servletResponse, List<OAuth.Parameter> parameters)
-      throws IOException {
+    throws IOException {
     servletResponse.setContentType("text/plain");
     OutputStream out = servletResponse.getOutputStream();
     OAuth.formEncode(parameters, out);
@@ -301,8 +306,8 @@ public class SampleOAuthServlet extends 
   }
 
   private static void handleException(Exception e, HttpServletRequest request,
-      HttpServletResponse response, boolean sendBody)
-      throws IOException, ServletException {
+                                      HttpServletResponse response, boolean sendBody)
+    throws IOException, ServletException {
     String realm = (request.isSecure()) ? "https://" : "http://";
 
     if (request.getHeader("Host") != null) {

Modified: shindig/branches/2.0.x/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/OAuthAuthenticationHanderTest.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/OAuthAuthenticationHanderTest.java?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/OAuthAuthenticationHanderTest.java (original)
+++ shindig/branches/2.0.x/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/OAuthAuthenticationHanderTest.java Wed Jun 23 06:23:54 2010
@@ -64,9 +64,9 @@ public class OAuthAuthenticationHanderTe
   public void setUp() throws Exception {
     reqHandler = new OAuthAuthenticationHandler(mockStore);
     formEncodedPost = new FakeOAuthRequest("POST", TEST_URL, "a=b&c=d",
-        OAuth.FORM_ENCODED);
+                                           OAuth.FORM_ENCODED);
     nonFormEncodedPost = new FakeOAuthRequest("POST", TEST_URL, "BODY",
-        "text/plain");
+                                              "text/plain");
   }
 
   private void expectTokenEntry() {
@@ -75,32 +75,32 @@ public class OAuthAuthenticationHanderTe
 
   private void expectTokenEntry(OAuthEntry authEntry) {
     EasyMock.expect(mockStore.getEntry(
-        EasyMock.eq(TOKEN))).
-          andReturn(authEntry).anyTimes();
+                      EasyMock.eq(TOKEN))).
+      andReturn(authEntry).anyTimes();
   }
 
   private OAuthEntry createOAuthEntry() {
     OAuthEntry authEntry = new OAuthEntry();
-    authEntry.appId = APP_ID;
-    authEntry.authorized = true;
-    authEntry.consumerKey = FakeOAuthRequest.CONSUMER_KEY;
-    authEntry.token = TOKEN;
-    authEntry.tokenSecret = FakeOAuthRequest.CONSUMER_SECRET;
-    authEntry.type = OAuthEntry.Type.ACCESS;
-    authEntry.userId = FakeOAuthRequest.REQUESTOR;
-    authEntry.issueTime = new Date();
-    authEntry.domain = DOMAIN;
-    authEntry.container = CONTAINER;
+    authEntry.setAppId(APP_ID);
+    authEntry.setAuthorized(true);
+    authEntry.setConsumerKey(FakeOAuthRequest.CONSUMER_KEY);
+    authEntry.setToken(TOKEN);
+    authEntry.setTokenSecret(FakeOAuthRequest.CONSUMER_SECRET);
+    authEntry.setType(OAuthEntry.Type.ACCESS);
+    authEntry.setUserId(FakeOAuthRequest.REQUESTOR);
+    authEntry.setIssueTime(new Date());
+    authEntry.setDomain(DOMAIN);
+    authEntry.setContainer(CONTAINER);
     return authEntry;
   }
 
   private void expectConsumer() {
     try {
       EasyMock.expect(mockStore.getConsumer(
-          EasyMock.eq(FakeOAuthRequest.CONSUMER_KEY))).
-            andReturn(new OAuthConsumer(null, FakeOAuthRequest.CONSUMER_KEY,
-              FakeOAuthRequest.CONSUMER_SECRET, new OAuthServiceProvider(null, null, null)))
-          .anyTimes();
+                        EasyMock.eq(FakeOAuthRequest.CONSUMER_KEY))).
+        andReturn(new OAuthConsumer(null, FakeOAuthRequest.CONSUMER_KEY,
+                                    FakeOAuthRequest.CONSUMER_SECRET, new OAuthServiceProvider(null, null, null)))
+        .anyTimes();
     } catch (OAuthProblemException e) {
       // ignore
     }
@@ -109,8 +109,8 @@ public class OAuthAuthenticationHanderTe
   private void expectSecurityToken() {
     try {
       EasyMock.expect(mockStore.getSecurityTokenForConsumerRequest(
-          EasyMock.eq(FakeOAuthRequest.CONSUMER_KEY), EasyMock.eq(FakeOAuthRequest.REQUESTOR))).
-            andReturn(new AnonymousSecurityToken());
+                        EasyMock.eq(FakeOAuthRequest.CONSUMER_KEY), EasyMock.eq(FakeOAuthRequest.REQUESTOR))).
+        andReturn(new AnonymousSecurityToken());
     } catch (OAuthProblemException e) {
       // ignore
     }
@@ -122,7 +122,7 @@ public class OAuthAuthenticationHanderTe
     expectConsumer();
     replay();
     HttpServletRequest request = formEncodedPost.sign(TOKEN,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
+                                                      FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
     SecurityToken token = reqHandler.getSecurityTokenFromRequest(request);
     assertEquals(FakeOAuthRequest.REQUESTOR, token.getViewerId());
     assertEquals(APP_ID, token.getAppId());
@@ -139,9 +139,9 @@ public class OAuthAuthenticationHanderTe
     expectConsumer();
     replay();
     FakeOAuthRequest get =
-        new FakeOAuthRequest("GET", TEST_URL, null, null);
+      new FakeOAuthRequest("GET", TEST_URL, null, null);
     FakeHttpServletRequest request = get.sign(TOKEN,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
+                                              FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
     assertNotNull(reqHandler.getSecurityTokenFromRequest(request));
   }
 
@@ -151,9 +151,9 @@ public class OAuthAuthenticationHanderTe
     expectConsumer();
     replay();
     FakeOAuthRequest get =
-        new FakeOAuthRequest("GET", TEST_URL, null, null);
+      new FakeOAuthRequest("GET", TEST_URL, null, null);
     FakeHttpServletRequest request = get.sign(TOKEN,
-        FakeOAuthRequest.OAuthParamLocation.AUTH_HEADER, FakeOAuthRequest.BodySigning.NONE);
+                                              FakeOAuthRequest.OAuthParamLocation.AUTH_HEADER, FakeOAuthRequest.BodySigning.NONE);
     assertNotNull(reqHandler.getSecurityTokenFromRequest(request));
   }
 
@@ -163,7 +163,7 @@ public class OAuthAuthenticationHanderTe
     expectConsumer();
     replay();
     HttpServletRequest request = formEncodedPost.sign(TOKEN,
-        FakeOAuthRequest.OAuthParamLocation.POST_BODY, FakeOAuthRequest.BodySigning.NONE);
+                                                      FakeOAuthRequest.OAuthParamLocation.POST_BODY, FakeOAuthRequest.BodySigning.NONE);
     SecurityToken token = reqHandler.getSecurityTokenFromRequest(request);
     assertNotNull(token);
     verify();
@@ -176,7 +176,7 @@ public class OAuthAuthenticationHanderTe
     expectConsumer();
     replay();
     HttpServletRequest request = formEncodedPost.sign(TOKEN,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
+                                                      FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
     try {
       reqHandler.getSecurityTokenFromRequest(request);
       fail("Expect failure as no token entry in store");
@@ -189,12 +189,12 @@ public class OAuthAuthenticationHanderTe
   @Test
   public void testVerifyFailTokenSecretMismatch() throws Exception {
     OAuthEntry authEntry = createOAuthEntry();
-    authEntry.tokenSecret = "badsecret";
+    authEntry.setTokenSecret("badsecret");
     expectTokenEntry(authEntry);
     expectConsumer();
     replay();
     HttpServletRequest request = formEncodedPost.sign(TOKEN,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
+                                                      FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
     try {
       reqHandler.getSecurityTokenFromRequest(request);
       fail("Expect failure as token secrets mismatch");
@@ -207,12 +207,12 @@ public class OAuthAuthenticationHanderTe
   @Test
   public void testVerifyFailTokenIsRequest() throws Exception {
     OAuthEntry authEntry = createOAuthEntry();
-    authEntry.type = OAuthEntry.Type.REQUEST;
+    authEntry.setType(OAuthEntry.Type.REQUEST);
     expectTokenEntry(authEntry);
     expectConsumer();
     replay();
     HttpServletRequest request = formEncodedPost.sign(TOKEN,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
+                                                      FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
     try {
       reqHandler.getSecurityTokenFromRequest(request);
       fail("Expect failure as token is a request token not an access token");
@@ -225,13 +225,13 @@ public class OAuthAuthenticationHanderTe
   @Test
   public void testVerifyFailTokenIsExpired() throws Exception {
     OAuthEntry authEntry = createOAuthEntry();
-    authEntry.issueTime = new Date(System.currentTimeMillis() - (OAuthEntry.ONE_YEAR + 1));
-    authEntry.type = OAuthEntry.Type.REQUEST;
+    authEntry.setIssueTime(new Date(System.currentTimeMillis() - (OAuthEntry.ONE_YEAR + 1)));
+    authEntry.setType(OAuthEntry.Type.REQUEST);
     expectTokenEntry(authEntry);
     expectConsumer();
     replay();
     HttpServletRequest request = formEncodedPost.sign(TOKEN,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
+                                                      FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
     try {
       reqHandler.getSecurityTokenFromRequest(request);
       fail("Expect failure as token is expired");
@@ -247,7 +247,7 @@ public class OAuthAuthenticationHanderTe
     expectSecurityToken();
     replay();
     HttpServletRequest request = formEncodedPost.sign(null,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
+                                                      FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
     SecurityToken token = reqHandler.getSecurityTokenFromRequest(request);
     assertNotNull(token);
     assertFalse(token instanceof OAuthSecurityToken);
@@ -260,9 +260,9 @@ public class OAuthAuthenticationHanderTe
     expectSecurityToken();
     replay();
     FakeOAuthRequest get =
-        new FakeOAuthRequest("GET", TEST_URL, null, null);
+      new FakeOAuthRequest("GET", TEST_URL, null, null);
     FakeHttpServletRequest request = get.sign(null,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
+                                              FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
     assertNotNull(reqHandler.getSecurityTokenFromRequest(request));
   }
 
@@ -272,9 +272,9 @@ public class OAuthAuthenticationHanderTe
     expectSecurityToken();
     replay();
     FakeOAuthRequest get =
-        new FakeOAuthRequest("GET", TEST_URL, null, null);
+      new FakeOAuthRequest("GET", TEST_URL, null, null);
     FakeHttpServletRequest request = get.sign(null,
-        FakeOAuthRequest.OAuthParamLocation.AUTH_HEADER, FakeOAuthRequest.BodySigning.NONE);
+                                              FakeOAuthRequest.OAuthParamLocation.AUTH_HEADER, FakeOAuthRequest.BodySigning.NONE);
     assertNotNull(reqHandler.getSecurityTokenFromRequest(request));
   }
 
@@ -284,7 +284,7 @@ public class OAuthAuthenticationHanderTe
     expectSecurityToken();
     replay();
     HttpServletRequest request = formEncodedPost.sign(null,
-        FakeOAuthRequest.OAuthParamLocation.AUTH_HEADER, FakeOAuthRequest.BodySigning.NONE);
+                                                      FakeOAuthRequest.OAuthParamLocation.AUTH_HEADER, FakeOAuthRequest.BodySigning.NONE);
     reqHandler.getSecurityTokenFromRequest(request);
     verify();
   }
@@ -295,7 +295,7 @@ public class OAuthAuthenticationHanderTe
     expectSecurityToken();
     replay();
     HttpServletRequest request = formEncodedPost.sign(null,
-        FakeOAuthRequest.OAuthParamLocation.POST_BODY, FakeOAuthRequest.BodySigning.NONE);
+                                                      FakeOAuthRequest.OAuthParamLocation.POST_BODY, FakeOAuthRequest.BodySigning.NONE);
     reqHandler.getSecurityTokenFromRequest(request);
     verify();
   }
@@ -304,7 +304,7 @@ public class OAuthAuthenticationHanderTe
   public void testNoSignature() throws Exception {
     replay();
     FakeHttpServletRequest request = formEncodedPost.sign(null,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
+                                                          FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.NONE);
     // A request without a signature is not an OAuth request
     request.setParameter(OAuth.OAUTH_SIGNATURE, "");
     SecurityToken st = reqHandler.getSecurityTokenFromRequest(request);
@@ -319,7 +319,7 @@ public class OAuthAuthenticationHanderTe
     replay();
 
     FakeHttpServletRequest request = nonFormEncodedPost.sign(null,
-        FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.HASH);
+                                                             FakeOAuthRequest.OAuthParamLocation.URI_QUERY, FakeOAuthRequest.BodySigning.HASH);
     assertNotNull(reqHandler.getSecurityTokenFromRequest(request));
   }
 
@@ -327,10 +327,10 @@ public class OAuthAuthenticationHanderTe
   public void testConsumerFailBodyHashSigningWithFormEncoding() throws Exception {
     replay();
     FakeOAuthRequest bodyHashPost =
-        new FakeOAuthRequest("POST", TEST_URL, "a=b&c=d&oauth_body_hash=hash",
-        OAuth.FORM_ENCODED);
+      new FakeOAuthRequest("POST", TEST_URL, "a=b&c=d&oauth_body_hash=hash",
+                           OAuth.FORM_ENCODED);
     FakeHttpServletRequest request = bodyHashPost
-        .sign(null, FakeOAuthRequest.OAuthParamLocation.URI_QUERY,
+      .sign(null, FakeOAuthRequest.OAuthParamLocation.URI_QUERY,
             FakeOAuthRequest.BodySigning.NONE);
     try {
       reqHandler.getSecurityTokenFromRequest(request);
@@ -357,7 +357,7 @@ public class OAuthAuthenticationHanderTe
     String body = "BODY";
     req.setPostData(CharsetUtil.getUtf8Bytes(body));
     String hash = new String(Base64.encodeBase64(DigestUtils.sha(CharsetUtil.getUtf8Bytes(body))),
-        "UTF-8");
+                             "UTF-8");
     req.setParameter(OAuthConstants.OAUTH_BODY_HASH, hash);
     OAuthAuthenticationHandler.verifyBodyHash(req, hash);
   }
@@ -369,7 +369,7 @@ public class OAuthAuthenticationHanderTe
     String body = "BODY";
     req.setPostData(CharsetUtil.getUtf8Bytes(body));
     String hash = new String(Base64.encodeBase64(
-        DigestUtils.sha(CharsetUtil.getUtf8Bytes("NOTBODY"))), "UTF-8");
+                               DigestUtils.sha(CharsetUtil.getUtf8Bytes("NOTBODY"))), "UTF-8");
     req.setParameter(OAuthConstants.OAUTH_BODY_HASH, hash);
     try {
       OAuthAuthenticationHandler.verifyBodyHash(req, hash);
@@ -386,7 +386,7 @@ public class OAuthAuthenticationHanderTe
     String body = "BODY";
     req.setPostData(CharsetUtil.getUtf8Bytes(body));
     String hash = new String(Base64.encodeBase64(DigestUtils.sha(CharsetUtil.getUtf8Bytes(body))),
-        "UTF-8");
+                             "UTF-8");
     req.setParameter(OAuthConstants.OAUTH_BODY_HASH, hash);
     try {
       OAuthAuthenticationHandler.verifyBodyHash(req, hash);
@@ -401,7 +401,7 @@ public class OAuthAuthenticationHanderTe
     FakeHttpServletRequest req = new FakeHttpServletRequest();
     req.setPostData(CharsetUtil.getUtf8Bytes(""));
     String hash = new String(Base64.encodeBase64(DigestUtils.sha(CharsetUtil.getUtf8Bytes(""))),
-        "UTF-8");
+                             "UTF-8");
     OAuthAuthenticationHandler.verifyBodyHash(req, hash);
   }
 }

Modified: shindig/branches/2.0.x/php/external/OAuth/OAuth.php
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/php/external/OAuth/OAuth.php?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/php/external/OAuth/OAuth.php (original)
+++ shindig/branches/2.0.x/php/external/OAuth/OAuth.php Wed Jun 23 06:23:54 2010
@@ -1,4 +1,6 @@
 <?php
+// Code taken from http://oauth.googlecode.com/ (r1226) (with modifications)
+// vim: foldmethod=marker
 
 /* Generic exception class
  */
@@ -10,7 +12,7 @@ class OAuthConsumer {
   public $key;
   public $secret;
 
-  function __construct($key, $secret, $callback_url = NULL) {
+  function __construct($key, $secret, $callback_url=NULL) {
     $this->key = $key;
     $this->secret = $secret;
     $this->callback_url = $callback_url;
@@ -40,7 +42,10 @@ class OAuthToken {
    * would respond to request_token and access_token calls with
    */
   function to_string() {
-    return "oauth_token=" . OAuthUtil::urlencode_rfc3986($this->key) . "&oauth_token_secret=" . OAuthUtil::urlencode_rfc3986($this->secret);
+    return "oauth_token=" .
+           OAuthUtil::urlencode_rfc3986($this->key) .
+           "&oauth_token_secret=" .
+           OAuthUtil::urlencode_rfc3986($this->secret);
   }
 
   function __toString() {
@@ -48,16 +53,51 @@ class OAuthToken {
   }
 }
 
-class OAuthSignatureMethod {
+/**
+ * A class for implementing a Signature Method
+ * See section 9 ("Signing Requests") in the spec
+ */
+abstract class OAuthSignatureMethod {
+  /**
+   * Needs to return the name of the Signature Method (ie HMAC-SHA1)
+   * @return string
+   */
+  abstract public function get_name();
 
-  public function check_signature(&$request, $consumer, $token, $signature) {
+  /**
+   * Build up the signature
+   * NOTE: The output of this function MUST NOT be urlencoded.
+   * the encoding is handled in OAuthRequest when the final
+   * request is serialized
+   * @param OAuthRequest $request
+   * @param OAuthConsumer $consumer
+   * @param OAuthToken $token
+   * @return string
+   */
+  abstract public function build_signature($request, $consumer, $token);
+
+  /**
+   * Verifies that a given signature is correct
+   * @param OAuthRequest $request
+   * @param OAuthConsumer $consumer
+   * @param OAuthToken $token
+   * @param string $signature
+   * @return bool
+   */
+  public function check_signature($request, $consumer, $token, $signature) {
     $built = $this->build_signature($request, $consumer, $token);
     return $built == $signature;
   }
 }
 
+/**
+ * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104] 
+ * where the Signature Base String is the text and the key is the concatenated values (each first 
+ * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&' 
+ * character (ASCII code 38) even if empty.
+ *   - Chapter 9.2 ("HMAC-SHA1")
+ */
 class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod {
-
   function get_name() {
     return "HMAC-SHA1";
   }
@@ -66,7 +106,10 @@ class OAuthSignatureMethod_HMAC_SHA1 ext
     $base_string = $request->get_signature_base_string();
     $request->base_string = $base_string;
 
-    $key_parts = array($consumer->secret, ($token) ? $token->secret : "");
+    $key_parts = array(
+      $consumer->secret,
+      ($token) ? $token->secret : ""
+    );
 
     $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
     $key = implode('&', $key_parts);
@@ -75,54 +118,67 @@ class OAuthSignatureMethod_HMAC_SHA1 ext
   }
 }
 
+/**
+ * The PLAINTEXT method does not provide any security protection and SHOULD only be used 
+ * over a secure channel such as HTTPS. It does not use the Signature Base String.
+ *   - Chapter 9.4 ("PLAINTEXT")
+ */
 class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod {
-
   public function get_name() {
     return "PLAINTEXT";
   }
 
+  /**
+   * oauth_signature is set to the concatenated encoded values of the Consumer Secret and 
+   * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is 
+   * empty. The result MUST be encoded again.
+   *   - Chapter 9.4.1 ("Generating Signatures")
+   *
+   * Please note that the second encoding MUST NOT happen in the SignatureMethod, as
+   * OAuthRequest handles this!
+   */
   public function build_signature($request, $consumer, $token) {
-    $sig = array(OAuthUtil::urlencode_rfc3986($consumer->secret));
-
-    if ($token) {
-      array_push($sig, OAuthUtil::urlencode_rfc3986($token->secret));
-    } else {
-      array_push($sig, '');
-    }
+    $key_parts = array(
+      $consumer->secret,
+      ($token) ? $token->secret : ""
+    );
 
-    $raw = implode("&", $sig);
-    // for debug purposes
-    $request->base_string = $raw;
+    $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
+    $key = implode('&', $key_parts);
+    $request->base_string = $key;
 
-    return OAuthUtil::urlencode_rfc3986($raw);
+    return $key;
   }
 }
 
-class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod {
-
+/**
+ * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in 
+ * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for 
+ * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a 
+ * verified way to the Service Provider, in a manner which is beyond the scope of this 
+ * specification.
+ *   - Chapter 9.3 ("RSA-SHA1")
+ */
+abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod {
   public function get_name() {
     return "RSA-SHA1";
   }
 
-  protected function fetch_public_cert(&$request) {
-    // not implemented yet, ideas are:
-    // (1) do a lookup in a table of trusted certs keyed off of consumer
-    // (2) fetch via http using a url provided by the requester
-    // (3) some sort of specific discovery code based on request
-    //
-    // either way should return a string representation of the certificate
-    throw Exception("fetch_public_cert not implemented");
-  }
-
-  protected function fetch_private_cert(&$request) {
-    // not implemented yet, ideas are:
-    // (1) do a lookup in a table of trusted certs keyed off of consumer
-    //
-    // either way should return a string representation of the certificate
-    throw Exception("fetch_private_cert not implemented");
-  }
+  // Up to the SP to implement this lookup of keys. Possible ideas are:
+  // (1) do a lookup in a table of trusted certs keyed off of consumer
+  // (2) fetch via http using a url provided by the requester
+  // (3) some sort of specific discovery code based on request
+  //
+  // Either way should return a string representation of the certificate
+  protected abstract function fetch_public_cert(&$request);
+
+  // Up to the SP to implement this lookup of keys. Possible ideas are:
+  // (1) do a lookup in a table of trusted certs keyed off of consumer
+  //
+  // Either way should return a string representation of the certificate
+  protected abstract function fetch_private_cert(&$request);
 
-  public function build_signature(&$request, $consumer, $token) {
+  public function build_signature($request, $consumer, $token) {
     $base_string = $request->get_signature_base_string();
     $request->base_string = $base_string;
 
@@ -141,7 +197,7 @@ class OAuthSignatureMethod_RSA_SHA1 exte
     return base64_encode($signature);
   }
 
-  public function check_signature(&$request, $consumer, $token, $signature) {
+  public function check_signature($request, $consumer, $token, $signature) {
     $decoded_sig = base64_decode($signature);
 
     $base_string = $request->get_signature_base_string();
@@ -174,26 +230,34 @@ class OAuthRequest {
   public static $version = '1.0';
   public static $POST_INPUT = 'php://input';
 
-  function __construct($http_method, $http_url, $parameters = NULL) {
+  function __construct($http_method, $http_url, $parameters=NULL) {
     @$parameters or $parameters = array();
+    $parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
     $this->parameters = $parameters;
     $this->http_method = $http_method;
     $this->http_url = $http_url;
   }
 
+
   /**
    * attempt to build up a request from what was passed to the server
    */
-  public static function from_request($http_method = NULL, $http_url = NULL, $parameters = NULL) {
-    $scheme = (! isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https';
-    @$http_url or $http_url = $scheme . '://' . $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
+  public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {
+    $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
+              ? 'http'
+              : 'https';
+    @$http_url or $http_url = $scheme .
+                              '://' . $_SERVER['HTTP_HOST'] .
+                              ':' .
+                              $_SERVER['SERVER_PORT'] .
+                              $_SERVER['REQUEST_URI'];
     @$http_method or $http_method = $_SERVER['REQUEST_METHOD'];
 
     // We weren't handed any parameters, so let's find the ones relevant to
     // this request.
     // If you run XML-RPC or similar you should use this to provide your own
     // parsed parameter-list
-    if (! $parameters) {
+    if (!$parameters) {
       // Find request headers
       $request_headers = OAuthUtil::get_headers();
 
@@ -202,15 +266,22 @@ class OAuthRequest {
 
       // It's a POST request of the proper content-type, so parse POST
       // parameters and add those overriding any duplicates from GET
-      if ($http_method == "POST" && @strstr($request_headers["Content-Type"], "application/x-www-form-urlencoded")) {
-        $post_data = OAuthUtil::parse_parameters(file_get_contents(self::$POST_INPUT));
+      if ($http_method == "POST"
+          && @strstr($request_headers["Content-Type"],
+                     "application/x-www-form-urlencoded")
+          ) {
+        $post_data = OAuthUtil::parse_parameters(
+          file_get_contents(self::$POST_INPUT)
+        );
         $parameters = array_merge($parameters, $post_data);
       }
 
       // We have a Authorization-header with OAuth data. Parse the header
       // and add those overriding any duplicates from GET or POST
       if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") {
-        $header_parameters = OAuthUtil::split_header($request_headers['Authorization']);
+        $header_parameters = OAuthUtil::split_header(
+          $request_headers['Authorization']
+        );
         $parameters = array_merge($parameters, $header_parameters);
       }
 
@@ -222,13 +293,14 @@ class OAuthRequest {
   /**
    * pretty much a helper function to set up the request
    */
-  public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL) {
+  public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
     @$parameters or $parameters = array();
     $defaults = array("oauth_version" => OAuthRequest::$version,
-        "oauth_nonce" => OAuthRequest::generate_nonce(),
-        "oauth_timestamp" => OAuthRequest::generate_timestamp(),
-        "oauth_consumer_key" => $consumer->key);
-    if ($token) $defaults['oauth_token'] = $token->key;
+                      "oauth_nonce" => OAuthRequest::generate_nonce(),
+                      "oauth_timestamp" => OAuthRequest::generate_timestamp(),
+                      "oauth_consumer_key" => $consumer->key);
+    if ($token)
+      $defaults['oauth_token'] = $token->key;
 
     $parameters = array_merge($defaults, $parameters);
 
@@ -241,8 +313,7 @@ class OAuthRequest {
       if (is_scalar($this->parameters[$name])) {
         // This is the first duplicate, so transform scalar (string)
         // into an array so we can add the duplicates
-        $this->parameters[$name] = array(
-            $this->parameters[$name]);
+        $this->parameters[$name] = array($this->parameters[$name]);
       }
 
       $this->parameters[$name][] = $value;
@@ -288,8 +359,11 @@ class OAuthRequest {
    * and the concated with &.
    */
   public function get_signature_base_string() {
-    $parts = array($this->get_normalized_http_method(), $this->get_normalized_http_url(),
-        $this->get_signable_parameters());
+    $parts = array(
+      $this->get_normalized_http_method(),
+      $this->get_normalized_http_url(),
+      $this->get_signable_parameters()
+    );
 
     $parts = OAuthUtil::urlencode_rfc3986($parts);
 
@@ -317,7 +391,8 @@ class OAuthRequest {
 
     $port or $port = ($scheme == 'https') ? '443' : '80';
 
-    if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port != '80')) {
+    if (($scheme == 'https' && $port != '443')
+        || ($scheme == 'http' && $port != '80')) {
       $host = "$host:$port";
     }
     return "$scheme://$host$path";
@@ -330,7 +405,7 @@ class OAuthRequest {
     $post_data = $this->to_postdata();
     $out = $this->get_normalized_http_url();
     if ($post_data) {
-      $out .= '?' . $post_data;
+      $out .= '?'.$post_data;
     }
     return $out;
   }
@@ -345,15 +420,26 @@ class OAuthRequest {
   /**
    * builds the Authorization: header
    */
-  public function to_header() {
-    $out = 'Authorization: OAuth realm=""';
+  public function to_header($realm=null) {
+    $first = true;
+	if($realm) {
+      $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"';
+      $first = false;
+    } else
+      $out = 'Authorization: OAuth';
+
     $total = array();
     foreach ($this->parameters as $k => $v) {
       if (substr($k, 0, 5) != "oauth") continue;
       if (is_array($v)) {
         throw new OAuthException('Arrays not supported in headers');
       }
-      $out .= ',' . OAuthUtil::urlencode_rfc3986($k) . '="' . OAuthUtil::urlencode_rfc3986($v) . '"';
+      $out .= ($first) ? ' ' : ',';
+      $out .= OAuthUtil::urlencode_rfc3986($k) .
+              '="' .
+              OAuthUtil::urlencode_rfc3986($v) .
+              '"';
+      $first = false;
     }
     return $out;
   }
@@ -362,8 +448,13 @@ class OAuthRequest {
     return $this->to_url();
   }
 
+
   public function sign_request($signature_method, $consumer, $token) {
-    $this->set_parameter("oauth_signature_method", $signature_method->get_name(), false);
+    $this->set_parameter(
+      "oauth_signature_method",
+      $signature_method->get_name(),
+      false
+    );
     $signature = $this->build_signature($signature_method, $consumer, $token);
     $this->set_parameter("oauth_signature", $signature, false);
   }
@@ -393,7 +484,7 @@ class OAuthRequest {
 
 class OAuthServer {
   protected $timestamp_threshold = 300; // in seconds, five minutes
-  protected $version = 1.0; // hi blaine
+  protected $version = '1.0';             // hi blaine
   protected $signature_methods = array();
 
   protected $data_store;
@@ -403,12 +494,12 @@ class OAuthServer {
   }
 
   public function add_signature_method($signature_method) {
-    $this->signature_methods[$signature_method->get_name()] = $signature_method;
+    $this->signature_methods[$signature_method->get_name()] =
+      $signature_method;
   }
 
   // high level functions
 
-
   /**
    * process a request_token request
    * returns the request token on success
@@ -423,7 +514,9 @@ class OAuthServer {
 
     $this->check_signature($request, $consumer, $token);
 
-    $new_token = $this->data_store->new_request_token($consumer);
+    // Rev A change
+    $callback = $request->get_parameter('oauth_callback');
+    $new_token = $this->data_store->new_request_token($consumer, $callback);
 
     return $new_token;
   }
@@ -442,7 +535,9 @@ class OAuthServer {
 
     $this->check_signature($request, $consumer, $token);
 
-    $new_token = $this->data_store->new_access_token($token, $consumer);
+    // Rev A change
+    $verifier = $request->get_parameter('oauth_verifier');
+    $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
 
     return $new_token;
   }
@@ -464,10 +559,12 @@ class OAuthServer {
    */
   private function get_version(&$request) {
     $version = $request->get_parameter("oauth_version");
-    if (! $version) {
-      $version = 1.0;
+    if (!$version) {
+      // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present. 
+      // Chapter 7.0 ("Accessing Protected Ressources")
+      $version = '1.0';
     }
-    if ($version && $version != $this->version) {
+    if ($version !== $this->version) {
       throw new OAuthException("OAuth version '$version' not supported");
     }
     return $version;
@@ -477,12 +574,22 @@ class OAuthServer {
    * figure out the signature with some defaults
    */
   private function get_signature_method(&$request) {
-    $signature_method = @$request->get_parameter("oauth_signature_method");
-    if (! $signature_method) {
-      $signature_method = "PLAINTEXT";
-    }
-    if (! in_array($signature_method, array_keys($this->signature_methods))) {
-      throw new OAuthException("Signature method '$signature_method' not supported " . "try one of the following: " . implode(", ", array_keys($this->signature_methods)));
+    $signature_method =
+        @$request->get_parameter("oauth_signature_method");
+
+    if (!$signature_method) {
+      // According to chapter 7 ("Accessing Protected Ressources") the signature-method
+      // parameter is required, and we can't just fallback to PLAINTEXT
+      throw new OAuthException('No signature method parameter. This parameter is required');
+    }
+
+    if (!in_array($signature_method,
+                  array_keys($this->signature_methods))) {
+      throw new OAuthException(
+        "Signature method '$signature_method' not supported " .
+        "try one of the following: " .
+        implode(", ", array_keys($this->signature_methods))
+      );
     }
     return $this->signature_methods[$signature_method];
   }
@@ -492,12 +599,12 @@ class OAuthServer {
    */
   private function get_consumer(&$request) {
     $consumer_key = @$request->get_parameter("oauth_consumer_key");
-    if (! $consumer_key) {
+    if (!$consumer_key) {
       throw new OAuthException("Invalid consumer key");
     }
 
     $consumer = $this->data_store->lookup_consumer($consumer_key);
-    if (! $consumer) {
+    if (!$consumer) {
       throw new OAuthException("Invalid consumer");
     }
 
@@ -507,10 +614,12 @@ class OAuthServer {
   /**
    * try to find the token for the provided request's token key
    */
-  private function get_token(&$request, $consumer, $token_type = "access") {
+  private function get_token(&$request, $consumer, $token_type="access") {
     $token_field = @$request->get_parameter('oauth_token');
-    $token = $this->data_store->lookup_token($consumer, $token_type, $token_field);
-    if (! $token) {
+    $token = $this->data_store->lookup_token(
+      $consumer, $token_type, $token_field
+    );
+    if (!$token) {
       throw new OAuthException("Invalid $token_type token: $token_field");
     }
     return $token;
@@ -531,9 +640,14 @@ class OAuthServer {
     $signature_method = $this->get_signature_method($request);
 
     $signature = $request->get_parameter('oauth_signature');
-    $valid_sig = $signature_method->check_signature($request, $consumer, $token, $signature);
+    $valid_sig = $signature_method->check_signature(
+      $request,
+      $consumer,
+      $token,
+      $signature
+    );
 
-    if (! $valid_sig) {
+    if (!$valid_sig) {
       throw new OAuthException("Invalid signature");
     }
   }
@@ -542,10 +656,17 @@ class OAuthServer {
    * check that the timestamp is new enough
    */
   private function check_timestamp($timestamp) {
+    if( ! $timestamp )
+      throw new OAuthException(
+        'Missing timestamp parameter. The parameter is required'
+      );
+    
     // verify that timestamp is recentish
     $now = time();
-    if ($now - $timestamp > $this->timestamp_threshold) {
-      throw new OAuthException("Expired timestamp, yours $timestamp, ours $now");
+    if (abs($now - $timestamp) > $this->timestamp_threshold) {
+      throw new OAuthException(
+        "Expired timestamp, yours $timestamp, ours $now"
+      );
     }
   }
 
@@ -553,8 +674,18 @@ class OAuthServer {
    * check that the nonce is not repeated
    */
   private function check_nonce($consumer, $token, $nonce, $timestamp) {
+    if( ! $nonce )
+      throw new OAuthException(
+        'Missing nonce parameter. The parameter is required'
+      );
+
     // verify that the nonce is uniqueish
-    $found = $this->data_store->lookup_nonce($consumer, $token, $nonce, $timestamp);
+    $found = $this->data_store->lookup_nonce(
+      $consumer,
+      $token,
+      $nonce,
+      $timestamp
+    );
     if ($found) {
       throw new OAuthException("Nonce already used: $nonce");
     }
@@ -563,38 +694,46 @@ class OAuthServer {
 }
 
 class OAuthDataStore {
-
-  function lookup_consumer($consumer_key) {  // implement me
+  function lookup_consumer($consumer_key) {
+    // implement me
   }
 
-  function lookup_token($consumer, $token_type, $token) {  // implement me
+  function lookup_token($consumer, $token_type, $token) {
+    // implement me
   }
 
-  function lookup_nonce($consumer, $token, $nonce, $timestamp) {  // implement me
+  function lookup_nonce($consumer, $token, $nonce, $timestamp) {
+    // implement me
   }
 
-  function new_request_token($consumer) {  // return a new token attached to this consumer
+  function new_request_token($consumer, $callback = null) {
+    // return a new token attached to this consumer
   }
 
-  function new_access_token($token, $consumer) {  // return a new access token attached to this consumer
-  // for the user associated with this token if the request token
-  // is authorized
-  // should also invalidate the request token
+  function new_access_token($token, $consumer, $verifier = null) {
+    // return a new access token attached to this consumer
+    // for the user associated with this token if the request token
+    // is authorized
+    // should also invalidate the request token
   }
 
 }
 
 class OAuthUtil {
-
   public static function urlencode_rfc3986($input) {
-    if (is_array($input)) {
-      return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
-    } else if (is_scalar($input)) {
-      return str_replace('+', ' ', str_replace('%7E', '~', rawurlencode($input)));
-    } else {
-      return '';
-    }
+  if (is_array($input)) {
+    return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
+  } else if (is_scalar($input)) {
+    return str_replace(
+      '+',
+      ' ',
+      str_replace('%7E', '~', rawurlencode($input))
+    );
+  } else {
+    return '';
   }
+}
+
 
   // This decode function isn't taking into consideration the above
   // modifications to the encoding process. However, this method doesn't
@@ -606,24 +745,18 @@ class OAuthUtil {
   // Utility function for turning the Authorization: header into
   // parameters, has to do some unescaping
   // Can filter out any non-oauth parameters if needed (default behaviour)
+  // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement.
+  //                  see http://code.google.com/p/oauth/issues/detail?id=163
   public static function split_header($header, $only_allow_oauth_parameters = true) {
-    $pattern = '/(([-_a-z]*)=("([^"]*)"|([^,]*)),?)/';
-    $offset = 0;
     $params = array();
-    while (preg_match($pattern, $header, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
-      $match = $matches[0];
-      $header_name = $matches[2][0];
-      $header_content = (isset($matches[5])) ? $matches[5][0] : $matches[4][0];
-      if (preg_match('/^oauth_/', $header_name) || ! $only_allow_oauth_parameters) {
-        $params[$header_name] = OAuthUtil::urldecode_rfc3986($header_content);
+    if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
+      foreach ($matches[1] as $i => $h) {
+        $params[$h] = OAuthUtil::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
+      }
+      if (isset($params['realm'])) {
+        unset($params['realm']);
       }
-      $offset = $match[1] + strlen($match[0]);
-    }
-
-    if (isset($params['realm'])) {
-      unset($params['realm']);
     }
-
     return $params;
   }
 
@@ -632,19 +765,43 @@ class OAuthUtil {
     if (function_exists('apache_request_headers')) {
       // we need this to get the actual Authorization: header
       // because apache tends to tell us it doesn't exist
-      return apache_request_headers();
-    }
-    // otherwise we don't have apache and are just going to have to hope
-    // that $_SERVER actually contains what we need
-    $out = array();
-    foreach ($_SERVER as $key => $value) {
-      if (substr($key, 0, 5) == "HTTP_") {
-        // this is chaos, basically it is just there to capitalize the first
-        // letter of every word that is not an initial HTTP and strip HTTP
-        // code from przemek
-        $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
+      $headers = apache_request_headers();
+
+      // sanitize the output of apache_request_headers because
+      // we always want the keys to be Cased-Like-This and arh()
+      // returns the headers in the same case as they are in the
+      // request
+      $out = array();
+      foreach ($headers AS $key => $value) {
+        $key = str_replace(
+            " ",
+            "-",
+            ucwords(strtolower(str_replace("-", " ", $key)))
+          );
         $out[$key] = $value;
       }
+    } else {
+      // otherwise we don't have apache and are just going to have to hope
+      // that $_SERVER actually contains what we need
+      $out = array();
+      if( isset($_SERVER['CONTENT_TYPE']) )
+        $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
+      if( isset($_ENV['CONTENT_TYPE']) )
+        $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
+
+      foreach ($_SERVER as $key => $value) {
+        if (substr($key, 0, 5) == "HTTP_") {
+          // this is chaos, basically it is just there to capitalize the first
+          // letter of every word that is not an initial HTTP and strip HTTP
+          // code from przemek
+          $key = str_replace(
+            " ",
+            "-",
+            ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
+          );
+          $out[$key] = $value;
+        }
+      }
     }
     return $out;
   }
@@ -652,8 +809,8 @@ class OAuthUtil {
   // This function takes a input like a=b&a=c&d=e and returns the parsed
   // parameters like this
   // array('a' => array('b','c'), 'd' => 'e')
-  public static function parse_parameters($input) {
-    if (! isset($input) || ! $input) return array();
+  public static function parse_parameters( $input ) {
+    if (!isset($input) || !$input) return array();
 
     $pairs = explode('&', $input);
 
@@ -667,12 +824,10 @@ class OAuthUtil {
         // We have already recieved parameter(s) with this name, so add to the list
         // of parameters with this name
 
-
         if (is_scalar($parsed_parameters[$parameter])) {
           // This is the first duplicate, so transform scalar (string) into an array
           // so we can add the duplicates
-          $parsed_parameters[$parameter] = array(
-              $parsed_parameters[$parameter]);
+          $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
         }
 
         $parsed_parameters[$parameter][] = $value;
@@ -684,7 +839,7 @@ class OAuthUtil {
   }
 
   public static function build_http_query($params) {
-    if (! $params) return '';
+    if (!$params) return '';
 
     // Urlencode both keys and values
     $keys = OAuthUtil::urlencode_rfc3986(array_keys($params));

Modified: shindig/branches/2.0.x/php/src/gadgets/GadgetSpecParser.php
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/php/src/gadgets/GadgetSpecParser.php?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/php/src/gadgets/GadgetSpecParser.php (original)
+++ shindig/branches/2.0.x/php/src/gadgets/GadgetSpecParser.php Wed Jun 23 06:23:54 2010
@@ -44,7 +44,6 @@ class GadgetSpecParser {
     $gadget = new GadgetSpec();
     $gadget->checksum = md5($xmlContent);
     $this->parseModulePrefs($doc, $gadget);
-    $this->parseLinks($doc, $gadget);
     $this->parseUserPrefs($doc, $gadget);
     $this->parseViews($doc, $gadget);
     //TODO: parse pipelined data
@@ -137,12 +136,12 @@ class GadgetSpecParser {
   /**
    * Parses the link spec elements
    *
-   * @param DOMDocument $doc
+   * @param DOMElement $modulePrefs
    * @param GadgetSpec $gadget
    */
-  private function parseLinks(DOMDocument &$doc, GadgetSpec &$gadget) {
+  private function parseLinks(DOMElement &$modulePrefs, GadgetSpec &$gadget) {
     $gadget->links = array();
-    if (($links = $doc->getElementsByTagName('link')) != null) {
+    if (($links = $modulePrefs->getElementsByTagName('Link')) != null) {
       foreach ($links as $linkNode) {
         $gadget->links[] = array('rel' => $linkNode->getAttribute('rel'),
             'href' => $linkNode->getAttribute('href'),
@@ -183,6 +182,7 @@ class GadgetSpecParser {
       }
     }
     // And parse the child nodes
+    $this->parseLinks($modulePrefs, $gadget);
     $this->parseIcon($modulePrefs, $gadget);
     $this->parseFeatures($modulePrefs, $gadget);
     $this->parsePreloads($modulePrefs, $gadget);

Modified: shindig/branches/2.0.x/php/src/gadgets/SigningFetcher.php
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/php/src/gadgets/SigningFetcher.php?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/php/src/gadgets/SigningFetcher.php (original)
+++ shindig/branches/2.0.x/php/src/gadgets/SigningFetcher.php Wed Jun 23 06:23:54 2010
@@ -94,19 +94,9 @@ class SigningFetcher extends RemoteConte
       // any OAuth or OpenSocial parameters injected by the client
       $parsedUri = parse_url($url);
       $resource = $url;
-      $queryParams = array();
-      if (isset($parsedUri['query'])) {
-        parse_str($parsedUri['query'], $queryParams);
-        // strip out all opensocial_* and oauth_* params so they can't be spoofed by the client
-        foreach ($queryParams as $key => $val) {
-          if ((strtolower(substr($key, 0, strlen('opensocial_'))) == 'opensocial_') || (strtolower(substr($key, 0, strlen('oauth_'))) == 'oauth_')) {
-            unset($queryParams[$key]);
-          }
-        }
-        $queryParams = $this->sanitize($queryParams);
-      }
       $contentType = $request->getHeader('Content-Type');
       $signBody = (stripos($contentType, 'application/x-www-form-urlencoded') !== false || $contentType == null);
+      $msgParams = array();
       if ($request->getPostBody()) {
         if ($signBody) {
           $postParams = array();
@@ -116,11 +106,9 @@ class SigningFetcher extends RemoteConte
         } else {
           // on any other content-type of post (application/{json,xml,xml+atom}) use the body signing hash
           // see http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/drafts/4/spec.html for details
-          $queryParams['oauth_body_hash'] = base64_encode(sha1($request->getPostBody(), true));
+          $msgParams['oauth_body_hash'] = base64_encode(sha1($request->getPostBody(), true));
         }
       }
-      $msgParams = array();
-      $msgParams = array_merge($msgParams, $queryParams);
       if ($signBody && isset($postParams)) {
         $msgParams = array_merge($msgParams, $postParams);
       }
@@ -151,15 +139,13 @@ class SigningFetcher extends RemoteConte
       $newQuery = '';
       foreach ($req_req->get_parameters() as $key => $param) {
         if (! isset($forPost[$key])) {
-          $newQuery .= urlencode($key) . '=' . urlencode($param) . '&';
-        }
-      }
-      // and stick on the original query params too
-      if (isset($parsedUri['query']) && ! empty($parsedUri['query'])) {
-        $oldQuery = array();
-        parse_str($parsedUri['query'], $oldQuery);
-        foreach ($oldQuery as $key => $val) {
-          $newQuery .= urlencode($key) . '=' . urlencode($val) . '&';
+          if (!is_array($param)) {
+            $newQuery .= urlencode($key) . '=' . urlencode($param) . '&';
+          } else {
+            foreach($param as $elem) {
+              $newQuery .= urlencode($key) . '=' . urlencode($elem) . '&';
+            }
+          }
         }
       }
       // Careful here; the OAuth form encoding scheme is slightly different than

Modified: shindig/branches/2.0.x/php/src/gadgets/oauth/OAuthFetcher.php
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/php/src/gadgets/oauth/OAuthFetcher.php?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/php/src/gadgets/oauth/OAuthFetcher.php (original)
+++ shindig/branches/2.0.x/php/src/gadgets/oauth/OAuthFetcher.php Wed Jun 23 06:23:54 2010
@@ -18,6 +18,9 @@
  * under the License.
  */
 
+// For TokenInfo
+require 'src/gadgets/oauth/OAuthStore.php';
+
 /**
  * Implements the OAuth dance (http://oauth.net/core/1.0/) for gadgets.
  *

Modified: shindig/branches/2.0.x/php/test/gadgets/SigningFetcherTest.php
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/php/test/gadgets/SigningFetcherTest.php?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/php/test/gadgets/SigningFetcherTest.php (original)
+++ shindig/branches/2.0.x/php/test/gadgets/SigningFetcherTest.php Wed Jun 23 06:23:54 2010
@@ -42,6 +42,9 @@ nbpJMipy62GBW7yBbG+ypSasgI0=
 -----END CERTIFICATE-----
 EOD;
   }
+  protected function fetch_private_cert(&$request) {
+    ;
+  }
 }
 
 /**

Modified: shindig/branches/2.0.x/pom.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/pom.xml?rev=957119&r1=957118&r2=957119&view=diff
==============================================================================
--- shindig/branches/2.0.x/pom.xml (original)
+++ shindig/branches/2.0.x/pom.xml Wed Jun 23 06:23:54 2010
@@ -490,7 +490,7 @@
             <artifactId>maven-jetty-plugin</artifactId>
             <configuration>
               <tempDirectory>${basedir}/java/server/target/work</tempDirectory>
-              <webApp>${basedir}/java/server/target/shindig-server-${pom.version}.war</webApp>
+              <webApp>${basedir}/java/server/target/shindig-server-${project.version}.war</webApp>
               <contextPath>/</contextPath>
             </configuration>
           </plugin>
@@ -531,30 +531,12 @@
                 </includes>
               </instrumentation>
             </configuration>
-            <executions>
-              <execution>
-                <id>clean</id>
-                <phase>pre-site</phase>
-                <goals>
-                  <goal>clean</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>instrument</id>
-                <phase>site</phase>
-                <goals>
-                  <goal>instrument</goal>
-                  <goal>cobertura</goal>
-                  <goal>check</goal>
-                </goals>
-              </execution>
-            </executions>
           </plugin>
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-site-plugin</artifactId>
             <configuration>
-              <stagingSiteURL>scp://people.apache.org/www/shindig.apache.org/shindig-1.1.x/${pom.version}</stagingSiteURL>
+              <stagingSiteURL>scp://people.apache.org/www/shindig.apache.org/shindig-2.0.x/${project.version}</stagingSiteURL>
             </configuration>
           </plugin>
          <plugin>
@@ -613,7 +595,7 @@
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-jxr-plugin</artifactId>
-            <version>2.1</version>
+            <version>2.2</version>
             <configuration>
               <inputEncoding>${project.build.sourceEncoding}</inputEncoding>
               <outputEncoding>${project.build.sourceEncoding}</outputEncoding>
@@ -713,23 +695,10 @@
           </plugin>
 
           <!-- Mojo -->
-          <!--plugin>
-            <groupId>org.codehaus.mojo</groupId>
-            <artifactId>clirr-maven-plugin</artifactId>
-            <version>2.2.2</version>
-          </plugin-->
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>clirr-maven-plugin</artifactId>
-        <configuration>
-          <!-- Compare the current code against version 1.2 -->
-          <comparisonVersion>1.0.1</comparisonVersion>
-        </configuration>
-      </plugin>
           <plugin>
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>cobertura-maven-plugin</artifactId>
-            <version>2.3</version>
+            <version>2.4</version>
           </plugin>
           <plugin>
             <groupId>org.codehaus.mojo</groupId>
@@ -756,12 +725,32 @@
             <artifactId>taglist-maven-plugin</artifactId>
             <version>2.4</version>
             <configuration>
-              <tags>
-                <tag>TODO</tag>
-                <tag>FIXME</tag>
-                <tag>@todo</tag>
-                <tag>@deprecated</tag>
-              </tags>
+              <tagListOptions>
+                <tagClasses>
+                  <tagClass>
+                    <displayName>Todo Work</displayName>
+                    <tags>
+                      <tag>
+                        <matchString>todo</matchString>
+                        <matchType>ignoreCase</matchType>
+                      </tag>
+                      <tag>
+                        <matchString>FIXME</matchString>
+                        <matchType>exact</matchType>
+                      </tag>
+                    </tags>
+                  </tagClass>
+                  <tagClass>
+                    <displayName>Deprecated</displayName>
+                    <tags>
+                      <tag>
+                        <matchString>@deprecated</matchString>
+                        <matchType>exact</matchType>
+                      </tag>
+                    </tags>
+                  </tagClass>
+                </tagClasses>
+              </tagListOptions>
               <encoding>${project.build.sourceEncoding}</encoding>
             </configuration>
             <reportSets>
@@ -901,7 +890,7 @@
               <xslFile>${basedir}/etc/to-committers.xsl</xslFile>
               <srcIncludes>pom.xml</srcIncludes>
               <srcDir>${basedir}</srcDir>
-              <destDir>${build.directory}</destDir>
+              <destDir>${project.build.directory}</destDir>
               <fileNameRegex>pom.xml</fileNameRegex>
               <fileNameReplacement>COMMITTERS</fileNameReplacement>
             </configuration>
@@ -972,6 +961,11 @@
         </plugin>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-gpg-plugin</artifactId>
+          <version>1.1</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-install-plugin</artifactId>
           <version>2.3.1</version>
         </plugin>
@@ -1028,7 +1022,7 @@
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-site-plugin</artifactId>
-          <version>2.0.1</version>
+          <version>2.1.1</version>
           <configuration>
             <inputEncoding>${project.build.sourceEncoding}</inputEncoding>
             <outputEncoding>${project.build.sourceEncoding}</outputEncoding>
@@ -1276,6 +1270,11 @@
       <id>java.net</id>
       <url>http://download.java.net/maven/2/</url>
     </repository>
+    <repository>
+      <id>mortbay-release-repo</id>
+      <name>MortBay Release Repo</name>
+      <url>http://jetty.mortbay.org/maven2/release</url>
+    </repository>
   </repositories>
 
   <!-- ====================================================================== -->
@@ -1396,13 +1395,13 @@
      <dependency>
        <groupId>caja</groupId>
        <artifactId>htmlparser</artifactId>
-       <version>r4067</version>
+       <version>r4135</version>
        <scope>compile</scope>
      </dependency>
       <dependency>
         <groupId>caja</groupId>
         <artifactId>caja</artifactId>
-        <version>r4067</version>
+        <version>r4135</version>
         <scope>compile</scope>
       </dependency>
       <dependency>
@@ -1545,12 +1544,12 @@
       <dependency>
         <groupId>de.odysseus.juel</groupId>
         <artifactId>juel-api</artifactId>
-        <version>2.1.2</version>
+        <version>2.1.3</version>
       </dependency>
       <dependency>
         <groupId>de.odysseus.juel</groupId>
         <artifactId>juel-impl</artifactId>
-        <version>2.1.2</version>
+        <version>2.1.3</version>
       </dependency>
       <dependency>
         <groupId>net.sf.ezmorph</groupId>