shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject svn commit: r1213769 - in /shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/oauth2/ main/java/org/apache/shindig/gadgets/oauth2/handler/ test/java/org/apache/shindig/gadgets/http/ test/java/org/apache/shindig/gadgets/oauth2/handler/
Date Tue, 13 Dec 2011 16:23:54 GMT
Author: lixu
Date: Tue Dec 13 16:23:54 2011
New Revision: 1213769

URL: http://svn.apache.org/viewvc?rev=1213769&view=rev
Log:
SHINDIG-1672 | Patch from Doug Davies | Support additional OAuth2RequestParameters

Added:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2RequestParameterGenerator.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2RequestParameterGenerator.java
Modified:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Accessor.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Request.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Accessor.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Module.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/BasicAuthenticationHandler.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/ClientCredentialsGrantTypeHandler.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandler.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/StandardAuthenticationHandler.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandlerTest.java

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Accessor.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Accessor.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Accessor.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Accessor.java Tue Dec 13 16:23:54 2011
@@ -16,6 +16,10 @@
  */
 package org.apache.shindig.gadgets.oauth2;
 
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+
 /**
  * 
  * see {@link OAuth2Accessor}
@@ -48,9 +52,10 @@ public class BasicOAuth2Accessor impleme
   private Type type;
   private boolean urlParameter;
   private final String user;
+  private Map<String, String> additionalRequestParams;
 
   BasicOAuth2Accessor(final Throwable exception, final OAuth2Error error,
-      final String contextMessage, final String errorUri) {
+          final String contextMessage, final String errorUri) {
     this.serviceName = null;
     this.scope = null;
     this.state = null;
@@ -60,6 +65,7 @@ public class BasicOAuth2Accessor impleme
     this.gadgetUri = null;
     this.globalRedirectUri = null;
     this.allowModuleOverrides = false;
+    this.additionalRequestParams = Maps.newHashMap();
     this.setErrorResponse(exception, error, contextMessage, errorUri);
   }
 
@@ -89,11 +95,12 @@ public class BasicOAuth2Accessor impleme
     this.errorContextMessage = accessor.getErrorContextMessage();
     this.errorException = accessor.getErrorException();
     this.errorUri = accessor.getErrorUri();
+    this.additionalRequestParams = Maps.newHashMap();
   }
 
   public BasicOAuth2Accessor(final String gadgetUri, final String serviceName, final String user,
-      final String scope, final boolean allowModuleOverrides, final OAuth2Store store,
-      final String globalRedirectUri) {
+          final String scope, final boolean allowModuleOverrides, final OAuth2Store store,
+          final String globalRedirectUri) {
     this.gadgetUri = gadgetUri;
     this.serviceName = serviceName;
     this.user = user;
@@ -103,6 +110,7 @@ public class BasicOAuth2Accessor impleme
     this.state = store.getOAuth2AccessorIndex(gadgetUri, serviceName, user, scope).toString();
     this.errorResponse = false;
     this.redirecting = false;
+    this.additionalRequestParams = Maps.newHashMap();
   }
 
   public OAuth2Token getAccessToken() {
@@ -160,6 +168,10 @@ public class BasicOAuth2Accessor impleme
     return this.refreshToken;
   }
 
+  public Map<String, String> getAdditionalRequestParams() {
+    return this.additionalRequestParams;
+  }
+
   public String getScope() {
     return this.scope;
   }
@@ -249,7 +261,7 @@ public class BasicOAuth2Accessor impleme
   }
 
   public void setErrorResponse(Throwable exception, OAuth2Error error, String contextMessage,
-      String errorUri) {
+          String errorUri) {
     this.errorResponse = true;
     this.errorException = exception;
     if (error != null) {
@@ -279,6 +291,10 @@ public class BasicOAuth2Accessor impleme
     this.refreshToken = refreshToken;
   }
 
+  public void setAdditionalRequestParams(Map<String, String> additionalRequestParams) {
+    this.additionalRequestParams = additionalRequestParams;
+  }
+
   public void setTokenUrl(final String tokenUrl) {
     this.tokenUrl = tokenUrl;
   }

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Request.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Request.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Request.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2Request.java Tue Dec 13 16:23:54 2011
@@ -47,7 +47,7 @@ import com.google.inject.Inject;
 public class BasicOAuth2Request implements OAuth2Request {
   private final static String LOG_CLASS = BasicOAuth2Request.class.getName();
   private final static FilteredLogger LOG = FilteredLogger
-      .getFilteredLogger(BasicOAuth2Request.LOG_CLASS);
+          .getFilteredLogger(BasicOAuth2Request.LOG_CLASS);
 
   private OAuth2Accessor _accessor;
 
@@ -77,6 +77,8 @@ public class BasicOAuth2Request implemen
 
   private final boolean sendTraceToClient;
 
+  private final OAuth2RequestParameterGenerator requestParameterGenerator;
+
   /**
    * @param fetcherConfig
    *          configuration options for the fetcher
@@ -85,12 +87,13 @@ public class BasicOAuth2Request implemen
    */
   @Inject
   public BasicOAuth2Request(final OAuth2FetcherConfig fetcherConfig, final HttpFetcher fetcher,
-      final List<AuthorizationEndpointResponseHandler> authorizationEndpointResponseHandlers,
-      final List<ClientAuthenticationHandler> clientAuthenticationHandlers,
-      final List<GrantRequestHandler> grantRequestHandlers,
-      final List<ResourceRequestHandler> resourceRequestHandlers,
-      final List<TokenEndpointResponseHandler> tokenEndpointResponseHandlers,
-      final boolean sendTraceToClient) {
+          final List<AuthorizationEndpointResponseHandler> authorizationEndpointResponseHandlers,
+          final List<ClientAuthenticationHandler> clientAuthenticationHandlers,
+          final List<GrantRequestHandler> grantRequestHandlers,
+          final List<ResourceRequestHandler> resourceRequestHandlers,
+          final List<TokenEndpointResponseHandler> tokenEndpointResponseHandlers,
+          final boolean sendTraceToClient,
+          final OAuth2RequestParameterGenerator requestParameterGenerator) {
     this.fetcherConfig = fetcherConfig;
     if (this.fetcherConfig != null) {
       this.store = this.fetcherConfig.getOAuth2Store();
@@ -104,20 +107,21 @@ public class BasicOAuth2Request implemen
     this.resourceRequestHandlers = resourceRequestHandlers;
     this.tokenEndpointResponseHandlers = tokenEndpointResponseHandlers;
     this.sendTraceToClient = sendTraceToClient;
+    this.requestParameterGenerator = requestParameterGenerator;
 
     if (BasicOAuth2Request.LOG.isLoggable()) {
       BasicOAuth2Request.LOG.log("this.fetcherConfig = {0}", this.fetcherConfig);
       BasicOAuth2Request.LOG.log("this.store = {0}", this.store);
       BasicOAuth2Request.LOG.log("this.fetcher = {0}", this.fetcher);
       BasicOAuth2Request.LOG.log("this.authorizationEndpointResponseHandlers = {0}",
-          this.authorizationEndpointResponseHandlers);
+              this.authorizationEndpointResponseHandlers);
       BasicOAuth2Request.LOG.log("this.clientAuthenticationHandlers = {0}",
-          this.clientAuthenticationHandlers);
+              this.clientAuthenticationHandlers);
       BasicOAuth2Request.LOG.log("this.grantRequestHandlers = {0}", this.grantRequestHandlers);
       BasicOAuth2Request.LOG
-          .log("this.resourceRequestHandlers = {0}", this.resourceRequestHandlers);
+              .log("this.resourceRequestHandlers = {0}", this.resourceRequestHandlers);
       BasicOAuth2Request.LOG.log("this.tokenEndpointResponseHandlers = {0}",
-          this.tokenEndpointResponseHandlers);
+              this.tokenEndpointResponseHandlers);
       BasicOAuth2Request.LOG.log("this.sendTraceToClient = {0}", this.sendTraceToClient);
     }
   }
