Search in sources :

Example 6 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.

the class AuthorizationCodeFlowEmbeddedTest method revokeTokensStep4.

@Parameters({ "tokenPath" })
@Test(dependsOnMethods = { "dynamicClientRegistration", "revokeTokensStep2n3" })
public void revokeTokensStep4(final String tokenPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
    TokenRequest tokenRequest = new TokenRequest(GrantType.REFRESH_TOKEN);
    tokenRequest.setRefreshToken(refreshToken1);
    tokenRequest.setScope("email read_stream manage_pages");
    tokenRequest.setAuthUsername(clientId);
    tokenRequest.setAuthPassword(clientSecret);
    request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("revokeTokensStep4", 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);
    }
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 7 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.

the class AuthorizationCodeFlowEmbeddedTest method completeFlowStep3.

public void completeFlowStep3(final String tokenPath, final String refreshToken) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
    TokenRequest tokenRequest = new TokenRequest(GrantType.REFRESH_TOKEN);
    tokenRequest.setRefreshToken(refreshToken);
    tokenRequest.setScope("email read_stream manage_pages");
    tokenRequest.setAuthUsername(clientId);
    tokenRequest.setAuthPassword(clientSecret);
    request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("completeFlowStep3", 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);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException)

Example 8 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.

the class AuthorizationCodeFlowEmbeddedTest method revokeTokensStep2n3.

@Parameters({ "tokenPath", "redirectUri" })
@Test(dependsOnMethods = { "dynamicClientRegistration", "revokeTokensStep1" })
public void revokeTokensStep2n3(final String tokenPath, final String redirectUri) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
    TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE);
    tokenRequest.setCode(authorizationCode2);
    tokenRequest.setRedirectUri(redirectUri);
    tokenRequest.setAuthUsername(clientId);
    tokenRequest.setAuthPassword(clientSecret);
    request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("revokeTokensStep2n3", 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("refresh_token"), "Unexpected result: refresh_token not found");
        assertTrue(jsonObj.has("id_token"), "Unexpected result: id_token not found");
        accessToken1 = jsonObj.getString("access_token");
        refreshToken1 = jsonObj.getString("refresh_token");
        Builder request2 = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
        TokenRequest tokenRequest2 = new TokenRequest(GrantType.AUTHORIZATION_CODE);
        tokenRequest2.setCode(authorizationCode2);
        tokenRequest2.setRedirectUri(redirectUri);
        tokenRequest2.setAuthUsername(clientId);
        tokenRequest2.setAuthPassword(clientSecret);
        request2.header("Authorization", "Basic " + tokenRequest2.getEncodedCredentials());
        Response response2 = request2.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest2.getParameters())));
        String entity2 = response2.readEntity(String.class);
        showResponse("revokeTokens step 3", response2, entity2);
        assertEquals(response2.getStatus(), 400, "Unexpected response code.");
        assertNotNull(entity2, "Unexpected result: " + entity2);
        try {
            JSONObject jsonObj2 = new JSONObject(entity2);
            assertTrue(jsonObj2.has("error"), "The error type is null");
            assertTrue(jsonObj2.has("error_description"), "The error description is null");
        } catch (JSONException e) {
            e.printStackTrace();
            fail(e.getMessage() + "\nResponse was: " + entity2);
        }
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 9 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.

the class AuthorizationCodeFlowEmbeddedTest method completeFlowStep2.

@Parameters({ "tokenPath", "validateTokenPath", "redirectUri" })
@Test(dependsOnMethods = { "dynamicClientRegistration", "completeFlowStep1" })
public void completeFlowStep2(final String tokenPath, final String validateTokenPath, final String redirectUri) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
    TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE);
    tokenRequest.setCode(authorizationCode1);
    tokenRequest.setRedirectUri(redirectUri);
    tokenRequest.setAuthUsername(clientId);
    tokenRequest.setAuthPassword(clientSecret);
    request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("completeFlowStep2", 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("refresh_token"), "Unexpected result: refresh_token not found");
        assertTrue(jsonObj.has("id_token"), "Unexpected result: id_token not found");
        String accessToken = jsonObj.getString("access_token");
        String refreshToken = jsonObj.getString("refresh_token");
        completeFlowStep3(tokenPath, refreshToken);
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 10 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.

the class ClientInfoRestWebServiceEmbeddedTest method requestClientInfoStep2PostImplicitFlow.

@Parameters({ "clientInfoPath" })
@Test(dependsOnMethods = "requestClientInfoStep1ImplicitFlow")
public void requestClientInfoStep2PostImplicitFlow(final String clientInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + clientInfoPath).request();
    request.header("Authorization", "Bearer " + accessToken1);
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestClientInfo step 2 POST Implicit Flow", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store, private"), "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("displayName"), "Unexpected result: displayName not found");
        assertTrue(jsonObj.has("inum"), "Unexpected result: inum not found");
        assertTrue(jsonObj.has("oxAuthAppType"), "Unexpected result: oxAuthAppType not found");
        assertTrue(jsonObj.has("oxAuthIdTokenSignedResponseAlg"), "Unexpected result: oxAuthIdTokenSignedResponseAlg not found");
        assertTrue(jsonObj.has("oxAuthRedirectURI"), "Unexpected result: oxAuthRedirectURI not found");
        assertTrue(jsonObj.has("oxAuthScope"), "Unexpected result: oxAuthScope not found");
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) ClientInfoRequest(org.xdi.oxauth.client.ClientInfoRequest) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Aggregations

MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)301 Response (javax.ws.rs.core.Response)191 Builder (javax.ws.rs.client.Invocation.Builder)151 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)150 Test (org.testng.annotations.Test)146 Parameters (org.testng.annotations.Parameters)144 Test (org.junit.Test)95 JSONException (org.codehaus.jettison.json.JSONException)77 JSONObject (org.codehaus.jettison.json.JSONObject)73 JSONException (org.json.JSONException)73 BaseTest (org.xdi.oxauth.BaseTest)73 BaseTest (org.gluu.oxauth.BaseTest)71 JSONObject (org.json.JSONObject)69 URISyntaxException (java.net.URISyntaxException)58 TokenRequest (org.gluu.oxauth.client.TokenRequest)40 TokenRequest (org.xdi.oxauth.client.TokenRequest)39 URI (java.net.URI)34 ByteArrayInputStream (java.io.ByteArrayInputStream)27 Matchers.containsString (org.hamcrest.Matchers.containsString)26 HashMap (java.util.HashMap)24