@GET @Path("/verifyInjectedAudience") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("Tester") public JsonObject verifyInjectedAudience(@QueryParam("aud") String audience) { boolean pass = false; String msg; // aud List<JsonString> audValue = aud.getValuesAs(JsonString.class); if(audValue == null || audValue.size() == 0) { msg = Claims.aud.name()+"value is null or empty, FAIL"; } else if(audValue.get(0).getString().equals(audience)) { msg = Claims.aud.name()+" PASS"; pass = true; } else { msg = String.format("%s: %s != %s", Claims.aud.name(), audValue, audience); } JsonObject result = Json.createObjectBuilder() .add("pass", pass) .add("msg", msg) .build(); return result; }
/** * {@inheritDoc} * @since 2017/12/13 */ @Override public RemoteResult send(RemoteRequest __r) throws NullPointerException, RemoteException { if (__r == null) throw new NullPointerException(); // Send the request to the consumer so that it may test the remote // end accordingly Consumer<RemoteRequest> function = this.function; if (function != null) function.accept(__r); // Check the authorization token if (MockConfiguration.VALID_TOKEN.equals(((JsonString) ((JsonObject)__r.bodyValue()).get("client_id")).getString())) return new RemoteResult(202, "Accepted"); return new RemoteResult(401, "{\"message\":\"Invalid client id sent.\"}"); }
/** * Says if status is OK * @return true if status is OK */ public boolean isStatusOk() { if (jsonResult == null || jsonResult.isEmpty()) { return false; } try { JsonReader reader = Json.createReader(new StringReader(jsonResult)); JsonStructure jsonst = reader.read(); JsonObject object = (JsonObject) jsonst; JsonString status = (JsonString) object.get("status"); if (status != null && status.getString().equals("OK")) { return true; } else { return false; } } catch (Exception e) { this.parseException = e; invalidJsonStream = true; return false; } }
/** * Converts a {@link JsonValue} to its corresponding Java object. Values of type {@link * JsonObject} or {@link JsonArray} are converted as specified by {@link #toJavaMap} and {@link * #toJavaList}, respectively. */ @Nullable public static Object toJavaObject(JsonValue value) { switch (value.getValueType()) { case ARRAY: return toJavaList((JsonArray) value); case FALSE: return Boolean.FALSE; case NULL: return null; case NUMBER: JsonNumber number = (JsonNumber) value; return number.isIntegral() ? number.intValue() : number.doubleValue(); case OBJECT: return toJavaMap((JsonObject) value); case STRING: return ((JsonString) value).getString(); case TRUE: return Boolean.TRUE; default: throw new VerifyException("Json value with unknown type: " + value); } }
public static Object unbox(JsonValue value, Function<JsonStructure, Object> convert) throws JsonException { switch (value.getValueType()) { case ARRAY: case OBJECT: return convert.apply((JsonStructure) value); case FALSE: return Boolean.FALSE; case TRUE: return Boolean.TRUE; case NULL: return null; case NUMBER: JsonNumber number = (JsonNumber) value; return number.isIntegral() ? number.longValue() : number.doubleValue(); case STRING: return ((JsonString) value).getString(); default: throw new JsonException("Unknow value type"); } }
@POST @Path("shib") public Response createShibGroup(JsonObject shibGroupInput) { String expectedNameKey = "name"; JsonString name = shibGroupInput.getJsonString(expectedNameKey); if (name == null) { return errorResponse(Response.Status.BAD_REQUEST, "required field missing: " + expectedNameKey); } String expectedAttributeKey = "attribute"; JsonString attribute = shibGroupInput.getJsonString(expectedAttributeKey); if (attribute == null) { return errorResponse(Response.Status.BAD_REQUEST, "required field missing: " + expectedAttributeKey); } String expectedPatternKey = "pattern"; JsonString pattern = shibGroupInput.getJsonString(expectedPatternKey); if (pattern == null) { return errorResponse(Response.Status.BAD_REQUEST, "required field missing: " + expectedPatternKey); } ShibGroup shibGroupToPersist = new ShibGroup(name.getString(), attribute.getString(), pattern.getString(), shibGroupPrv); ShibGroup persitedShibGroup = shibGroupPrv.persist(shibGroupToPersist); if (persitedShibGroup != null) { return okResponse("Shibboleth group persisted: " + persitedShibGroup); } else { return errorResponse(Response.Status.BAD_REQUEST, "Could not persist Shibboleth group"); } }
/** * Constructor * * @param data Json load from response body */ Product(JsonObject data) { super(data); this.imageList = new LinkedList<>(); if (data.get("Images") instanceof JsonObject) { JsonValue imageData = data.getJsonObject("Images").get("Image"); if (imageData instanceof JsonArray) { for (JsonValue img : (JsonArray) imageData) { if (img instanceof JsonString) { imageList.add(((JsonString) img).getString()); } } } else { imageList.add(imageData.toString()); } } this.productData = new ProductData(data.getJsonObject("ProductData")); }
public static Session mapJsonToSession(JsonObject jsonObject) { int capacity = jsonObject.containsKey("capacity") ? jsonObject.getInt("capacity") : 0; long endTime = jsonObject.containsKey("endTime") ? jsonObject.getJsonNumber("endTime").longValue() : 0L; String experienceLevel = jsonObject.containsKey("experienceLevel") ? jsonObject.getString("experienceLevel") : ""; String location = jsonObject.containsKey("location") ? jsonObject.getString("location") : ""; int registered = jsonObject.containsKey("registered") ? jsonObject.getInt("registered") : 0; List<String> speakersUuid = new ArrayList<>(); if (jsonObject.containsKey("speakersUuid")) { JsonObject speakersObject = jsonObject.getJsonObject("speakersUuid"); for (JsonString jsonString : speakersObject.getJsonArray("items").getValuesAs(JsonString.class)) { speakersUuid.add(jsonString.getString()); } } long startTime = jsonObject.containsKey("startTime") ? jsonObject.getJsonNumber("startTime").longValue() : 0L; String summary = jsonObject.containsKey("summary") ? jsonObject.getString("summary") : ""; String title = jsonObject.containsKey("title") ? jsonObject.getString("title") : ""; Track track = jsonObject.containsKey("track") ? Track.valueOf(jsonObject.getString("track")) : null; String type = jsonObject.containsKey("type") ? jsonObject.getString("type") : ""; String uuid = jsonObject.containsKey("uuid") ? jsonObject.getString("uuid") : ""; return new Session(uuid, title, summary, location, capacity, registered, startTime, endTime, track, type, experienceLevel, speakersUuid); }
public Bson buildAdditionalQuery(JsonObject filter) { List<Bson> fragments = new ArrayList<>(); if(filter.containsKey("eid")) { fragments.add(new Document("executionID", filter.getString("eid"))); } fragments.add(or(new Document("_class","step.artefacts.reports.CallFunctionReportNode"), new Document("_class","step.artefacts.reports.EchoReportNode"), new Document("error.root",true))); if(filter.containsKey("testcases")) { //customAttributes.TestCase List<String> testcaseIds = new ArrayList<>(); filter.getJsonArray("testcases").forEach(v->testcaseIds.add(((JsonString)v).getString())); fragments.add(in("customAttributes.TestCase",testcaseIds)); } return and(fragments); }
@OnMessage public void onMessage(String id, Session s) throws IOException { JsonObject m = manager.get(id); if (m == null) { s.close(); return; } JsonString url = m.getJsonString("meetingURL"); if (url != null) { s.getBasicRemote().sendText(url.getString()); s.close(); return; } Queue<Session> sessions = listeners.get(id); if (sessions == null) { sessions = new ArrayBlockingQueue<>(1000); Queue<Session> actual = listeners.putIfAbsent(id, sessions); if (actual != null) { sessions = actual; } } sessions.add(s); }
public static CouchID fromJSON(InputStream is) { JsonReader rdr = null; try { rdr = Json.createReader(is); JsonObject couchIDJson = rdr.readObject(); JsonString idJson = couchIDJson.getJsonString("id"); JsonString revJson = couchIDJson.getJsonString("rev"); CouchID attendee = new CouchID(idJson.getString(), revJson.getString()); return attendee; } finally { if (rdr != null) { rdr.close(); } } }
@Test public void duplication() { String json = "[\"club\", \"diamond\", \"club\", \"spade\"]"; Schema schema = schema(array(string()).unique()); JsonValidator validator = new BasicJsonValidator(schema); ValidationResult result = validator.validate(new StringReader(json)); assertResultValid(result, json); assertThat(result.getProblems().size(), equalTo(1)); assertThat(result.getProblems().get(0), instanceOf(ArrayDuplicateItemProblem.class)); ArrayDuplicateItemProblem p = (ArrayDuplicateItemProblem)result.getProblems().get(0); assertThat(p.getPointer().toString(), equalTo("")); assertThat(p.getDuplicateIndex(), equalTo(2)); assertThat(((JsonString)p.getDuplicateItem()).getString(), equalTo("club")); assertNotNull(p.getDescription()); }
private boolean botInChannel(final String team, final String channel) { final String bot = botUser(team); final String botToken = utoken(bot); try { return channelInfo(botToken, channel).get() .getJsonObject("channel") .getJsonArray("members") .stream() .map(jv -> ((JsonString) jv).getString()) .filter(bot::equals) .findAny() .isPresent(); } catch (final Exception x) { return false; } }
private Object plainifyJsonValue(final JsonValue jval) { switch (jval.getValueType()) { case ARRAY: return plainifyJsonArray((JsonArray) jval); case FALSE: return Boolean.FALSE; case TRUE: return Boolean.TRUE; case NULL: return null; case NUMBER: return ((JsonNumber) jval).bigDecimalValue(); case OBJECT: return plainifyJsonObject((JsonObject) jval); case STRING: return ((JsonString) jval).getString(); default: throw new RuntimeException("unexpected json type"); } }
private static String readAdapterNotes(JsonObject root) { if (root.containsKey("adapterNotes")) { JsonValue notes = root.get("adapterNotes"); if (notes.getValueType() == ValueType.STRING) { // Return unquoted string return ((JsonString)notes).getString(); } else { return notes.toString(); } } return ""; }
private Object map( JsonValue v ) { switch( v.getValueType() ) { case STRING: return ((JsonString) v).getString(); case NUMBER: return ((JsonNumber) v).bigDecimalValue(); case TRUE: return true; case FALSE: return false; case OBJECT: return MapBuilder.fromJsonObject( (JsonObject) v ); case ARRAY: return CollectionBuilder.fromJsonArray( (JsonArray) v ); case NULL: default: return null; } }
public static String getString( JsonObject o, String n, String defaultValue ) { JsonValue v = o.get( n ); if( v == null ) { return defaultValue; } switch( v.getValueType() ) { case NUMBER: JsonNumber jn = (JsonNumber) v; return jn.toString(); case STRING: JsonString s = (JsonString) v; return s.getString(); case TRUE: return "true"; case FALSE: return "false"; case NULL: return defaultValue; default: return v.toString(); } }
public static Boolean getBoolean( JsonObject o, String n, Boolean defaultValue ) { JsonValue v = o.get( n ); if( v == null ) { return defaultValue; } switch( v.getValueType() ) { case NUMBER: JsonNumber jn = (JsonNumber) v; return !jn.bigIntegerValue(). equals( BigInteger.ZERO ); case STRING: JsonString s = (JsonString) v; return Boolean.parseBoolean( s.getString() ); case TRUE: return true; case FALSE: return false; case NULL: return defaultValue; default: return Boolean.parseBoolean( v.toString() ); } }
public static Date getDate( JsonValue v ) { if( v == null ) { return null; } switch( v.getValueType() ) { case NUMBER: return new Date( ((JsonNumber) v).longValue() ); case STRING: return Date.valueOf( ((JsonString) v).getString() ); case TRUE: case FALSE: case NULL: return null; default: return Date.valueOf( v.toString() ); } }
public static Time getTime( JsonValue v ) { if( v == null ) { return null; } switch( v.getValueType() ) { case NUMBER: return new Time( ((JsonNumber) v).longValue() ); case STRING: return Time.valueOf( ((JsonString) v).getString() ); case TRUE: case FALSE: case NULL: return null; default: return Time.valueOf( v.toString() ); } }
public static LocalTime getLocalTime( JsonObject o, String n ) { JsonValue v = o.get( n ); if( v == null ) { return null; } switch( v.getValueType() ) { case STRING: return TimeUtils.getLocalTime( ((JsonString) v).getString() ); case NUMBER: return TimeUtils.getLocalTime( ((JsonNumber) v).longValue() ); default: return null; } }
private String getEndPointUrl(ServletContextEvent e) { //if we're running in a cf, we should use the details from those environment vars. String vcap_application = System.getenv("VCAP_APPLICATION"); if(vcap_application!=null){ ServletContext sc = e.getServletContext(); String contextPath = sc.getContextPath(); JsonObject vcapApplication = Json.createReader(new StringReader(vcap_application)).readObject(); JsonArray uris = vcapApplication.getJsonArray("application_uris"); JsonString firstUriAsString = uris.getJsonString(0); endPointUrl = "ws://"+firstUriAsString.getString()+contextPath+"/room"; System.out.println("Using CF details of "+endPointUrl); }else{ System.out.println("This room is intended to obtain it's configuration from the CF environment"); System.out.println("Assuming that this room is running on localhost port 9080 (this should match the config in server.xml)"); endPointUrl = "ws://localhost:9080/room"; } return endPointUrl; }
@Override public List<String> affectedVersions() { final List<String> affected; final JsonArray versions = this.vulnerability .getJsonArray("affected_versions"); if(versions == null) { affected = new ArrayList<>(); } else { affected = new ArrayList<>(); for(final JsonValue version : versions) { affected.add(((JsonString) version).getString()); } } return affected; }
public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; }
@Test public void givenSourceAndTarget_shouldCreateMergePatch() { JsonMergeDiffExample jsonMergeDiffExample = new JsonMergeDiffExample(); JsonMergePatch mergePatch = jsonMergeDiffExample.createMergePatch(); JsonString jsonString = (JsonString) mergePatch.toJsonValue(); assertThat(jsonString.getString()).isEqualToIgnoringCase("{\"colour\":\"red\"}"); }
@Test public void givenPatch_sourceValueChanges() throws Exception { JsonMergePatchExample jsonMergePatchExample = new JsonMergePatchExample(); JsonValue result = jsonMergePatchExample.changeValue(); assertThat(((JsonString) result).getString()).isEqualToIgnoringCase("{\"colour\":\"red\"}"); }
@Test @Ignore // Behaviour is not as specified in https://tools.ietf.org/html/rfc7386 public void givenPatch_addNewJsonToSource() throws Exception { JsonMergePatchExample jsonMergePatchExample = new JsonMergePatchExample(); JsonValue result = jsonMergePatchExample.addValue(); assertThat(((JsonString) result).getString()).isEqualToIgnoringCase("{\"colour\":\"blue\",\"blue\":\"light\"}"); }
@Test @Ignore // Behaviour is not as specified in https://tools.ietf.org/html/rfc7386 public void givenPatch_deleteValue() throws Exception { JsonMergePatchExample jsonMergePatchExample = new JsonMergePatchExample(); JsonValue result = jsonMergePatchExample.deleteValue(); assertThat(((JsonString) result).getString()).isEqualToIgnoringCase("{}"); }
@GET @Path("/verifyInjectedCustomStringArray") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("Tester") public JsonObject verifyInjectedCustomStringArray(@QueryParam("value") List<String> array) { boolean pass = false; HashSet<String> expected = new HashSet<>(); for(String value : array) { expected.add(value); } StringBuilder msg = new StringBuilder(); if(customStringArray == null || customStringArray.size() == 0) { msg.append("customStringArray value is null or empty, FAIL"); } else if(customStringArray.size() != array.size()) { msg.append(String.format("customStringArray.size(%d) != expected.size(%d)", customStringArray.size(), array.size())); } else { for(int n = 0; n < customStringArray.size(); n ++) { JsonString js = customStringArray.getJsonString(n); if(!expected.remove(js.getString())) { msg.append(String.format("%s not found in expected", js.getString())); } } pass = expected.size() == 0; } JsonObject result = Json.createObjectBuilder() .add("pass", pass) .add("msg", msg.toString()) .build(); return result; }
static String getString(JsonObject jsonObject, String name) { return Optional.ofNullable(jsonObject.get(name)) .filter(it -> it.getValueType() == JsonValue.ValueType.STRING) .map(it -> ((JsonString) it).getString()) .orElse(null); }
private String getString(String name) { return Optional.ofNullable(_jsonObject.get(name)) .filter(it -> it.getValueType() == JsonValue.ValueType.STRING) .map(it -> ((JsonString) it).getString()) .orElse(null); }
/** * Returns the value for a name * @param name * @return the value */ public String getValue(String name) { if (name == null) { throw new NullPointerException("name is null!"); } if (isInvalidJsonStream()) { return null; } try { JsonReader reader = Json.createReader(new StringReader(jsonResult)); JsonStructure jsonst = reader.read(); JsonObject object = (JsonObject) jsonst; JsonString value = (JsonString) object.get(name); if (value == null) { return null; } return value.getString(); } catch (Exception e) { this.parseException = e; return null; } }
/** * Returns the error_type in case of failure * @return the error_type in case of failure, -1 if no error */ public int getErrorType() { if (isInvalidJsonStream()) { return 0; } try { JsonReader reader = Json.createReader(new StringReader(jsonResult)); JsonStructure jsonst = reader.read(); JsonObject object = (JsonObject) jsonst; JsonString status = (JsonString) object.get("status"); if (status == null) { return -1; } JsonNumber errorType = (JsonNumber) object.get("error_type"); if (errorType == null) { return -1; } else { return errorType.intValue(); } } catch (Exception e) { this.parseException = e; return -1; } }
/** * Returns the stack_trace in case of failure * @return the stack_trace in case of failure, null if no stack_trace */ public String getStackTrace() { if (isInvalidJsonStream()) { return null; } try { JsonReader reader = Json.createReader(new StringReader(jsonResult)); JsonStructure jsonst = reader.read(); JsonObject object = (JsonObject) jsonst; JsonString status = (JsonString) object.get("status"); if (status == null) { return null; } JsonString stackTrace = (JsonString) object.get("stack_trace"); if (stackTrace == null) { return null; } else { return stackTrace.getString(); } } catch (Exception e) { this.parseException = e; return null; } }
private ImmutableList<CallArgument> processScriptArguments(JsonArray args) { ImmutableList.Builder<CallArgument> argsBuilder = ImmutableList.builder(); for (JsonValue arg : args) { if (ValueType.OBJECT.equals(arg.getValueType())) { JsonObject jsonArg = (JsonObject) arg; if (jsonArg.containsKey("ELEMENT")) { NodeId n = new NodeId(Integer.parseInt(jsonArg.getString("ELEMENT").split("_")[1])); RemoteWebElement rwep = new RemoteWebElement(n, this); argsBuilder.add(callArgument().withObjectId(rwep.getRemoteObject().getId())); } else { log.info("JsonObject without ELEMENT tag" + jsonArg); } } else if (ValueType.ARRAY.equals(arg.getValueType())) { JsonObject array = getScriptResponse("return " + arg + ";"); argsBuilder.add(callArgument().withObjectId(getResponseBody(array).getString("objectId"))); } else if (ValueType.FALSE.equals(arg.getValueType())) { argsBuilder.add(callArgument().withValue(false)); } else if (ValueType.TRUE.equals(arg.getValueType())) { argsBuilder.add(callArgument().withValue(true)); } else if (ValueType.NUMBER.equals(arg.getValueType())) { argsBuilder.add(callArgument().withValue(((JsonNumber) arg).longValue())); } else if (ValueType.STRING.equals(arg.getValueType())) { argsBuilder.add(callArgument().withValue(((JsonString) arg).getString())); } else { throw new WebDriverException("Unsupported argument type: " + arg.getValueType()); } } return argsBuilder.build(); }
@Override public Response handle() throws Exception { JsonValue p = getRequest().getPayload().get("id"); if (JsonValue.NULL.equals(p)) { getWebDriver().getContext().setCurrentFrame(null, null, null); } else { RemoteWebElement iframe; switch (p.getValueType()) { case NUMBER: iframe = getIframe(((JsonNumber) p).intValue()); break; case OBJECT: String id = ((JsonObject) p).getString("ELEMENT"); iframe = getWebDriver().createElement(id); break; case STRING: iframe = getIframe(((JsonString) p).getString()); break; default: throw new UnsupportedCommandException("cannot select frame by " + p.getClass()); } RemoteWebElement document = iframe.getContentDocument(); RemoteWebElement window = iframe.getContentWindow(); getWebDriver().getContext().setCurrentFrame(iframe, document, window); } Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
public static String getString(String key, JsonObject json) { String result = null; if (json.containsKey(key)) { JsonString value = json.getJsonString(key); if (value != null) { result = value.getString(); } } return result; }
public static LocalDate getDate(String key, JsonObject json) { LocalDate result = null; if (json.containsKey(key)) { JsonString value = json.getJsonString(key); if (value != null) { result = date(value.getString()); } } return result; }
public static LocalTime getTime(String key, JsonObject json) { LocalTime result = null; if (json.containsKey(key)) { JsonString value = json.getJsonString(key); if (value != null) { result = time(value.getString()); } } return result; }
/** * * @param queue * @return * @throws JMSException */ public String getAddress(String queue) throws JMSException { return withRequestor(r -> { final Message req = r.context().createMessage(); putOperationInvocation(req, ResourceNames.QUEUE + queue, "listConsumerAsJSON"); final Message res = r.request(req, 1, TimeUnit.MINUTES); return ((JsonString) getResults(res).get(0)).getString(); }); }