@@ -137,7 +141,7 @@ public class BasicOAuth2Request implemen
       if ((request == null) || (request.getSecurityToken() == null)) {
         // Any errors before we have an accessor are special cases
         response = this.sendErrorResponse(null, OAuth2Error.MISSING_FETCH_PARAMS,
-            "no request or security token", "");
+                "no request or security token", "");
       } else {
         this.realRequest = request;
         this.securityToken = request.getSecurityToken();
@@ -154,7 +158,7 @@ public class BasicOAuth2Request implemen
         if ((this.responseParams == null) || (this.arguments == null)) {
           // Any errors before we have an accessor are special cases
           return this.sendErrorResponse(null, OAuth2Error.FETCH_INIT_PROBLEM,
-              "no responseParams or arguments", "");
+                  "no responseParams or arguments", "");
         }
 
         accessor = this.getAccessor();
@@ -166,10 +170,14 @@ public class BasicOAuth2Request implemen
         if (accessor == null) {
           // Any errors before we have an accessor are special cases
           response = this.sendErrorResponse(null, OAuth2Error.FETCH_INIT_PROBLEM,
-              "accessor is null", "");
+                  "accessor is null", "");
         } else {
           accessor.setRedirecting(false);
 
+          Map<String, String> requestParams = requestParameterGenerator
+                  .generateParams(this.realRequest);
+          accessor.setAdditionalRequestParams(requestParams);
+
           HttpResponseBuilder responseBuilder = null;
           if (!accessor.isErrorResponse()) {
             responseBuilder = this.attemptFetch(accessor, false);
@@ -184,13 +192,13 @@ public class BasicOAuth2Request implemen
       }
       if (accessor == null) {
         accessor = new BasicOAuth2Accessor(t, OAuth2Error.FETCH_PROBLEM,
-            "exception occurred during fetch", "");
+                "exception occurred during fetch", "");
       } else {
         accessor.setErrorResponse(t, OAuth2Error.FETCH_PROBLEM, "exception occurred during fetch",
-            "");
+                "");
       }
       response = this.processResponse(accessor, this.getErrorResponseBuilder(t,
-          OAuth2Error.FETCH_PROBLEM, "exception occurred during fetch", ""));
+              OAuth2Error.FETCH_PROBLEM, "exception occurred during fetch", ""));
     } finally {
       if (accessor != null) {
         if (!accessor.isRedirecting()) {
@@ -212,7 +220,7 @@ public class BasicOAuth2Request implemen
     final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
     if (isLogging) {
       BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "attemptFetch", new Object[] {
-          accessor, tryAgain });
+              accessor, tryAgain });
     }
 
     HttpResponseBuilder ret = null;
@@ -235,7 +243,7 @@ public class BasicOAuth2Request implemen
               // There was an error refreshing, stop.
               final OAuth2Error error = handlerError.getError();
               ret = this.getErrorResponseBuilder(handlerError.getCause(), error,
-                  handlerError.getContextMessage(), "");
+                      handlerError.getContextMessage(), "");
             }
           } else {
             // User cannot refresh, they'll have to try to authorize again.
@@ -299,7 +307,7 @@ public class BasicOAuth2Request implemen
 
     if (grantRequestHandlerUsed == null) {
       accessor.setErrorResponse(null, OAuth2Error.AUTHENTICATION_PROBLEM,
-          "no grantRequestHandler found for " + grantType, "");
+              "no grantRequestHandler found for " + grantType, "");
     } else {
       String completeAuthUrl = null;
       try {
@@ -313,10 +321,10 @@ public class BasicOAuth2Request implemen
         ret = completeAuthUrl;
       } else {
         final OAuth2HandlerError error = this.authorize(accessor, grantRequestHandlerUsed,
-            completeAuthUrl);
+                completeAuthUrl);
         if (error != null) {
           accessor.setErrorResponse(error.getCause(), OAuth2Error.AUTHENTICATION_PROBLEM,
-              error.getContextMessage(), "");
+                  error.getContextMessage(), "");
         }
       }
     }
@@ -329,12 +337,12 @@ public class BasicOAuth2Request implemen
   }
 
   private OAuth2HandlerError authorize(final OAuth2Accessor accessor,
-      final GrantRequestHandler grantRequestHandler, final String completeAuthUrl) {
+          final GrantRequestHandler grantRequestHandler, final String completeAuthUrl) {
 
     final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
     if (isLogging) {
       BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "authorize", new Object[] {
-          accessor, grantRequestHandler, completeAuthUrl });
+              accessor, grantRequestHandler, completeAuthUrl });
     }
 
     OAuth2HandlerError ret = null;
@@ -361,7 +369,7 @@ public class BasicOAuth2Request implemen
         }
         authorizationResponse = null;
         ret = new OAuth2HandlerError(OAuth2Error.AUTHORIZE_PROBLEM,
-            "exception thrown fetching authorization", e);
+                "exception thrown fetching authorization", e);
       }
 
       if (isLogging) {
@@ -372,13 +380,13 @@ public class BasicOAuth2Request implemen
         if (grantRequestHandler.isAuthorizationEndpointResponse()) {
           for (final AuthorizationEndpointResponseHandler authorizationEndpointResponseHandler : this.authorizationEndpointResponseHandlers) {
             if (authorizationEndpointResponseHandler.handlesResponse(accessor,
-                authorizationResponse)) {
+                    authorizationResponse)) {
               if (isLogging) {
                 BasicOAuth2Request.LOG.log("using AuthorizationEndpointResponseHandler = {0}",
-                    authorizationEndpointResponseHandler);
+                        authorizationEndpointResponseHandler);
               }
               ret = authorizationEndpointResponseHandler.handleResponse(accessor,
-                  authorizationResponse);
+                      authorizationResponse);
               if (ret != null) {
                 // error occurred stop processing
                 break;
@@ -393,7 +401,7 @@ public class BasicOAuth2Request implemen
               if (tokenEndpointResponseHandler.handlesResponse(accessor, authorizationResponse)) {
                 if (isLogging) {
                   BasicOAuth2Request.LOG.log("using TokenEndpointResponseHandler = {0}",
-                      tokenEndpointResponseHandler);
+                          tokenEndpointResponseHandler);
                 }
                 ret = tokenEndpointResponseHandler.handleResponse(accessor, authorizationResponse);
                 if (ret != null) {
@@ -418,7 +426,7 @@ public class BasicOAuth2Request implemen
     final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
     if (isLogging) {
       BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "buildRefreshTokenUrl",
-          accessor);
+              accessor);
     }
 
     String ret = null;
@@ -457,11 +465,11 @@ public class BasicOAuth2Request implemen
 
     if ((pageOwner == null) || (pageViewer == null)) {
       accessor.setErrorResponse(null, OAuth2Error.AUTHORIZE_PROBLEM,
-          "pageOwner or pageViewer is null", "");
+              "pageOwner or pageViewer is null", "");
       ret = false;
     } else if (!this.fetcherConfig.isViewerAccessTokensEnabled() && !pageOwner.equals(pageViewer)) {
       accessor.setErrorResponse(null, OAuth2Error.AUTHORIZE_PROBLEM, "pageViewer is not pageOwner",
-          "");
+              "");
       ret = false;
     }
 
