Example usage for javax.json JsonNumber intValue

List of usage examples for javax.json JsonNumber intValue

Introduction

In this page you can find the example usage for javax.json JsonNumber intValue.

Prototype

int intValue();

Source Link

Document

Returns this JSON number as an int .

Usage

From source file:jp.co.yahoo.yconnect.core.oidc.IdTokenDecoder.java

/**
 * IdToken?//from  w  w w  .  ja v a 2  s  . c o  m
 * 
 * @return IdTokenObject
 * @throws DataFormatException
 */
public IdTokenObject decode() throws DataFormatException {

    HashMap<String, String> idToken = this.splitIdToken();

    // Header
    String jsonHeader = idToken.get("header");

    JsonReader jsonHeaderReader = Json.createReader(new StringReader(jsonHeader));
    JsonObject rootHeader = jsonHeaderReader.readObject();
    jsonHeaderReader.close();

    JsonString typeString = rootHeader.getJsonString("typ");
    String type = typeString.getString();

    JsonString algorithmString = rootHeader.getJsonString("alg");
    String algorithm = algorithmString.getString();

    // Payload
    String jsonPayload = idToken.get("payload");

    JsonReader jsonPayloadReader = Json.createReader(new StringReader(jsonPayload));

    JsonObject rootPayload = jsonPayloadReader.readObject();
    jsonPayloadReader.close();

    JsonString issString = rootPayload.getJsonString("iss");
    String iss = issString.getString();

    JsonString userIdString = rootPayload.getJsonString("user_id");
    String userId = userIdString.getString();

    JsonString audString = rootPayload.getJsonString("aud");
    ArrayList<String> aud = new ArrayList<String>();
    aud.add(audString.getString());

    JsonNumber expString = rootPayload.getJsonNumber("exp");
    int exp = expString.intValue();

    JsonNumber iatString = rootPayload.getJsonNumber("iat");
    int iat = iatString.intValue();

    JsonString nonceString = rootPayload.getJsonString("nonce");
    String nonce = nonceString.getString();

    // signature
    String signature = idToken.get("signature");

    // ???
    return new IdTokenObject(type, algorithm, iss, userId, aud, nonce, exp, iat, signature);
}