incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1432899 - in /incubator/amber/trunk/oauth-2.0: client/src/main/java/org/apache/amber/oauth2/client/request/ common/src/main/java/org/apache/amber/oauth2/common/utils/ common/src/test/java/org/apache/amber/oauth2/common/utils/
Date Mon, 14 Jan 2013 12:25:54 GMT
Author: asanso
Date: Mon Jan 14 12:25:53 2013
New Revision: 1432899

URL: http://svn.apache.org/viewvc?rev=1432899&view=rev
Log:
AMBER-69 - Client code generates wrong header for Bearer Token 

Modified:
    incubator/amber/trunk/oauth-2.0/client/src/main/java/org/apache/amber/oauth2/client/request/ClientHeaderParametersApplier.java
    incubator/amber/trunk/oauth-2.0/common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java
    incubator/amber/trunk/oauth-2.0/common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java

Modified: incubator/amber/trunk/oauth-2.0/client/src/main/java/org/apache/amber/oauth2/client/request/ClientHeaderParametersApplier.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/client/src/main/java/org/apache/amber/oauth2/client/request/ClientHeaderParametersApplier.java?rev=1432899&r1=1432898&r2=1432899&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/client/src/main/java/org/apache/amber/oauth2/client/request/ClientHeaderParametersApplier.java
(original)
+++ incubator/amber/trunk/oauth-2.0/client/src/main/java/org/apache/amber/oauth2/client/request/ClientHeaderParametersApplier.java
Mon Jan 14 12:25:53 2013
@@ -39,7 +39,7 @@ public class ClientHeaderParametersAppli
     public OAuthMessage applyOAuthParameters(OAuthMessage message, Map<String, Object>
params)
         throws OAuthSystemException {
 
-        String header = OAuthUtils.encodeOAuthHeader(params);
+        String header = OAuthUtils.encodeAuthorizationBearerHeader(params);
         message.addHeader(OAuth.HeaderType.AUTHORIZATION, header);
         return message;
 

Modified: incubator/amber/trunk/oauth-2.0/common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java?rev=1432899&r1=1432898&r2=1432899&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java
(original)
+++ incubator/amber/trunk/oauth-2.0/common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java
Mon Jan 14 12:25:53 2013
@@ -364,7 +364,7 @@ public final class OAuthUtils {
     // todo: implement method to decode header form (with no challenge)
 
     /**
-     * Construct a WWW-Authenticate or Authorization header with the OAuth challenge/credentials
+     * Construct a WWW-Authenticate header
      */
     public static String encodeOAuthHeader(Map<String, Object> entries) {
         StringBuffer sb = new StringBuffer();
@@ -381,6 +381,22 @@ public final class OAuthUtils {
 
         return sb.substring(0, sb.length() - 1);
     }
+    
+    /**
+     * Construct an Authorization Bearer header
+     */
+    public static String encodeAuthorizationBearerHeader(Map<String, Object> entries)
{
+        StringBuffer sb = new StringBuffer();
+        sb.append(OAuth.OAUTH_HEADER_NAME).append(" ");
+        for (Map.Entry<String, Object> entry : entries.entrySet()) {
+            String value = entry.getValue() == null? null: String.valueOf(entry.getValue());
+            if (!OAuthUtils.isEmpty(entry.getKey()) && !OAuthUtils.isEmpty(value))
{
+                sb.append(value);
+            }
+        }
+
+        return sb.toString();
+    }
 
     public static boolean isEmpty(String value) {
         return value == null || "".equals(value);

Modified: incubator/amber/trunk/oauth-2.0/common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java?rev=1432899&r1=1432898&r2=1432899&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java
(original)
+++ incubator/amber/trunk/oauth-2.0/common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java
Mon Jan 14 12:25:53 2013
@@ -123,6 +123,23 @@ public class OAuthUtilsTest {
 
     @Test
     public void testEncodeOAuthHeader() throws Exception {
+    	Map<String, Object> parameters = new HashMap<String, Object>();
+    	parameters.put("realm", "example");
+    	
+    	///rfc6750#section-3
+    	String header = OAuthUtils.encodeOAuthHeader(parameters);
+        Assert.assertEquals("Bearer realm=\"example\"", header);
+
+    }
+    
+    @Test
+    public void testEncodeAuthorizationBearerHeader() throws Exception {
+    	Map<String, Object> parameters = new HashMap<String, Object>();
+    	parameters.put("accessToken", "mF_9.B5f-4.1JqM");
+    	
+    	//rfc6749#section-7.1
+    	String header = OAuthUtils.encodeAuthorizationBearerHeader(parameters);
+        Assert.assertEquals("Bearer mF_9.B5f-4.1JqM", header);
 
     }
 



Mime
View raw message