@@ -504,11 +512,11 @@ public class BasicOAuth2Request implemen
   }
 
   private HttpResponse fetchFromServer(final OAuth2Accessor accessor, final HttpRequest request)
-      throws OAuth2RequestException {
+          throws OAuth2RequestException {
     final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
     if (isLogging) {
       BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "fetchFromServer",
-          new Object[] { accessor, "only log request once" });
+              new Object[] { accessor, "only log request once" });
     }
 
     HttpResponse ret;
@@ -538,12 +546,12 @@ public class BasicOAuth2Request implemen
       ret = this.fetcher.fetch(request);
     } catch (final GadgetException e) {
       throw new OAuth2RequestException(OAuth2Error.MISSING_SERVER_RESPONSE,
-          "GadgetException fetchFromServer", e);
+              "GadgetException fetchFromServer", e);
     }
 
     if (ret == null) {
       throw new OAuth2RequestException(OAuth2Error.MISSING_SERVER_RESPONSE, "response is null",
-          null);
+              null);
     }
 
     final int responseCode = ret.getHttpStatusCode();
@@ -553,13 +561,13 @@ public class BasicOAuth2Request implemen
     }
 
     if ((responseCode >= HttpResponse.SC_BAD_REQUEST)
-        && (responseCode < HttpResponse.SC_INTERNAL_SERVER_ERROR)) {
+            && (responseCode < HttpResponse.SC_INTERNAL_SERVER_ERROR)) {
       if (accessToken != null) {
         try {
           this.store.removeToken(accessToken);
         } catch (final GadgetException e) {
           throw new OAuth2RequestException(OAuth2Error.MISSING_SERVER_RESPONSE,
-              "error removing access_token", null);
+                  "error removing access_token", null);
         }
         accessor.setAccessToken(null);
       }
@@ -569,7 +577,7 @@ public class BasicOAuth2Request implemen
           this.store.removeToken(refreshToken);
         } catch (final GadgetException e) {
           throw new OAuth2RequestException(OAuth2Error.MISSING_SERVER_RESPONSE,
-              "error removing refresh_token", null);
+                  "error removing refresh_token", null);
         }
         accessor.setRefreshToken(null);
       }
@@ -588,7 +596,7 @@ public class BasicOAuth2Request implemen
         final GadgetOAuth2TokenStore tokenStore = this.fetcherConfig.getTokenStore();
         if (tokenStore != null) {
           this._accessor = tokenStore.getOAuth2Accessor(this.securityToken, this.arguments,
-              this.realRequest.getGadget());
+                  this.realRequest.getGadget());
         }
       }
     }
@@ -601,16 +609,16 @@ public class BasicOAuth2Request implemen
   }
 
   private HttpResponseBuilder getErrorResponseBuilder(final Throwable t, final OAuth2Error error,
-      final String contextMessage, final String errorUri) {
+          final String contextMessage, final String errorUri) {
 
     final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
     if (isLogging) {
       BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "getErrorResponseBuilder",
-          new Object[] { t, error, contextMessage, errorUri });
+              new Object[] { t, error, contextMessage, errorUri });
     }
 
     final HttpResponseBuilder ret = new HttpResponseBuilder().setHttpStatusCode(
-        HttpResponse.SC_FORBIDDEN).setStrictNoCache();
+            HttpResponse.SC_FORBIDDEN).setStrictNoCache();
 
     if ((t != null) && (this.sendTraceToClient)) {
       final StringWriter sw = new StringWriter();
@@ -620,7 +628,7 @@ public class BasicOAuth2Request implemen
     }
 
     this.responseParams.addToResponse(ret, error.getErrorCode(),
-        error.getErrorDescription(contextMessage), errorUri, error.getErrorExplanation());
+            error.getErrorDescription(contextMessage), errorUri, error.getErrorExplanation());
 
     if (isLogging) {
       BasicOAuth2Request.LOG.exiting(BasicOAuth2Request.LOG_CLASS, "getErrorResponseBuilder", ret);
@@ -642,7 +650,7 @@ public class BasicOAuth2Request implemen
       queryParams = Maps.newHashMap();
       queryParams.put(OAuth2Message.GRANT_TYPE, OAuth2Message.REFRESH_TOKEN);
       queryParams.put(OAuth2Message.REFRESH_TOKEN, new String(accessor.getRefreshToken()
-          .getSecret(), "UTF-8"));
+              .getSecret(), "UTF-8"));
       if ((accessor.getScope() != null) && (accessor.getScope().length() > 0)) {
         queryParams.put(OAuth2Message.SCOPE, accessor.getScope());
       }
@@ -673,22 +681,22 @@ public class BasicOAuth2Request implemen
   }
 
   private HttpResponse processResponse(final OAuth2Accessor accessor,
-      final HttpResponseBuilder responseBuilder) {
+          final HttpResponseBuilder responseBuilder) {
 
     final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
     if (isLogging) {
       BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "processResponse",
-          new Object[] { accessor, (responseBuilder == null) });
+              new Object[] { accessor, (responseBuilder == null) });
     }
 
     if (accessor.isErrorResponse() || (responseBuilder == null)) {
       return this.sendErrorResponse(accessor.getErrorException(), accessor.getError(),
-          accessor.getErrorContextMessage(), accessor.getErrorUri());
+              accessor.getErrorContextMessage(), accessor.getErrorUri());
     }
 
     if (this.responseParams.getAuthorizationUrl() != null) {
       responseBuilder.setMetadata(OAuth2ResponseParams.APPROVAL_URL,
-          this.responseParams.getAuthorizationUrl());
+              this.responseParams.getAuthorizationUrl());
       accessor.setRedirecting(true);
     } else {
       accessor.setRedirecting(false);
@@ -697,7 +705,7 @@ public class BasicOAuth2Request implemen
     final HttpResponse ret = responseBuilder.create();
     if (isLogging) {
       BasicOAuth2Request.LOG.exiting(BasicOAuth2Request.LOG_CLASS, "processResponse",
-          "response logged in fetch()");
+              "response logged in fetch()");
     }
 
     return ret;
@@ -707,7 +715,7 @@ public class BasicOAuth2Request implemen
     final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
     if (isLogging) {
       BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "refreshToken",
-          new Object[] { accessor });
+              new Object[] { accessor });
     }
 
     OAuth2HandlerError ret = null;
@@ -728,7 +736,7 @@ public class BasicOAuth2Request implemen
 
       for (final ClientAuthenticationHandler clientAuthenticationHandler : this.clientAuthenticationHandlers) {
         if (clientAuthenticationHandler.geClientAuthenticationType().equalsIgnoreCase(
-            accessor.getClientAuthenticationType())) {
+                accessor.getClientAuthenticationType())) {
           clientAuthenticationHandler.addOAuth2Authentication(request, accessor);
         }
       }
@@ -741,7 +749,7 @@ public class BasicOAuth2Request implemen
           BasicOAuth2Request.LOG.log("refreshToken()", e);
         }
         ret = new OAuth2HandlerError(OAuth2Error.REFRESH_TOKEN_PROBLEM,
-            "error generating refresh body", e);
+                "error generating refresh body", e);
       }
 
       if (ret == null) {
@@ -752,7 +760,7 @@ public class BasicOAuth2Request implemen
             BasicOAuth2Request.LOG.log("refreshToken()", e);
           }
           ret = new OAuth2HandlerError(OAuth2Error.REFRESH_TOKEN_PROBLEM,
-              "error fetching refresh token", e);
+                  "error fetching refresh token", e);
         }
 
         if (isLogging) {
@@ -768,14 +776,14 @@ public class BasicOAuth2Request implemen
           final int statusCode = response.getHttpStatusCode();
           if (statusCode != HttpResponse.SC_OK) {
             ret = new OAuth2HandlerError(OAuth2Error.REFRESH_TOKEN_PROBLEM,
-                "bad response from server : " + statusCode, null);
+                    "bad response from server : " + statusCode, null);
           }
 
           if (ret == null) {
             for (final TokenEndpointResponseHandler tokenEndpointResponseHandler : this.tokenEndpointResponseHandlers) {
               if (tokenEndpointResponseHandler.handlesResponse(accessor, response)) {
                 final OAuth2HandlerError error = tokenEndpointResponseHandler.handleResponse(
-                    accessor, response);
+                        accessor, response);
                 if (error != null) {
                   return error;
                 }
@@ -794,9 +802,9 @@ public class BasicOAuth2Request implemen
   }
 
   private HttpResponse sendErrorResponse(final Throwable t, final OAuth2Error error,
-      final String contextMessage, final String errorUri) {
+          final String contextMessage, final String errorUri) {
     final HttpResponseBuilder responseBuilder = this.getErrorResponseBuilder(t, error,
-        contextMessage, errorUri);
+            contextMessage, errorUri);
     return responseBuilder.create();
   }
 
@@ -804,7 +812,7 @@ public class BasicOAuth2Request implemen
     final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
     if (isLogging) {
       BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "haveAccessToken",
-          new Object[] { accessor });
+              new Object[] { accessor });
     }
 
     OAuth2Token ret = accessor.getAccessToken();
@@ -825,7 +833,7 @@ public class BasicOAuth2Request implemen
     final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
     if (isLogging) {
       BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "haveRefreshToken",
-          new Object[] { accessor });
+              new Object[] { accessor });
     }
 
     OAuth2Token ret = accessor.getRefreshToken();

Added: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2RequestParameterGenerator.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2RequestParameterGenerator.java?rev=1213769&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2RequestParameterGenerator.java (added)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/BasicOAuth2RequestParameterGenerator.java Tue Dec 13 16:23:54 2011
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import com.google.common.collect.Maps;
+import org.apache.shindig.gadgets.http.HttpRequest;
+
+import java.util.Map;
+
+/**
+ * Default implementation of a request parameter generator that return an empty map
+ */
+public class BasicOAuth2RequestParameterGenerator implements OAuth2RequestParameterGenerator {
+
+  public Map<String, String> generateParams(HttpRequest request) {
+
+    return Maps.newHashMap();
+  }
+}
\ No newline at end of file

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Accessor.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Accessor.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Accessor.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Accessor.java Tue Dec 13 16:23:54 2011
@@ -17,18 +17,18 @@
 package org.apache.shindig.gadgets.oauth2;
 
 import java.io.Serializable;
+import java.util.Map;
 
 import org.apache.shindig.gadgets.oauth2.handler.ClientAuthenticationHandler;
 
 /**
  * OAuth2 related data accessor.
  * 
- * Every {@link OAuth2Request} will create an accessor and store it in the
- * OAuth2Store while the request is being issued. It will be removed when the
- * request is done (success or failure.)
+ * Every {@link OAuth2Request} will create an accessor and store it in the OAuth2Store while the
+ * request is being issued. It will be removed when the request is done (success or failure.)
  * 
- * OAuth2Accessor implementations should be {@link Serializable} to facilitate
- * cluster storage and caching across the various phases of OAuth 2.0 flows.
+ * OAuth2Accessor implementations should be {@link Serializable} to facilitate cluster storage and
+ * caching across the various phases of OAuth 2.0 flows.
  */
 
 public interface OAuth2Accessor extends Serializable {
@@ -85,8 +85,7 @@ public interface OAuth2Accessor extends 
 
   /**
    * 
-   * @return the error exception, if this is an error, otherwise
-   *         <code>null</code>
+   * @return the error exception, if this is an error, otherwise <code>null</code>
    */
   public Throwable getErrorException();
 
@@ -121,6 +120,12 @@ public interface OAuth2Accessor extends 
   public OAuth2Token getRefreshToken();
 
   /**
+   * 
+   * @return the additional oauth2 request params (never <code>null</code>)
+   */
+  public Map<String, String> getAdditionalRequestParams();
+
+  /**
    * if the gadget request or gadget spec specifies a scope it will be set here
    * 
    * See {@link http://tools.ietf.org/html/draft-ietf-oauth-v2-21#section-3.3}
@@ -167,14 +172,13 @@ public interface OAuth2Accessor extends 
 
   /**
    * 
-   * @return <code>true</code> if the gadget's <ModulePrefs> can override
-   *         accessor settings
+   * @return <code>true</code> if the gadget's <ModulePrefs> can override accessor settings
    */
   public boolean isAllowModuleOverrides();
 
   /**
-   * Indicates the service provider wants the access token in an
-   * "Authorization:" header, per the spec.
+   * Indicates the service provider wants the access token in an "Authorization:" header, per the
+   * spec.
    * 
    * @return
    */
@@ -194,9 +198,8 @@ public interface OAuth2Accessor extends 
   public boolean isRedirecting();
 
   /**
-   * Indicates the service provider wants the access token in an URL Parameter.
-   * This goes against the spec but Google, Facebook and Microsoft all expect
-   * it.
+   * Indicates the service provider wants the access token in an URL Parameter. This goes against
+   * the spec but Google, Facebook and Microsoft all expect it.
    * 
    * @return
    */
@@ -205,8 +208,7 @@ public interface OAuth2Accessor extends 
   public boolean isValid();
 
   /**
-   * updates the access token for the request (does not add it to
-   * {@link OAuth2Store})
+   * updates the access token for the request (does not add it to {@link OAuth2Store})
    * 
    * @param accessToken
    */
@@ -227,25 +229,31 @@ public interface OAuth2Accessor extends 
    * @param errorUri
    */
   public void setErrorResponse(Throwable exception, OAuth2Error error, String contextMessage,
-      String errorUri);
+          String errorUri);
 
   /**
-   * Used to communicate that we are in a redirect authorization flow and the
-   * accessor should be preserved.
+   * Used to communicate that we are in a redirect authorization flow and the accessor should be
+   * preserved.
    * 
    * @param redirecting
    */
   public void setRedirecting(boolean redirecting);
 
   /**
-   * updates the refresh token for the request (does not add it to
-   * {@link OAuth2Store})
+   * updates the refresh token for the request (does not add it to {@link OAuth2Store})
    * 
    * @param accessToken
    */
   public void setRefreshToken(OAuth2Token refreshToken);
 
   /**
+   * set the oauth2 request parameters
+   * 
+   * @param requestParams
+   */
+  public void setAdditionalRequestParams(Map<String, String> requestParams);
+
+  /**
    * updates the token endpoint url
    * 
    * @param tokenUrl

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Module.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Module.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Module.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2Module.java Tue Dec 13 16:23:54 2011
@@ -48,8 +48,7 @@ import com.google.inject.name.Named;
  */
 public class OAuth2Module extends AbstractModule {
   private static final String CLASS_NAME = OAuth2Module.class.getName();
-  static final FilteredLogger LOG = FilteredLogger
-      .getFilteredLogger(OAuth2Module.CLASS_NAME);
+  static final FilteredLogger LOG = FilteredLogger.getFilteredLogger(OAuth2Module.CLASS_NAME);
 
   private static final String OAUTH2_IMPORT = "shindig.oauth2.import";
   private static final String OAUTH2_IMPORT_CLEAN = "shindig.oauth2.import.clean";
@@ -65,15 +64,17 @@ public class OAuth2Module extends Abstra
     private final List<ResourceRequestHandler> resourceRequestHandlers;
     private final List<TokenEndpointResponseHandler> tokenEndpointResponseHandlers;
     private final boolean sendTraceToClient;
+    private final OAuth2RequestParameterGenerator requestParameterGenerator;
 
     @Inject
     public OAuth2RequestProvider(final OAuth2FetcherConfig config, final HttpFetcher fetcher,
-        final List<AuthorizationEndpointResponseHandler> authorizationEndpointResponseHandlers,
-        final List<ClientAuthenticationHandler> clientAuthenticationHandlers,
-        final List<GrantRequestHandler> grantRequestHandlers,
-        final List<ResourceRequestHandler> resourceRequestHandlers,
-        final List<TokenEndpointResponseHandler> tokenEndpointResponseHandlers,
-        @Named(OAuth2Module.SEND_TRACE_TO_CLIENT) final boolean sendTraceToClient) {
+            final List<AuthorizationEndpointResponseHandler> authorizationEndpointResponseHandlers,
+            final List<ClientAuthenticationHandler> clientAuthenticationHandlers,
+            final List<GrantRequestHandler> grantRequestHandlers,
+            final List<ResourceRequestHandler> resourceRequestHandlers,
+            final List<TokenEndpointResponseHandler> tokenEndpointResponseHandlers,
+            @Named(OAuth2Module.SEND_TRACE_TO_CLIENT) final boolean sendTraceToClient,
+            final OAuth2RequestParameterGenerator requestParameterGenerator) {
       this.config = config;
       this.fetcher = fetcher;
       this.authorizationEndpointResponseHandlers = authorizationEndpointResponseHandlers;
@@ -82,13 +83,15 @@ public class OAuth2Module extends Abstra
       this.resourceRequestHandlers = resourceRequestHandlers;
       this.tokenEndpointResponseHandlers = tokenEndpointResponseHandlers;
       this.sendTraceToClient = sendTraceToClient;
+      this.requestParameterGenerator = requestParameterGenerator;
     }
 
     public OAuth2Request get() {
       return new BasicOAuth2Request(this.config, this.fetcher,
-          this.authorizationEndpointResponseHandlers, this.clientAuthenticationHandlers,
-          this.grantRequestHandlers, this.resourceRequestHandlers,
-          this.tokenEndpointResponseHandlers, this.sendTraceToClient);
+              this.authorizationEndpointResponseHandlers, this.clientAuthenticationHandlers,
+              this.grantRequestHandlers, this.resourceRequestHandlers,
+              this.tokenEndpointResponseHandlers, this.sendTraceToClient,
+              this.requestParameterGenerator);
     }
   }
 
@@ -99,12 +102,12 @@ public class OAuth2Module extends Abstra
 
     @Inject
     public OAuth2StoreProvider(
-        @Named(OAuth2Module.OAUTH2_REDIRECT_URI) final String globalRedirectUri,
-        @Named(OAuth2Module.OAUTH2_IMPORT) final boolean importFromConfig,
-        @Named(OAuth2Module.OAUTH2_IMPORT_CLEAN) final boolean importClean,
-        final Authority authority, final OAuth2Cache cache, final OAuth2Persister persister,
-        final OAuth2Encrypter encrypter,
-        @Nullable @Named("shindig.contextroot") final String contextRoot) {
+            @Named(OAuth2Module.OAUTH2_REDIRECT_URI) final String globalRedirectUri,
+            @Named(OAuth2Module.OAUTH2_IMPORT) final boolean importFromConfig,
+            @Named(OAuth2Module.OAUTH2_IMPORT_CLEAN) final boolean importClean,
+            final Authority authority, final OAuth2Cache cache, final OAuth2Persister persister,
+            final OAuth2Encrypter encrypter,
+            @Nullable @Named("shindig.contextroot") final String contextRoot) {
 
       String redirectUri = globalRedirectUri;
       if (authority != null) {
@@ -118,7 +121,7 @@ public class OAuth2Module extends Abstra
       if (importFromConfig) {
         try {
           final OAuth2Persister source = new JSONOAuth2Persister(encrypter, authority,
-              globalRedirectUri, contextRoot);
+                  globalRedirectUri, contextRoot);
           BasicOAuth2Store.runImport(source, persister, importClean);
         } catch (final OAuth2PersistenceException e) {
           if (OAuth2Module.LOG.isLoggable()) {
@@ -145,5 +148,6 @@ public class OAuth2Module extends Abstra
   protected void configure() {
     this.bind(OAuth2Store.class).toProvider(OAuth2StoreProvider.class);
     this.bind(OAuth2Request.class).toProvider(OAuth2RequestProvider.class);
+    this.bind(OAuth2RequestParameterGenerator.class).to(BasicOAuth2RequestParameterGenerator.class);
   }
 }

Added: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2RequestParameterGenerator.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2RequestParameterGenerator.java?rev=1213769&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2RequestParameterGenerator.java (added)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/OAuth2RequestParameterGenerator.java Tue Dec 13 16:23:54 2011
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import org.apache.shindig.gadgets.http.HttpRequest;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Enables injection of a new request parameter generator into the system.
+ */
+public interface OAuth2RequestParameterGenerator {
+
+  /**
+   * Generates additional parameters that are added to the request sent to the authorization server
+   * 
+   * @return map of additional parameters. this should never be <code>null</code>
+   */
+  public Map<String, String> generateParams(HttpRequest request);
+}
\ No newline at end of file

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/BasicAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/BasicAuthenticationHandler.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/BasicAuthenticationHandler.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/BasicAuthenticationHandler.java Tue Dec 13 16:23:54 2011
@@ -22,6 +22,8 @@ import org.apache.shindig.gadgets.oauth2
 import org.apache.shindig.gadgets.oauth2.OAuth2Error;
 import org.apache.shindig.gadgets.oauth2.OAuth2Message;
 
+import java.util.Map;
+
 /**
  * 
  * See {@link ClientAuthenticationHandler}
@@ -32,11 +34,10 @@ import org.apache.shindig.gadgets.oauth2
 public class BasicAuthenticationHandler implements ClientAuthenticationHandler {
   private static final OAuth2Error ERROR = OAuth2Error.AUTHENTICATION_PROBLEM;
 
-  public BasicAuthenticationHandler() {
-  }
+  public BasicAuthenticationHandler() {}
 
   public OAuth2HandlerError addOAuth2Authentication(final HttpRequest request,
-      final OAuth2Accessor accessor) {
+          final OAuth2Accessor accessor) {
     try {
       if (request == null) {
         return BasicAuthenticationHandler.getError("request is null");
@@ -64,6 +65,11 @@ public class BasicAuthenticationHandler 
       final byte[] authBytes = Base64.encodeBase64(authString.getBytes());
       request.setHeader(OAuth2Message.AUTHORIZATION_HEADER, "Basic: " + new String(authBytes));
 
+      // add any additional parameters
+      for (Map.Entry<String, String> entry : accessor.getAdditionalRequestParams().entrySet()) {
+        request.setParam(entry.getKey(), entry.getValue());
+      }
+
       return null;
     } catch (final Exception e) {
       return BasicAuthenticationHandler.getError("Exception adding basic auth headers", e);

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/ClientCredentialsGrantTypeHandler.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/ClientCredentialsGrantTypeHandler.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/ClientCredentialsGrantTypeHandler.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/ClientCredentialsGrantTypeHandler.java Tue Dec 13 16:23:54 2011
@@ -44,7 +44,7 @@ public class ClientCredentialsGrantTypeH
 
   @Inject
   public ClientCredentialsGrantTypeHandler(
-      final List<ClientAuthenticationHandler> clientAuthenticationHandlers) {
+          final List<ClientAuthenticationHandler> clientAuthenticationHandlers) {
     this.clientAuthenticationHandlers = clientAuthenticationHandlers;
   }
 
@@ -61,7 +61,7 @@ public class ClientCredentialsGrantTypeH
       secret = new String(secretBytes, "UTF-8");
     } catch (final UnsupportedEncodingException e) {
       throw new OAuth2RequestException(OAuth2Error.CLIENT_CREDENTIALS_PROBLEM,
-          "error getting authorization body", e);
+              "error getting authorization body", e);
     }
     queryParams.put(OAuth2Message.CLIENT_ID, clientId);
     queryParams.put(OAuth2Message.CLIENT_SECRET, secret);
@@ -77,11 +77,11 @@ public class ClientCredentialsGrantTypeH
   }
 
   public HttpRequest getAuthorizationRequest(final OAuth2Accessor accessor,
-      final String completeAuthorizationUrl) throws OAuth2RequestException {
+          final String completeAuthorizationUrl) throws OAuth2RequestException {
 
     if ((completeAuthorizationUrl == null) || (completeAuthorizationUrl.length() == 0)) {
       throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
-          "completeAuthorizationUrl is null", null);
+              "completeAuthorizationUrl is null", null);
     }
 
     final HttpRequest request = new HttpRequest(Uri.parse(completeAuthorizationUrl));
@@ -90,27 +90,27 @@ public class ClientCredentialsGrantTypeH
 
     if (accessor == null) {
       throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR, "accessor is null",
-          null);
+              null);
     }
 
     if (!accessor.isValid() || accessor.isErrorResponse() || accessor.isRedirecting()) {
       throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
-          "accessor is invalid", null);
+              "accessor is invalid", null);
     }
 
     if (!accessor.getGrantType().equalsIgnoreCase(OAuth2Message.CLIENT_CREDENTIALS)) {
       throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
-          "grant type is not client_credentials", null);
+              "grant type is not client_credentials", null);
     }
 
     for (final ClientAuthenticationHandler clientAuthenticationHandler : this.clientAuthenticationHandlers) {
       if (clientAuthenticationHandler.geClientAuthenticationType().equalsIgnoreCase(
-          accessor.getClientAuthenticationType())) {
+              accessor.getClientAuthenticationType())) {
         final OAuth2HandlerError error = clientAuthenticationHandler.addOAuth2Authentication(
-            request, accessor);
+                request, accessor);
         if (error != null) {
           throw new OAuth2RequestException(error.getError(), error.getContextMessage(),
-              error.getCause());
+                  error.getCause());
         }
       }
     }
@@ -119,7 +119,7 @@ public class ClientCredentialsGrantTypeH
       request.setPostBody(this.getAuthorizationBody(accessor).getBytes("UTF-8"));
     } catch (final UnsupportedEncodingException e) {
       throw new OAuth2RequestException(OAuth2Error.CLIENT_CREDENTIALS_PROBLEM,
-          "ClientCredentialsGrantTypeHandler - exception setting post body", e);
+              "ClientCredentialsGrantTypeHandler - exception setting post body", e);
     }
 
     return request;
@@ -129,17 +129,17 @@ public class ClientCredentialsGrantTypeH
 
     if (accessor == null) {
       throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR, "accessor is null",
-          null);
+              null);
     }
 
     if (!accessor.isValid() || accessor.isErrorResponse() || accessor.isRedirecting()) {
       throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
-          "accessor is invalid", null);
+              "accessor is invalid", null);
     }
 
     if (!accessor.getGrantType().equalsIgnoreCase(OAuth2Message.CLIENT_CREDENTIALS)) {
       throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
-          "grant type is not client_credentials", null);
+              "grant type is not client_credentials", null);
     }
 
     String ret;
@@ -158,10 +158,15 @@ public class ClientCredentialsGrantTypeH
         queryParams.put(OAuth2Message.SCOPE, scope);
       }
 
+      // add any additional parameters
+      for (Map.Entry<String, String> entry : accessor.getAdditionalRequestParams().entrySet()) {
+        queryParams.put(entry.getKey(), entry.getValue());
+      }
+
       ret = OAuth2Utils.buildUrl(accessor.getTokenUrl(), queryParams, null);
     } catch (final UnsupportedEncodingException e) {
       throw new OAuth2RequestException(OAuth2Error.CLIENT_CREDENTIALS_PROBLEM,
-          "problem getting complete url", e);
+              "problem getting complete url", e);
     }
 
     return ret;

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandler.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandler.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandler.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandler.java Tue Dec 13 16:23:54 2011
@@ -38,13 +38,12 @@ public class CodeGrantTypeHandler implem
   private static final OAuth2Error ERROR = OAuth2Error.CODE_GRANT_PROBLEM;
 
   @Inject
-  public CodeGrantTypeHandler() {
-  }
+  public CodeGrantTypeHandler() {}
 
   public HttpRequest getAuthorizationRequest(final OAuth2Accessor accessor,
-      final String completeAuthorizationUrl) throws OAuth2RequestException {
+          final String completeAuthorizationUrl) throws OAuth2RequestException {
     throw new OAuth2RequestException(CodeGrantTypeHandler.ERROR,
-        "inappropriate call to CodeGrantTypeHandler.getAuthorizationRequest()", null);
+            "inappropriate call to CodeGrantTypeHandler.getAuthorizationRequest()", null);
   }
 
   public String getCompleteUrl(final OAuth2Accessor accessor) throws OAuth2RequestException {
@@ -78,6 +77,11 @@ public class CodeGrantTypeHandler implem
       queryParams.put(OAuth2Message.SCOPE, scope);
     }
 
+    // add any additional parameters
+    for (Map.Entry<String, String> entry : accessor.getAdditionalRequestParams().entrySet()) {
+      queryParams.put(entry.getKey(), entry.getValue());
+    }
+
     return OAuth2Utils.buildUrl(accessor.getAuthorizationUrl(), queryParams, null);
   }
 

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/StandardAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/StandardAuthenticationHandler.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/StandardAuthenticationHandler.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/handler/StandardAuthenticationHandler.java Tue Dec 13 16:23:54 2011
@@ -21,6 +21,8 @@ import org.apache.shindig.gadgets.oauth2
 import org.apache.shindig.gadgets.oauth2.OAuth2Error;
 import org.apache.shindig.gadgets.oauth2.OAuth2Message;
 
+import java.util.Map;
+
 /**
  * 
  * See {@link ClientAuthenticationHandler}
@@ -31,11 +33,10 @@ import org.apache.shindig.gadgets.oauth2
 public class StandardAuthenticationHandler implements ClientAuthenticationHandler {
   private static final OAuth2Error ERROR = OAuth2Error.AUTHENTICATION_PROBLEM;
 
-  public StandardAuthenticationHandler() {
-  }
+  public StandardAuthenticationHandler() {}
 
   public OAuth2HandlerError addOAuth2Authentication(final HttpRequest request,
-      final OAuth2Accessor accessor) {
+          final OAuth2Accessor accessor) {
     try {
       if (request == null) {
         return StandardAuthenticationHandler.getError("request is null");
@@ -68,6 +69,11 @@ public class StandardAuthenticationHandl
       request.setHeader(OAuth2Message.CLIENT_SECRET, secret);
       request.setParam(OAuth2Message.CLIENT_SECRET, secret);
 
+      // add any additional parameters
+      for (Map.Entry<String, String> entry : accessor.getAdditionalRequestParams().entrySet()) {
+        request.setParam(entry.getKey(), entry.getValue());
+      }
+
       return null;
     } catch (final Exception e) {
       return StandardAuthenticationHandler.getError("Exception adding standard auth headers", e);

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java Tue Dec 13 16:23:54 2011
@@ -50,8 +50,9 @@ public class DefaultRequestPipelineTest 
       return resp.getResponseAsString();
     }
   };
-  private final RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth, oauth2,
-      new DefaultResponseRewriterRegistry(null, null), new NoOpInvalidationService(), helper);
+  private final RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth,
+          oauth2, new DefaultResponseRewriterRegistry(null, null), new NoOpInvalidationService(),
+          helper);
 
   @Before
   public void setUp() {
@@ -60,8 +61,7 @@ public class DefaultRequestPipelineTest 
 
   @Test
   public void authTypeNoneNotCached() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.NONE);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE);
 
     fetcher.response = new HttpResponse("response");
 
@@ -74,64 +74,57 @@ public class DefaultRequestPipelineTest 
     assertEquals(1, cache.writeCount);
     assertEquals(1, fetcher.fetchCount);
     assertEquals(1, response.getMetadata().size());
-    assertEquals("response",
-        response.getMetadata().get(HttpResponseMetadataHelper.DATA_HASH));
+    assertEquals("response", response.getMetadata().get(HttpResponseMetadataHelper.DATA_HASH));
   }
 
   @Test
   public void verifyHashCode() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.NONE);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE);
 
     int time = roundToSeconds(HttpResponseTest.timeSource.currentTimeMillis()) - 10;
     String date = DateUtil.formatRfc1123Date(1000L * time);
-    HttpResponseBuilder builder = new HttpResponseBuilder()
-        .setCacheTtl(100)
-        .addHeader("Date", date);
+    HttpResponseBuilder builder = new HttpResponseBuilder().setCacheTtl(100)
+            .addHeader("Date", date);
     builder.setContent("response");
 
     fetcher.response = builder.create();
 
     RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth, oauth2,
-        new DefaultResponseRewriterRegistry(null, null), new NoOpInvalidationService(),
-        new HttpResponseMetadataHelper());
+            new DefaultResponseRewriterRegistry(null, null), new NoOpInvalidationService(),
+            new HttpResponseMetadataHelper());
     HttpResponse response = pipeline.execute(request);
     assertEquals(1, response.getMetadata().size());
     assertEquals("q7u8tbpmidtu1gtqhjv0kb0rvo",
-        response.getMetadata().get(HttpResponseMetadataHelper.DATA_HASH));
+            response.getMetadata().get(HttpResponseMetadataHelper.DATA_HASH));
     assertEquals(date, response.getHeader("Date"));
     assertEquals(roundToSeconds(90000 - 1), roundToSeconds(response.getCacheTtl() - 1));
   }
 
   @Test
   public void verifyFixedDate() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.NONE);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE);
 
     int time = roundToSeconds(HttpResponseTest.timeSource.currentTimeMillis());
-    String date = DateUtil.formatRfc1123Date(1000L * time
-        - 1000 - DefaultRequestPipeline.DEFAULT_DRIFT_LIMIT_MS);
-    HttpResponseBuilder builder = new HttpResponseBuilder()
-        .setCacheTtl(100)
-        .addHeader("Date", date);
+    String date = DateUtil.formatRfc1123Date(1000L * time - 1000
+            - DefaultRequestPipeline.DEFAULT_DRIFT_LIMIT_MS);
+    HttpResponseBuilder builder = new HttpResponseBuilder().setCacheTtl(100)
+            .addHeader("Date", date);
     builder.setContent("response");
 
     fetcher.response = builder.create();
 
     RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth, oauth2,
-        new DefaultResponseRewriterRegistry(null, null), new NoOpInvalidationService(),
-        new HttpResponseMetadataHelper());
+            new DefaultResponseRewriterRegistry(null, null), new NoOpInvalidationService(),
+            new HttpResponseMetadataHelper());
     HttpResponse response = pipeline.execute(request);
     // Verify time is current time instead of expired
     assertEquals(DateUtil.formatRfc1123Date(1000L * time), response.getHeader("Date"));
     assertEquals(roundToSeconds(100000 - 1), roundToSeconds(response.getCacheTtl() - 1));
   }
 
-
   @Test
   public void authTypeNoneWasCached() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.NONE);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE);
 
     HttpResponse cached = new HttpResponse("cached");
     cache.data.put(DEFAULT_URI, cached);
@@ -146,8 +139,7 @@ public class DefaultRequestPipelineTest 
 
   @Test
   public void authTypeNoneWasCachedButStale() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.NONE);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE);
 
     HttpResponse cached = new HttpResponseBuilder().setStrictNoCache().create();
     cache.data.put(DEFAULT_URI, cached);
@@ -164,15 +156,13 @@ public class DefaultRequestPipelineTest 
     assertEquals(1, cache.writeCount);
     assertEquals(1, fetcher.fetchCount);
     assertEquals(1, response.getMetadata().size());
-    assertEquals("fetched",
-        response.getMetadata().get(HttpResponseMetadataHelper.DATA_HASH));
+    assertEquals("fetched", response.getMetadata().get(HttpResponseMetadataHelper.DATA_HASH));
 
   }
 
   @Test
   public void authTypeNoneStaleCachedServed() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.NONE);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE);
 
     HttpResponse cached = new HttpResponseBuilder().setCacheTtl(-1).create();
     cache.data.put(DEFAULT_URI, cached);
@@ -190,13 +180,9 @@ public class DefaultRequestPipelineTest 
 
   @Test
   public void authTypeNoneWasCachedErrorStale() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.NONE);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE);
 
-    HttpResponse cached = new HttpResponseBuilder()
-        .setCacheTtl(-1)
-        .setHttpStatusCode(401)
-        .create();
+    HttpResponse cached = new HttpResponseBuilder().setCacheTtl(-1).setHttpStatusCode(401).create();
     cache.data.put(DEFAULT_URI, cached);
 
     HttpResponse fetched = HttpResponse.error();
@@ -214,9 +200,8 @@ public class DefaultRequestPipelineTest 
 
   @Test
   public void authTypeNoneIgnoreCache() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.NONE)
-        .setIgnoreCache(true);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE).setIgnoreCache(
+            true);
 
     HttpResponse fetched = new HttpResponse("fetched");
     fetcher.response = fetched;
@@ -232,8 +217,7 @@ public class DefaultRequestPipelineTest 
 
   @Test
   public void authTypeOAuthNotCached() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.OAUTH);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.OAUTH);
 
     oauth.httpResponse = new HttpResponse("oauth result");
 
@@ -250,8 +234,7 @@ public class DefaultRequestPipelineTest 
 
   @Test
   public void authTypeOAuthWasCached() throws Exception {
-    HttpRequest request = new HttpRequest(DEFAULT_URI)
-        .setAuthType(AuthType.OAUTH);
+    HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.OAUTH);
 
     HttpResponse cached = new HttpResponse("cached");
     cache.data.put(DEFAULT_URI, cached);
@@ -266,17 +249,18 @@ public class DefaultRequestPipelineTest 
   }
 
   private static int roundToSeconds(long ts) {
-    return (int)(ts / 1000);
+    return (int) (ts / 1000);
   }
 
   @Test
   public void testFixedDateOk() throws Exception {
     int time = roundToSeconds(HttpResponseTest.timeSource.currentTimeMillis());
     HttpResponse response = new HttpResponseBuilder()
-        .addHeader("Date", DateUtil.formatRfc1123Date(1000L * time
-            + 1000 - DefaultRequestPipeline.DEFAULT_DRIFT_LIMIT_MS))
-        .setCacheTtl(100)
-        .create();
+            .addHeader(
+                    "Date",
+                    DateUtil.formatRfc1123Date(1000L * time + 1000
+                            - DefaultRequestPipeline.DEFAULT_DRIFT_LIMIT_MS)).setCacheTtl(100)
+            .create();
 
     HttpResponse newResponse = DefaultRequestPipeline.maybeFixDriftTime(response);
     assertSame(response, newResponse);
@@ -286,32 +270,34 @@ public class DefaultRequestPipelineTest 
   public void testFixedDateOld() throws Exception {
     int time = roundToSeconds(HttpResponseTest.timeSource.currentTimeMillis());
     HttpResponse response = new HttpResponseBuilder()
-        .addHeader("Date", DateUtil.formatRfc1123Date(1000L * time
-            - 1000 - DefaultRequestPipeline.DEFAULT_DRIFT_LIMIT_MS))
-        .setCacheTtl(100)
-        .create();
+            .addHeader(
+                    "Date",
+                    DateUtil.formatRfc1123Date(1000L * time - 1000
+                            - DefaultRequestPipeline.DEFAULT_DRIFT_LIMIT_MS)).setCacheTtl(100)
+            .create();
 
     response = DefaultRequestPipeline.maybeFixDriftTime(response);
     // Verify that the old time is ignored:
     assertEquals(time + 100, roundToSeconds(response.getCacheExpiration()));
     assertEquals(DateUtil.formatRfc1123Date(HttpResponseTest.timeSource.currentTimeMillis()),
-        response.getHeader("Date"));
+            response.getHeader("Date"));
   }
 
   @Test
   public void testFixedDateNew() throws Exception {
     int time = roundToSeconds(HttpResponseTest.timeSource.currentTimeMillis());
     HttpResponse response = new HttpResponseBuilder()
-        .addHeader("Date", DateUtil.formatRfc1123Date(1000L * time
-            + 1000 + DefaultRequestPipeline.DEFAULT_DRIFT_LIMIT_MS))
-        .setCacheTtl(100)
-        .create();
+            .addHeader(
+                    "Date",
+                    DateUtil.formatRfc1123Date(1000L * time + 1000
+                            + DefaultRequestPipeline.DEFAULT_DRIFT_LIMIT_MS)).setCacheTtl(100)
+            .create();
 
     response = DefaultRequestPipeline.maybeFixDriftTime(response);
     // Verify that the old time is ignored:
     assertEquals(time + 100, roundToSeconds(response.getCacheExpiration()));
     assertEquals(DateUtil.formatRfc1123Date(HttpResponseTest.timeSource.currentTimeMillis()),
-        response.getHeader("Date"));
+            response.getHeader("Date"));
   }
 
   public static class FakeHttpFetcher implements HttpFetcher {
@@ -319,8 +305,7 @@ public class DefaultRequestPipelineTest 
     protected HttpResponse response;
     protected int fetchCount = 0;
 
-    protected FakeHttpFetcher() {
-    }
+    protected FakeHttpFetcher() {}
 
     public HttpResponse fetch(HttpRequest request) throws GadgetException {
       fetchCount++;
@@ -337,8 +322,7 @@ public class DefaultRequestPipelineTest 
     protected int writeCount = 0;
     protected int readCount = 0;
 
-    protected FakeHttpCache() {
-    }
+    protected FakeHttpCache() {}
 
     public boolean addResponse(HttpRequest request, HttpResponse response) {
       writeCount++;
@@ -365,9 +349,7 @@ public class DefaultRequestPipelineTest 
     protected HttpRequest httpRequest;
     protected HttpResponse httpResponse;
 
-    protected FakeOAuthRequestProvider() {
-    }
-
+    protected FakeOAuthRequestProvider() {}
 
     private final OAuthRequest oauthRequest = new OAuthRequest(null, null) {
       @Override
@@ -383,17 +365,16 @@ public class DefaultRequestPipelineTest 
     }
 
   }
-  
+
   public static class FakeOAuth2RequestProvider implements Provider<OAuth2Request> {
     protected int fetchCount = 0;
     protected HttpRequest httpRequest;
     protected HttpResponse httpResponse;
 
-    protected FakeOAuth2RequestProvider() {
-    }
-
+    protected FakeOAuth2RequestProvider() {}
 
-    private final OAuth2Request oauth2Request = new BasicOAuth2Request(null, null, null, null, null, null, null, false) {
+    private final OAuth2Request oauth2Request = new BasicOAuth2Request(null, null, null, null,
+            null, null, null, false, null) {
       @Override
       public HttpResponse fetch(HttpRequest request) {
         fetchCount++;

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandlerTest.java?rev=1213769&r1=1213768&r2=1213769&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandlerTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/handler/CodeGrantTypeHandlerTest.java Tue Dec 13 16:23:54 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.shindig.gadgets.oauth2.handler;
 
+import com.google.common.collect.Maps;
 import org.apache.shindig.gadgets.oauth2.MockUtils;
 import org.apache.shindig.gadgets.oauth2.OAuth2Accessor;
 import org.apache.shindig.gadgets.oauth2.OAuth2RequestException;
@@ -25,6 +26,8 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.Map;
+
 public class CodeGrantTypeHandlerTest extends MockUtils {
 
   private static CodeGrantTypeHandler cgth;
@@ -84,13 +87,25 @@ public class CodeGrantTypeHandlerTest ex
     final String result = fixture.getCompleteUrl(accessor);
 
     Assert.assertNotNull(result);
-    Assert
-        .assertEquals(
+    Assert.assertEquals(
             "http://www.example.com/authorize?client_id=clientId1&redirect_uri=https%3A%2F%2Fwww.example.com%2Fgadgets%2Foauth2callback&response_type=code&scope=testScope&state=574006657",
             result);
   }
 
   @Test
+  public void testGetCompleteUrl_5() throws Exception {
+    final CodeGrantTypeHandler fixture = CodeGrantTypeHandlerTest.cgth;
+    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
+    Map<String, String> additionalParams = Maps.newHashMap();
+    additionalParams.put("param1", "value1");
+    accessor.setAdditionalRequestParams(additionalParams);
+    final String result = fixture.getCompleteUrl(accessor);
+
+    Assert.assertNotNull(result);
+    Assert.assertTrue(result.contains("&param1=value1"));
+  }
+
+  @Test
   public void testGetGrantType_1() throws Exception {
     final CodeGrantTypeHandler fixture = CodeGrantTypeHandlerTest.cgth;
 



Mime
View raw message