incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1332515 - /incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/BearerQueryTokenExtractor.java
Date Tue, 01 May 2012 03:34:42 GMT
Author: rfeng
Date: Tue May  1 03:34:41 2012
New Revision: 1332515

URL: http://svn.apache.org/viewvc?rev=1332515&view=rev
Log:
Fix the code to not mess up with HTTP POST body

Modified:
    incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/BearerQueryTokenExtractor.java

Modified: incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/BearerQueryTokenExtractor.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/BearerQueryTokenExtractor.java?rev=1332515&r1=1332514&r2=1332515&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/BearerQueryTokenExtractor.java
(original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/BearerQueryTokenExtractor.java
Tue May  1 03:34:41 2012
@@ -21,6 +21,9 @@
 
 package org.apache.amber.oauth2.rs.extractor;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.amber.oauth2.common.OAuth;
@@ -34,16 +37,48 @@ public class BearerQueryTokenExtractor i
 
     @Override
     public String getAccessToken(HttpServletRequest request) {
-        String token = request.getParameter(OAuth.OAUTH_BEARER_TOKEN);
+        String token = getQueryParameter(request, OAuth.OAUTH_BEARER_TOKEN);
         if (token == null) {
-            token = request.getParameter(OAuth.OAUTH_TOKEN);
+            token = getQueryParameter(request, OAuth.OAUTH_TOKEN);
         }
         return token;
     }
 
     @Override
     public String getAccessToken(HttpServletRequest request, String tokenName) {
-        return request.getParameter(tokenName);
+        return getQueryParameter(request, tokenName);
+    }
+
+    /**
+     * A replacement for HttpServletRequest.getParameter() as it will mess up with HTTP POST
body
+     * @param request
+     * @param name
+     * @return
+     */
+    private String getQueryParameter(HttpServletRequest request, String name) {
+        String query = request.getQueryString();
+        if (query == null) {
+            return null;
+        }
+        String[] params = query.split("&");
+        for (String param : params) {
+            try {
+                param = URLDecoder.decode(param, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                // Ignore
+            }
+            int index = param.indexOf('=');
+            String key = param;
+            String value = null;
+            if (index != -1) {
+                key = param.substring(0, index);
+                value = param.substring(index + 1);
+            }
+            if (key.equals(name)) {
+                return value;
+            }
+        }
+        return null;
     }
 
 }



Mime
View raw message