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());
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations