Search in sources :

Example 66 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoStep2PasswordFlow.

@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoStep1PasswordFlow")
public void requestUserInfoStep2PasswordFlow(final String userInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
    request.header("Authorization", "Bearer " + accessToken4);
    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("requestUserInfoStep2PasswordFlow", 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 67 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class TestUtil method assertErrorResponse.

public static void assertErrorResponse(String p_entity) {
    assertNotNull(p_entity, "Unexpected result: " + p_entity);
    try {
        JSONObject jsonObj = new JSONObject(p_entity);
        assertTrue(jsonObj.has("error"), "The error type is null");
        assertTrue(jsonObj.has("error_description"), "The error description is null");
    } catch (JSONException e) {
        LOG.error(e.getMessage(), e);
        fail(e.getMessage() + "\nResponse was: " + p_entity);
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException)

Example 68 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class JwtClaimSet method load.

public void load(String base64JsonObject) throws InvalidJwtException {
    try {
        String jsonObjectString = new String(Base64Util.base64urldecode(base64JsonObject), Util.UTF8_STRING_ENCODING);
        load(new JSONObject(jsonObjectString));
    } catch (UnsupportedEncodingException e) {
        throw new InvalidJwtException(e);
    } catch (JSONException e) {
        throw new InvalidJwtException(e);
    } catch (Exception e) {
        throw new InvalidJwtException(e);
    }
}
Also used : InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) JSONObject(org.codehaus.jettison.json.JSONObject) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONException(org.codehaus.jettison.json.JSONException) JSONException(org.codehaus.jettison.json.JSONException) InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 69 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class JwtClaimSet method getClaimAsStringList.

public List<String> getClaimAsStringList(String key) {
    List<String> list = new ArrayList<String>();
    Object claims = getClaim(key);
    try {
        if (claims != null && claims instanceof JSONArray) {
            JSONArray jsonArray = (JSONArray) claims;
            for (int i = 0; i < jsonArray.length(); i++) {
                list.add(jsonArray.getString(i));
            }
        } else {
            String claim = getClaimAsString(key);
            if (claim != null) {
                list.add(claim);
            }
        }
    } catch (JSONException e) {
    }
    return list;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 70 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class JwtClaimSet method toMap.

public Map<String, List<String>> toMap() throws InvalidJwtException {
    Map<String, List<String>> map = new HashMap<String, java.util.List<String>>();
    try {
        for (Map.Entry<String, Object> claim : claims.entrySet()) {
            String key = claim.getKey();
            Object value = claim.getValue();
            List<String> values = new ArrayList<String>();
            if (value instanceof JSONArray) {
                JSONArray jsonArray = (JSONArray) value;
                for (int i = 0; i < jsonArray.length(); i++) {
                    values.add(jsonArray.getString(i));
                }
            } else if (value != null) {
                values.add(value.toString());
            }
            map.put(key, values);
        }
    } catch (JSONException e) {
        throw new InvalidJwtException(e);
    }
    return map;
}
Also used : InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) java.util(java.util) JSONObject(org.codehaus.jettison.json.JSONObject)

Aggregations

JSONException (org.codehaus.jettison.json.JSONException)281 JSONObject (org.codehaus.jettison.json.JSONObject)256 Response (javax.ws.rs.core.Response)183 Builder (javax.ws.rs.client.Invocation.Builder)179 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)179 Test (org.testng.annotations.Test)174 BaseTest (org.xdi.oxauth.BaseTest)174 Parameters (org.testng.annotations.Parameters)171 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)78 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)68 JSONArray (org.codehaus.jettison.json.JSONArray)44 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)43 URISyntaxException (java.net.URISyntaxException)35 TokenRequest (org.xdi.oxauth.client.TokenRequest)35 ResponseType (org.xdi.oxauth.model.common.ResponseType)35 WebApplicationException (javax.ws.rs.WebApplicationException)18 IOException (java.io.IOException)17 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)17 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14