Java Code Examples for org.gluu.oxauth.client.TokenRequest#setUsername()
The following examples show how to use
org.gluu.oxauth.client.TokenRequest#setUsername() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 5 votes |
/** * Fail 1: Call to Token Endpoint with Auth Method * <code>client_secret_post</code> should fail. */ @Parameters({"tokenPath", "userId", "userSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodClientSecretBasicStep2") public void tokenEndpointAuthMethodClientSecretBasicFail1(final String tokenPath, final String userId, final String userSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_POST); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId2); tokenRequest.setAuthPassword(clientSecret2); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodClientSecretBasicFail1", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 2
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 5 votes |
/** * Fail 1: Call to Token Endpoint with Auth Method * <code>client_secret_basic</code> should fail. */ @Parameters({"tokenPath", "userId", "userSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodPrivateKeyJwtStep2") public void tokenEndpointAuthMethodPrivateKeyJwtFail1(final String tokenPath, final String userId, final String userSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId5); tokenRequest.setAuthPassword(clientSecret5); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodPrivateKeyJwtFail1", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 3
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 5 votes |
/** * Fail 3: Call to Token Endpoint with Auth Method * <code>client_secret_jwt</code> should fail. */ @Parameters({"tokenPath", "audience", "userId", "userSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodPrivateKeyJwtStep2") public void tokenEndpointAuthMethodPrivateKeyJwtFail3(final String tokenPath, final String audience, final String userId, final String userSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setAudience(audience); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId5); tokenRequest.setAuthPassword(clientSecret5); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodPrivateKeyJwtFail3", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 4
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 5 votes |
/** * Fail 2: Call to Token Endpoint with Auth Method * <code>client_secret_post</code> should fail. */ @Parameters({"tokenPath", "userId", "userSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodClientSecretJwtStep2") public void tokenEndpointAuthMethodClientSecretJwtFail2(final String tokenPath, final String userId, final String userSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_POST); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId4); tokenRequest.setAuthPassword(clientSecret4); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodClientSecretJwtFail2", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 5
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 5 votes |
/** * Fail 1: Call to Token Endpoint with Auth Method * <code>client_secret_basic</code> should fail. */ @Parameters({"tokenPath", "userId", "userSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodClientSecretJwtStep2") public void tokenEndpointAuthMethodClientSecretJwtFail1(final String tokenPath, final String userId, final String userSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId4); tokenRequest.setAuthPassword(clientSecret4); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodClientSecretJwtFail1", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 6
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 5 votes |
/** * Fail 2: Call to Token Endpoint with Auth Method * <code>client_secret_jwt</code> should fail. */ @Parameters({"tokenPath", "audience", "userId", "userSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodClientSecretPostStep2") public void tokenEndpointAuthMethodClientSecretPostFail2(final String tokenPath, final String audience, final String userId, final String userSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setAudience(audience); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId3); tokenRequest.setAuthPassword(clientSecret3); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodClientSecretPostFail2", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 7
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 5 votes |
/** * Fail 1: Call to Token Endpoint with Auth Method * <code>client_secret_basic</code> should fail. */ @Parameters({"tokenPath", "userId", "userSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodClientSecretPostStep2") public void tokenEndpointAuthMethodClientSecretPostFail1(final String tokenPath, final String userId, final String userSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId3); tokenRequest.setAuthPassword(clientSecret3); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodClientSecretPostFail1", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 8
Source File: TokenAction.java From oxAuth with MIT License | 5 votes |
public void exec() { try { TokenRequest request = new TokenRequest(grantType); request.setAuthUsername(clientId); request.setAuthPassword(clientSecret); request.setCode(code); request.setRedirectUri(redirectUri); request.setUsername(username); request.setPassword(password); request.setScope(scope); request.setAssertion(assertion); request.setRefreshToken(refreshToken); request.setAuthenticationMethod(authenticationMethod); if (authenticationMethod.equals(AuthenticationMethod.CLIENT_SECRET_JWT)) { request.setAudience(tokenEndpoint); } request.setAuthReqId(authReqId); TokenClient client = new TokenClient(tokenEndpoint); client.setRequest(request); TokenResponse response = client.exec(); if (response.getStatus() == 200) { userInfoAction.setAccessToken(response.getAccessToken()); } showResults = true; requestString = client.getRequestAsString(); responseString = client.getResponseAsString(); } catch (Exception e) { log.error(e.getMessage(), e); } }
Example 9
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 5 votes |
/** * Fail 2: Call to Token Endpoint with Auth Method * <code>client_secret_post</code> should fail. */ @Parameters({"tokenPath", "userId", "userSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodPrivateKeyJwtStep2") public void tokenEndpointAuthMethodPrivateKeyJwtFail2(final String tokenPath, final String userId, final String userSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_POST); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId5); tokenRequest.setAuthPassword(clientSecret5); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodPrivateKeyJwtFail2", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 10
Source File: TokenRestWebServiceWithRSAlgEmbeddedTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"tokenPath", "userId", "userSecret", "audience", "RS256_keyId", "keyStoreFile", "keyStoreSecret"}) @Test(dependsOnMethods = "requestAccessTokenWithClientSecretJwtRS256Step1") public void requestAccessTokenWithClientSecretJwtRS256Step2(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String keyStoreFile, final String keyStoreSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId1); tokenRequest.setAuthPassword(clientSecret1); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setAlgorithm(SignatureAlgorithm.RS256); tokenRequest.setKeyId(keyId); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwtRS256Step2", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); assertTrue( response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control")); assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma")); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found"); assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found"); assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 11
Source File: TokenRestWebServiceWithESAlgEmbeddedTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"tokenPath", "userId", "userSecret", "audience", "ES512_keyId", "keyStoreFile", "keyStoreSecret"}) @Test(dependsOnMethods = "requestAccessTokenWithClientSecretJwtES512X509CertStep1") public void requestAccessTokenWithClientSecretJwtES512X509CertStep2(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String keyStoreFile, final String keyStoreSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId6); tokenRequest.setAuthPassword(clientSecret6); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setAlgorithm(SignatureAlgorithm.ES512); tokenRequest.setKeyId(keyId); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwtES512X509CertStep2", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); assertTrue( response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control")); assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma")); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found"); assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found"); assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 12
Source File: TokenRestWebServiceWithRSAlgEmbeddedTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"tokenPath", "userId", "userSecret", "audience", "RS512_keyId", "keyStoreFile", "keyStoreSecret"}) @Test(dependsOnMethods = "requestAccessTokenWithClientSecretJwtRS512Step1") public void requestAccessTokenWithClientSecretJwtRS512Step2(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String keyStoreFile, final String keyStoreSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId3); tokenRequest.setAuthPassword(clientSecret3); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setAlgorithm(SignatureAlgorithm.RS512); tokenRequest.setKeyId(keyId); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwtRS512Step2", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); assertTrue( response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control")); assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma")); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found"); assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found"); assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 13
Source File: TokenRestWebServiceWithRSAlgEmbeddedTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"tokenPath", "userId", "userSecret", "audience", "RS512_keyId", "keyStoreFile", "keyStoreSecret"}) @Test(dependsOnMethods = "requestAccessTokenWithClientSecretJwtRS512X509CertStep1") public void requestAccessTokenWithClientSecretJwtRS512X509CertStep2(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String keyStoreFile, final String keyStoreSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId6); tokenRequest.setAuthPassword(clientSecret6); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setAlgorithm(SignatureAlgorithm.RS512); tokenRequest.setKeyId(keyId); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwtRS512X509CertStep2", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); assertTrue( response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control")); assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma")); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found"); assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found"); assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 14
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 4 votes |
/** * Fail 3: Call to Token Endpoint with Auth Method * <code>private_key_jwt</code> should fail. */ @Parameters({"tokenPath", "userId", "userSecret", "audience", "RS256_keyId", "keyStoreFile", "keyStoreSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodClientSecretBasicStep2") public void tokenEndpointAuthMethodClientSecretBasicFail3(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String keyStoreFile, final String keyStoreSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.PRIVATE_KEY_JWT); tokenRequest.setAlgorithm(SignatureAlgorithm.RS256); tokenRequest.setKeyId(keyId); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAudience(audience); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId2); tokenRequest.setAuthPassword(clientSecret2); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodClientSecretBasicFail3", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 15
Source File: TokenRestWebServiceWithESAlgEmbeddedTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"tokenPath", "userId", "userSecret", "audience", "ES512_keyId", "keyStoreFile", "keyStoreSecret"}) @Test(dependsOnMethods = "requestAccessTokenWithClientSecretJwtES512Step1") public void requestAccessTokenWithClientSecretJwtES512Step2(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String keyStoreFile, final String keyStoreSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId3); tokenRequest.setAuthPassword(clientSecret3); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setAlgorithm(SignatureAlgorithm.ES512); tokenRequest.setKeyId(keyId); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwtES512Step2", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); assertTrue( response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control")); assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma")); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found"); assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found"); assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 16
Source File: TokenRestWebServiceWithRSAlgEmbeddedTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"tokenPath", "userId", "userSecret", "audience", "RS384_keyId", "keyStoreFile", "keyStoreSecret"}) @Test(dependsOnMethods = "requestAccessTokenWithClientSecretJwtRS384Step1") public void requestAccessTokenWithClientSecretJwtRS384Step2(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String keyStoreFile, final String keyStoreSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId2); tokenRequest.setAuthPassword(clientSecret2); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setAlgorithm(SignatureAlgorithm.RS384); tokenRequest.setKeyId(keyId); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwtRS384Step2", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); assertTrue( response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control")); assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma")); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found"); assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found"); assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 17
Source File: TokenEndpointAuthMethodRestrictionEmbeddedTest.java From oxAuth with MIT License | 4 votes |
/** * Fail 3: Call to Token Endpoint with Auth Method * <code>private_key_jwt</code> should fail. */ @Parameters({"tokenPath", "userId", "userSecret", "audience", "RS256_keyId", "keyStoreFile", "keyStoreSecret"}) @Test(dependsOnMethods = "tokenEndpointAuthMethodClientSecretPostStep2") public void tokenEndpointAuthMethodClientSecretPostFail3(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String keyStoreFile, final String keyStoreSecret) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setAuthenticationMethod(AuthenticationMethod.PRIVATE_KEY_JWT); tokenRequest.setAlgorithm(SignatureAlgorithm.RS256); tokenRequest.setKeyId(keyId); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAudience(audience); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId3); tokenRequest.setAuthPassword(clientSecret3); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("tokenEndpointAuthMethodClientSecretPostFail3", response, entity); assertEquals(response.getStatus(), 401, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
Example 18
Source File: TokenRestWebServiceWithHSAlgEmbeddedTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"tokenPath", "userId", "userSecret", "audience"}) @Test(dependsOnMethods = "requestAccessTokenWithClientSecretJwtHS512Step1") public void requestAccessTokenWithClientSecretJwtHS512Step2(final String tokenPath, final String userId, final String userSecret, final String audience) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId3); tokenRequest.setAuthPassword(clientSecret3); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAlgorithm(SignatureAlgorithm.HS512); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwtHS512Step2", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); assertTrue( response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control")); assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma")); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found"); assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found"); assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found"); } catch (Exception e) { fail(e.getMessage(), e); } }
Example 19
Source File: TokenRestWebServiceWithHSAlgEmbeddedTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"tokenPath", "userId", "userSecret", "audience"}) @Test(dependsOnMethods = "requestAccessTokenWithClientSecretJwtHS384Step1") public void requestAccessTokenWithClientSecretJwtHS384Step2(final String tokenPath, final String userId, final String userSecret, final String audience) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId2); tokenRequest.setAuthPassword(clientSecret2); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAlgorithm(SignatureAlgorithm.HS384); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwtHS384Step2", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); assertTrue( response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control")); assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma")); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found"); assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found"); assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found"); } catch (Exception e) { fail(e.getMessage(), e); } }
Example 20
Source File: TokenRestWebServiceWithHSAlgEmbeddedTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"tokenPath", "userId", "userSecret", "audience"}) @Test(dependsOnMethods = "requestAccessTokenWithClientSecretJwtHS256Step1") public void requestAccessTokenWithClientSecretJwtHS256Step2(final String tokenPath, final String userId, final String userSecret, final String audience) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId1); tokenRequest.setAuthPassword(clientSecret1); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setCryptoProvider(cryptoProvider); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwtHS256Step2", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); assertTrue( response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control")); assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma")); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found"); assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found"); assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found"); } catch (Exception e) { fail(e.getMessage(), e); } }