Repository: cxf Updated Branches: refs/heads/3.1.x-fixes 9eb57287e -> f7c55ceac
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/f7c55cea Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f7c55cea Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f7c55cea Branch: refs/heads/3.1.x-fixes Commit: f7c55ceac2b58e15379ac37a03a398df000f71b3 Parents: 9eb5728 Author: Sergey Beryozkin <[email protected]> Authored: Wed Aug 16 16:26:51 2017 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Wed Aug 16 16:41:52 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/f7c55cea/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 61e70f0..75c922a 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/f7c55cea/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 33c9c46..e52a77f 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 @@ -129,6 +129,35 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase { extraParams); 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 {
