Search in sources :

Example 1 with UserInfoRequest

use of org.xdi.oxauth.client.UserInfoRequest in project oxAuth by GluuFederation.

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoInvalidSchema.

@Parameters({ "userInfoPath" })
@Test
public void requestUserInfoInvalidSchema(final String userInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    UserInfoRequest userInfoRequest = new UserInfoRequest("INVALID_ACCESS_TOKEN");
    Map<String, String> userInfoParameters = userInfoRequest.getParameters();
    userInfoParameters.put("schema", "INVALID_SCHEMA");
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfoInvalidSchema", response, entity);
    assertEquals(response.getStatus(), 400, "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 : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) Builder(javax.ws.rs.client.Invocation.Builder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) JSONException(org.codehaus.jettison.json.JSONException) UserInfoRequest(org.xdi.oxauth.client.UserInfoRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 2 with UserInfoRequest

use of org.xdi.oxauth.client.UserInfoRequest in project oxAuth by GluuFederation.

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoInsufficientScopeStep2.

@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoInsufficientScope")
public void requestUserInfoInsufficientScopeStep2(final String userInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    UserInfoRequest userInfoRequest = new UserInfoRequest(accessToken2);
    userInfoRequest.setAuthorizationMethod(AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfoInsufficientScope step 2", response, entity);
    assertEquals(response.getStatus(), 403, "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 : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) Builder(javax.ws.rs.client.Invocation.Builder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) JSONException(org.codehaus.jettison.json.JSONException) UserInfoRequest(org.xdi.oxauth.client.UserInfoRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 3 with UserInfoRequest

use of org.xdi.oxauth.client.UserInfoRequest in project oxAuth by GluuFederation.

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoStep2GetImplicitFlow.

@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoStep1ImplicitFlow")
public void requestUserInfoStep2GetImplicitFlow(final String userInfoPath) throws Exception {
    UserInfoRequest userInfoRequest = new UserInfoRequest(null);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath + "?" + userInfoRequest.getQueryString()).request();
    request.header("Authorization", "Bearer " + accessToken1);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfo step 2 GET 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(JwtClaimName.SUBJECT_IDENTIFIER));
        assertTrue(jsonObj.has(JwtClaimName.NAME));
        assertTrue(jsonObj.has(JwtClaimName.GIVEN_NAME));
        assertTrue(jsonObj.has(JwtClaimName.FAMILY_NAME));
        assertTrue(jsonObj.has(JwtClaimName.EMAIL));
    } 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) JSONObject(org.codehaus.jettison.json.JSONObject) Builder(javax.ws.rs.client.Invocation.Builder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) JSONException(org.codehaus.jettison.json.JSONException) UserInfoRequest(org.xdi.oxauth.client.UserInfoRequest) URISyntaxException(java.net.URISyntaxException) InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 4 with UserInfoRequest

use of org.xdi.oxauth.client.UserInfoRequest in project oxAuth by GluuFederation.

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoInvalidRequest.

@Parameters({ "userInfoPath" })
@Test
public void requestUserInfoInvalidRequest(final String userInfoPath) throws Exception {
    UserInfoRequest userInfoRequest = new UserInfoRequest(null);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfoInvalidRequest", response, entity);
    assertEquals(response.getStatus(), 400, "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 : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) Builder(javax.ws.rs.client.Invocation.Builder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) JSONException(org.codehaus.jettison.json.JSONException) UserInfoRequest(org.xdi.oxauth.client.UserInfoRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 5 with UserInfoRequest

use of org.xdi.oxauth.client.UserInfoRequest in project oxAuth by GluuFederation.

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoInvalidToken.

@Parameters({ "userInfoPath" })
@Test
public void requestUserInfoInvalidToken(final String userInfoPath) throws Exception {
    UserInfoRequest userInfoRequest = new UserInfoRequest("INVALID_ACCESS_TOKEN");
    userInfoRequest.setAuthorizationMethod(AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfoInvalidToken", response, entity);
    assertEquals(response.getStatus(), 400, "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 : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) Builder(javax.ws.rs.client.Invocation.Builder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) JSONException(org.codehaus.jettison.json.JSONException) UserInfoRequest(org.xdi.oxauth.client.UserInfoRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Aggregations

UserInfoRequest (org.xdi.oxauth.client.UserInfoRequest)14 Builder (javax.ws.rs.client.Invocation.Builder)13 Response (javax.ws.rs.core.Response)13 JSONException (org.codehaus.jettison.json.JSONException)13 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)13 Parameters (org.testng.annotations.Parameters)13 Test (org.testng.annotations.Test)13 BaseTest (org.xdi.oxauth.BaseTest)13 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)13 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)12 JSONObject (org.codehaus.jettison.json.JSONObject)10 URISyntaxException (java.net.URISyntaxException)9 InvalidJwtException (org.xdi.oxauth.model.exception.InvalidJwtException)7 Jwt (org.xdi.oxauth.model.jwt.Jwt)3 UserInfoClient (org.xdi.oxauth.client.UserInfoClient)1