Package net.minidev.json

Examples of net.minidev.json.JSONObject


  public static JOSEObject parse(final String s)
    throws ParseException {

    Base64URL[] parts = split(s);

    JSONObject jsonObject;

    try {
      jsonObject = JSONObjectUtils.parseJSONObject(parts[0].decodeToString());

    } catch (ParseException e) {
View Full Code Here



  @Override
  public JSONObject toJSONObject() {

    JSONObject o = new JSONObject(customClaims);

    if (iss != null) {
      o.put(ISSUER_CLAIM, iss);
    }

    if (sub != null) {
      o.put(SUBJECT_CLAIM, sub);
    }

    if (aud != null && ! aud.isEmpty()) {

      if (aud.size() == 1) {
        o.put(AUDIENCE_CLAIM, aud.get(0));
      } else {
        JSONArray audArray = new JSONArray();
        audArray.addAll(aud);
        o.put(AUDIENCE_CLAIM, audArray);
      }
    }

    if (exp != null) {
      o.put(EXPIRATION_TIME_CLAIM, exp.getTime() / 1000);
    }

    if (nbf != null) {
      o.put(NOT_BEFORE_CLAIM, nbf.getTime() / 1000);
    }

    if (iat != null) {
      o.put(ISSUED_AT_CLAIM, iat.getTime() / 1000);
    }

    if (jti != null) {
      o.put(JWT_ID_CLAIM, jti);
    }

    if (typ != null) {
      o.put(TYPE_CLAIM, typ);
    }

    return o;
  }
View Full Code Here

  @Override
  public ReadOnlyJWTClaimsSet getJWTClaimsSet()
    throws ParseException {

    JSONObject json = getPayload().toJSONObject();

    if (json == null) {
     
      throw new ParseException("Payload of plain JOSE object is not a valid JSON object", 0);
    }
View Full Code Here

    assertEquals(1, cs.getCustomClaims().size());


    // serialise
    JSONObject json = cs.toJSONObject();

    assertEquals(9, json.size());

    // parse back

    try {
      cs = JWTClaimsSet.parse(json);
View Full Code Here

    assertNull("x-custom init check", cs.getClaim("x-custom"));
    cs.setClaim("x-custom", "abc");
    assertEquals("abc", (String)cs.getClaim("x-custom"));

    // serialise
    JSONObject json = cs.toJSONObject();

    assertEquals(2, json.size());

    // parse back

    try {
      cs = JWTClaimsSet.parse(json);
View Full Code Here

    cs.setIssueTime(ONE_MIN_AFTER_EPOCH);
    cs.setNotBeforeTime(ONE_MIN_AFTER_EPOCH);
    cs.setExpirationTime(ONE_MIN_AFTER_EPOCH);

    JSONObject json = cs.toJSONObject();

    assertEquals(new Long(60l), json.get("iat"));
    assertEquals(new Long(60l), json.get("nbf"));
    assertEquals(new Long(60l), json.get("exp"));
  }
View Full Code Here


  public void testStringAudience()
    throws Exception {

    JSONObject o = new JSONObject();
    o.put("aud", "http://example.com");

    ReadOnlyJWTClaimsSet jwtClaimsSet = JWTClaimsSet.parse(o.toJSONString());

    assertEquals("http://example.com", jwtClaimsSet.getAudience().get(0));
    assertEquals(1, jwtClaimsSet.getAudience().size());
  }
View Full Code Here


  public void testStringArrayAudience()
    throws Exception {

    JSONObject o = new JSONObject();
    o.put("aud", Arrays.asList("http://example.com"));

    ReadOnlyJWTClaimsSet jwtClaimsSet = JWTClaimsSet.parse(o.toJSONString());

    assertEquals("http://example.com", jwtClaimsSet.getAudience().get(0));
    assertEquals(1, jwtClaimsSet.getAudience().size());
  }
View Full Code Here


  public void testStringArrayMultipleAudience()
    throws Exception {

    JSONObject o = new JSONObject();
    o.put("aud", Arrays.asList("http://example.com", "http://example2.com"));

    ReadOnlyJWTClaimsSet jwtClaimsSet = JWTClaimsSet.parse(o.toJSONString());

    assertEquals("http://example.com", jwtClaimsSet.getAudience().get(0));
    assertEquals("http://example2.com", jwtClaimsSet.getAudience().get(1));
    assertEquals(2, jwtClaimsSet.getAudience().size());
  }
View Full Code Here

    assertEquals("mfa", ((List<String>)claimsSet.getCustomClaim("amr")).get(0));
    assertEquals(1, ((List<String>)claimsSet.getCustomClaim("amr")).size());

    assertEquals("185.7.248.1", claimsSet.getStringClaim("login_ip"));

    JSONObject geoLoc = (JSONObject)claimsSet.getCustomClaim("login_geo");

    // {"long":"37.3956","lat":"-122.076"}
    assertEquals("37.3956", (String)geoLoc.get("long"));
    assertEquals("-122.076", (String)geoLoc.get("lat"));
  }
View Full Code Here

TOP

Related Classes of net.minidev.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.