You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2017/08/16 15:27:06 UTC

cxf git commit: Adding a couple of OAuth2 tests

Repository: cxf
Updated Branches:
  refs/heads/master ce3de8e35 -> 070c4fce4


Adding a couple of OAuth2 tests


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/070c4fce
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/070c4fce
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/070c4fce

Branch: refs/heads/master
Commit: 070c4fce493328a534c1ea766fdf1af74087cc64
Parents: ce3de8e
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Wed Aug 16 16:26:51 2017 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Wed Aug 16 16:26:51 2017 +0100

----------------------------------------------------------------------
 .../oauth2/common/OAuthDataProviderImpl.java    |  8 ++++++
 .../security/oauth2/grants/JAXRSOAuth2Test.java | 29 ++++++++++++++++++++
 2 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/070c4fce/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuthDataProviderImpl.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuthDataProviderImpl.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuthDataProviderImpl.java
index a495d0b..593efce 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuthDataProviderImpl.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuthDataProviderImpl.java
@@ -110,6 +110,14 @@ public class OAuthDataProviderImpl extends DefaultEHCacheCodeDataProvider {
         client.getAllowedGrantTypes().add("urn:ietf:params:oauth:grant-type:jwt-bearer");
         client.getAllowedGrantTypes().add("custom_grant");
         this.setClient(client);
+        
+        client = new Client("fredNoPassword", null, true);
+        client.getAllowedGrantTypes().add("custom_grant");
+        this.setClient(client);
+        
+        client = new Client("fred", "password", true);
+        client.getAllowedGrantTypes().add("custom_grant");
+        this.setClient(client);
 
         Certificate cert = loadCert();
         String encodedCert = Base64Utility.encode(cert.getEncoded());

http://git-wip-us.apache.org/repos/asf/cxf/blob/070c4fce/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/JAXRSOAuth2Test.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/JAXRSOAuth2Test.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/JAXRSOAuth2Test.java
index 3acbf51..a028469 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/JAXRSOAuth2Test.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/JAXRSOAuth2Test.java
@@ -130,6 +130,35 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
         assertNotNull(at.getTokenKey());
     }
 
+    @Test()
+    public void testConfidentialClientIdOnly() throws Exception {
+        String address = "https://localhost:" + PORT + "/oauth2/token";
+        WebClient wc = createWebClient(address);
+
+        try {
+            OAuthClientUtils.getAccessToken(wc,
+                                            new Consumer("fredNoPassword"),
+                                            new CustomGrant(),
+                                            false);
+            fail("NotAuthorizedException exception is expected");
+        } catch (OAuthServiceException ex) {
+            assertEquals("invalid_client", ex.getError().getError());
+        }
+    }
+
+    @Test
+    public void testConfidentialClientIdAndSecret() throws Exception {
+        String address = "https://localhost:" + PORT + "/oauth2/token";
+        WebClient wc = createWebClient(address);
+
+        
+        ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
+                                                               new Consumer("fred", "password"),
+                                                               new CustomGrant(),
+                                                               false);
+        assertNotNull(at.getTokenKey());
+    }
+    
     @Test
     public void testTwoWayTLSAuthenticationCustomGrant() throws Exception {
         String address = "https://localhost:" + PORT + "/oauth2/token";