Search in sources :

Example 11 with UserInfoRequest

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

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoAdditionalClaimsStep2.

@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoAdditionalClaims")
public void requestUserInfoAdditionalClaimsStep2(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(accessToken3);
    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("requestUserInfoAdditionalClaims step 2", 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));
        // Custom attributes
        assertTrue(jsonObj.has("iname"));
        assertTrue(jsonObj.has("o"));
    } 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) 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 12 with UserInfoRequest

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

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoHS256Step3.

@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoHS256Step2")
public void requestUserInfoHS256Step3(final String userInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
    request.header("Authorization", "Bearer " + accessToken5);
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    UserInfoRequest userInfoRequest = new UserInfoRequest(null);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfoHS256Step3", 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 {
        Jwt jwt = Jwt.parse(entity);
        assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER));
        assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.NAME));
        assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.EMAIL));
        assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.PICTURE));
    } catch (InvalidJwtException 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) InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) Jwt(org.xdi.oxauth.model.jwt.Jwt) Builder(javax.ws.rs.client.Invocation.Builder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) 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 13 with UserInfoRequest

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

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoStep2PostImplicitFlow.

@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoStep1ImplicitFlow")
public void requestUserInfoStep2PostImplicitFlow(final String userInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
    request.header("Authorization", "Bearer " + accessToken1);
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    UserInfoRequest userInfoRequest = new UserInfoRequest(null);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfo 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(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) 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) 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 14 with UserInfoRequest

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

the class OpenIDRequestObjectEmbeddedTest method requestParameterMethod2Step3.

@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = { "requestParameterMethod2Step2" })
public void requestParameterMethod2Step3(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("requestParameterMethod2Step3", 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));
    } 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) 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) JSONException(org.codehaus.jettison.json.JSONException) 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