incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmo...@apache.org
Subject svn commit: r1205835 - in /incubator/amber/trunk/oauth-2.0: oauth2-client/src/main/java/org/apache/amber/oauth2/client/ oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ oauth2-integration-tests/src/test/java/org/apache/amber/...
Date Thu, 24 Nov 2011 13:59:21 GMT
Author: lmoren
Date: Thu Nov 24 13:59:20 2011
New Revision: 1205835

URL: http://svn.apache.org/viewvc?rev=1205835&view=rev
Log:
[AMBER-44] Add method to OAuthClient that allows sending GET request to OAuth token endpoint

Modified:
    incubator/amber/trunk/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/OAuthClient.java
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/TokenEndpoint.java

Modified: incubator/amber/trunk/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/OAuthClient.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/OAuthClient.java?rev=1205835&r1=1205834&r2=1205835&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/OAuthClient.java
(original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/OAuthClient.java
Thu Nov 24 13:59:20 2011
@@ -51,11 +51,17 @@ public class OAuthClient {
         Class<T> responseClass)
         throws OAuthSystemException, OAuthProblemException {
 
-        String method = OAuth.HttpMethod.POST;
+        return accessToken(request, OAuth.HttpMethod.POST, responseClass);
+    }
+
+    public <T extends OAuthAccessTokenResponse> T accessToken(
+        OAuthClientRequest request, String requestMethod, Class<T> responseClass)
+        throws OAuthSystemException, OAuthProblemException {
+
         Map<String, String> headers = new HashMap<String, String>();
         headers.put(OAuth.HeaderType.CONTENT_TYPE, OAuth.ContentType.URL_ENCODED);
 
-        return httpClient.execute(request, headers, method, responseClass);
+        return httpClient.execute(request, headers, requestMethod, responseClass);
     }
 
     public OAuthJSONAccessTokenResponse accessToken(
@@ -63,7 +69,13 @@ public class OAuthClient {
         throws OAuthSystemException, OAuthProblemException {
         return accessToken(request, OAuthJSONAccessTokenResponse.class);
     }
-    
+
+    public OAuthJSONAccessTokenResponse accessToken(
+        OAuthClientRequest request, String requestMethod)
+        throws OAuthSystemException, OAuthProblemException {
+        return accessToken(request, requestMethod, OAuthJSONAccessTokenResponse.class);
+    }
+
     public void shutdown() {
         httpClient.shutdown();
     }

Modified: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java?rev=1205835&r1=1205834&r2=1205835&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java
(original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java
Thu Nov 24 13:59:20 2011
@@ -28,9 +28,8 @@ import org.apache.amber.oauth2.client.re
 import org.apache.amber.oauth2.common.OAuth;
 import org.apache.amber.oauth2.common.error.OAuthError;
 import org.apache.amber.oauth2.common.exception.OAuthProblemException;
-import org.junit.Test;
-
 import org.apache.amber.oauth2.common.message.types.GrantType;
+import org.junit.Test;
 
 /**
  * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
@@ -61,6 +60,26 @@ public class AccessTokenTestAuthCodeTest
     }
 
     @Test
+    public void testSuccessfullAccesTokenGETMethod() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.AUTHORIZATION_CODE)
+            .setCode(Common.AUTHORIZATION_CODE)
+            .setRedirectURI(Common.REDIRECT_URL)
+            .setClientId(Common.CLIENT_ID)
+            .setClientSecret(Common.CLIENT_SECRET)
+            .buildQueryMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+        OAuthAccessTokenResponse response = oAuthClient.accessToken(request, OAuth.HttpMethod.GET);
+        assertNotNull(response.getAccessToken());
+        assertNotNull(response.getExpiresIn());
+
+
+    }
+
+    @Test
     public void testNoneGrantType() throws Exception {
         OAuthClientRequest request = OAuthClientRequest
             .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)

Modified: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/TokenEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/TokenEndpoint.java?rev=1205835&r1=1205834&r2=1205835&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/TokenEndpoint.java
(original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/TokenEndpoint.java
Thu Nov 24 13:59:20 2011
@@ -24,6 +24,7 @@ package org.apache.amber.oauth2.integrat
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
@@ -31,8 +32,8 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 
 import org.apache.amber.oauth2.as.issuer.MD5Generator;
-import org.apache.amber.oauth2.as.issuer.OAuthIssuerImpl;
 import org.apache.amber.oauth2.as.issuer.OAuthIssuer;
+import org.apache.amber.oauth2.as.issuer.OAuthIssuerImpl;
 import org.apache.amber.oauth2.as.request.OAuthTokenRequest;
 import org.apache.amber.oauth2.as.response.OAuthASResponse;
 import org.apache.amber.oauth2.common.OAuth;
@@ -132,4 +133,19 @@ public class TokenEndpoint {
         }
     }
 
+    @GET
+    @Consumes("application/x-www-form-urlencoded")
+    @Produces("application/json")
+    public Response authorizeGet(@Context HttpServletRequest request) throws OAuthSystemException
{
+        OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
+
+        OAuthResponse response = OAuthASResponse
+            .tokenResponse(HttpServletResponse.SC_OK)
+            .setAccessToken(oauthIssuerImpl.accessToken())
+            .setExpiresIn("3600")
+            .buildJSONMessage();
+
+        return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
+    }
+
 }
\ No newline at end of file



Mime
View raw message