Java Code Examples for net.minidev.json.JSONObject#getAsString()

The following examples show how to use net.minidev.json.JSONObject#getAsString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PyLint.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
int initialize() {
    JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);

    try {
        JSONArray elements = (JSONArray) parser.parse(PyLint.class.getResourceAsStream("pylint-descriptions.json"));
        for (Object element : elements) {
            JSONObject object = (JSONObject) element;
            String description = object.getAsString("description");
            descriptionByName.put(object.getAsString("name"), description);
            descriptionById.put(object.getAsString("code"), description);
        }
    }
    catch (ParseException | UnsupportedEncodingException ignored) {
        // ignore all exceptions
    }

    return descriptionByName.size();
}
 
Example 2
Source File: AdvertisingTopologyFlinkStateHighKeyCard.java    From yahoo-streaming-benchmark with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(String input, Collector<Tuple7<String, String, String, String, String, String, String>> out)
  throws Exception {
  JSONObject obj = (JSONObject) parser.parse(input);

  Tuple7<String, String, String, String, String, String, String> tuple =
    new Tuple7<>(
      obj.getAsString("user_id"),
      obj.getAsString("page_id"),
      obj.getAsString("campaign_id"),
      obj.getAsString("ad_type"),
      obj.getAsString("event_type"),
      obj.getAsString("event_time"),
      obj.getAsString("ip_address"));
  out.collect(tuple);
}
 
Example 3
Source File: ReconfigurationPlanConverter.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ReconfigurationPlan fromJSON(JSONObject ob)
    throws JSONConverterException {

    JSONs.checkKeys(ob, ORIGIN_LABEL, ACTIONS_LABEL);
    final Model m = mc.fromJSON((JSONObject) ob.get(ORIGIN_LABEL));
    final ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
    for (final JSONObject json : (List<JSONObject>) ob.get(ACTIONS_LABEL)) {
        final String id =
            json.getAsString(ActionConverter.ID_LABEL);
        ActionConverter<? extends Action> ac = json3java.get(id);
        if (ac == null) {
            throw new JSONConverterException(
                "No converter for action '" + id + "'");
        }
        final Action action = ac.fromJSON(m, json);
        eventsFromJSON(json, m, action);
        plan.add(action);
    }
    return plan;
}
 
Example 4
Source File: Song.java    From RecSys2018 with Apache License 2.0 5 votes vote down vote up
public Song(final JSONObject obj) {
	this.artist_name = obj.getAsString("artist_name");
	this.track_uri = obj.getAsString("track_uri");
	this.artist_uri = obj.getAsString("artist_uri");
	this.track_name = obj.getAsString("track_name");
	this.album_uri = obj.getAsString("album_uri");
	this.duration_ms = obj.getAsNumber("duration_ms").intValue();
	this.album_name = obj.getAsString("album_name");
}
 
Example 5
Source File: Playlist.java    From RecSys2018 with Apache License 2.0 5 votes vote down vote up
public Playlist(final JSONObject obj) {
	this.pid = obj.getAsString("pid");
	this.name = obj.getAsString("name");

	if (obj.containsKey("collaborative") == true) {
		this.collaborative = obj.getAsString("collaborative").toLowerCase()
				.equals("true");
	}
	if (obj.containsKey("modified_at") == true) {
		this.modified_at = obj.getAsNumber("modified_at").longValue();
	}
	if (obj.containsKey("num_albums") == true) {
		this.num_albums = obj.getAsNumber("num_albums").intValue();
	}
	if (obj.containsKey("num_tracks") == true) {
		this.num_tracks = obj.getAsNumber("num_tracks").intValue();
	}
	if (obj.containsKey("num_followers") == true) {
		this.num_followers = obj.getAsNumber("num_followers").intValue();
	}
	if (obj.containsKey("num_edits") == true) {
		this.num_edits = obj.getAsNumber("num_edits").intValue();
	}
	if (obj.containsKey("duration_ms") == true) {
		this.duration_ms = obj.getAsNumber("duration_ms").intValue();
	}
	if (obj.containsKey("num_artists") == true) {
		this.num_artists = obj.getAsNumber("num_artists").intValue();
	}
}
 
Example 6
Source File: ClientChainData.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private boolean verifyChain(List<String> chains) throws Exception {

        PublicKey lastKey = null;
        boolean mojangKeyVerified = false;
        for (String chain: chains) {
            JWSObject jws = JWSObject.parse(chain);

            if (!mojangKeyVerified) {
                // First chain should be signed using Mojang's private key. We'd be in big trouble if it leaked...
                mojangKeyVerified = verify(MOJANG_PUBLIC_KEY, jws);
            }

            if (lastKey != null) {
                if (!verify(lastKey, jws)) {
                    throw new JOSEException("Unable to verify key in chain.");
                }
            }

            JSONObject payload = jws.getPayload().toJSONObject();
            String base64key = payload.getAsString("identityPublicKey");
            if (base64key == null) {
                throw new RuntimeException("No key found");
            }
            lastKey = generateKey(base64key);
        }
        return mojangKeyVerified;
    }
 
Example 7
Source File: ClientChainData.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private boolean verifyChain(List<String> chains) throws Exception {

        PublicKey lastKey = null;
        boolean mojangKeyVerified = false;
        for (String chain: chains) {
            JWSObject jws = JWSObject.parse(chain);

            if (!mojangKeyVerified) {
                // First chain should be signed using Mojang's private key. We'd be in big trouble if it leaked...
                mojangKeyVerified = verify(MOJANG_PUBLIC_KEY, jws);
            }

            if (lastKey != null) {
                if (!verify(lastKey, jws)) {
                    throw new JOSEException("Unable to verify key in chain.");
                }
            }

            JSONObject payload = jws.getPayload().toJSONObject();
            String base64key = payload.getAsString("identityPublicKey");
            if (base64key == null) {
                throw new RuntimeException("No key found");
            }
            lastKey = generateKey(base64key);
        }
        return mojangKeyVerified;
    }
 
Example 8
Source File: GatewayUtils.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public static AuthenticationContext generateAuthenticationContext(String tokenSignature,
                                                                  JWTValidationInfo jwtValidationInfo,
                                                                  JSONObject api,
                                                                  APIKeyValidationInfoDTO apiKeyValidationInfoDTO,
                                                                  String apiLevelPolicy, String endUserToken,
                                                                  boolean isOauth) throws java.text.ParseException {


    AuthenticationContext authContext = new AuthenticationContext();
    authContext.setAuthenticated(true);
    authContext.setApiKey(tokenSignature);
    authContext.setUsername(jwtValidationInfo.getUser());

    if (apiKeyValidationInfoDTO != null) {
        authContext.setApiTier(apiKeyValidationInfoDTO.getApiTier());
        authContext.setKeyType(apiKeyValidationInfoDTO.getType());
        authContext.setApplicationId(apiKeyValidationInfoDTO.getApplicationId());
        authContext.setApplicationName(apiKeyValidationInfoDTO.getApplicationName());
        authContext.setApplicationTier(apiKeyValidationInfoDTO.getApplicationTier());
        authContext.setSubscriber(apiKeyValidationInfoDTO.getSubscriber());
        authContext.setTier(apiKeyValidationInfoDTO.getTier());
        authContext.setSubscriberTenantDomain(apiKeyValidationInfoDTO.getSubscriberTenantDomain());
        authContext.setApiName(apiKeyValidationInfoDTO.getApiName());
        authContext.setApiPublisher(apiKeyValidationInfoDTO.getApiPublisher());
        authContext.setStopOnQuotaReach(apiKeyValidationInfoDTO.isStopOnQuotaReach());
        authContext.setSpikeArrestLimit(apiKeyValidationInfoDTO.getSpikeArrestLimit());
        authContext.setSpikeArrestUnit(apiKeyValidationInfoDTO.getSpikeArrestUnit());
        authContext.setConsumerKey(apiKeyValidationInfoDTO.getConsumerKey());
        authContext.setIsContentAware(apiKeyValidationInfoDTO.isContentAware());
    } else {
        if (jwtValidationInfo.getClaims().get(APIConstants.JwtTokenConstants.KEY_TYPE)!= null) {
            authContext.setKeyType(
                    (String) jwtValidationInfo.getClaims().get(APIConstants.JwtTokenConstants.KEY_TYPE));
        } else {
            authContext.setKeyType(APIConstants.API_KEY_TYPE_PRODUCTION);
        }

        authContext.setApiTier(apiLevelPolicy);

        if (jwtValidationInfo.getClaims().get(APIConstants.JwtTokenConstants.APPLICATION) != null) {
            JSONObject applicationObj =
                    (JSONObject) jwtValidationInfo.getClaims().get(APIConstants.JwtTokenConstants.APPLICATION);

            authContext
                    .setApplicationId(String.valueOf(applicationObj.getAsNumber(APIConstants.JwtTokenConstants.APPLICATION_ID)));
            authContext.setApplicationName(applicationObj.getAsString(APIConstants.JwtTokenConstants.APPLICATION_NAME));
            authContext.setApplicationTier(applicationObj.getAsString(APIConstants.JwtTokenConstants.APPLICATION_TIER));
            authContext.setSubscriber(applicationObj.getAsString(APIConstants.JwtTokenConstants.APPLICATION_OWNER));
            if (applicationObj.containsKey(APIConstants.JwtTokenConstants.QUOTA_TYPE)
                    && APIConstants.JwtTokenConstants.QUOTA_TYPE_BANDWIDTH
                    .equals(applicationObj.getAsString(APIConstants.JwtTokenConstants.QUOTA_TYPE))) {
                authContext.setIsContentAware(true);;
            }
        }
    }
    if (isOauth) {
        authContext.setConsumerKey(jwtValidationInfo.getConsumerKey());
    }
    if (apiKeyValidationInfoDTO == null && api != null) {

        // If the user is subscribed to the API
        String subscriptionTier = api.getAsString(APIConstants.JwtTokenConstants.SUBSCRIPTION_TIER);
        authContext.setTier(subscriptionTier);
        authContext.setSubscriberTenantDomain(
                api.getAsString(APIConstants.JwtTokenConstants.SUBSCRIBER_TENANT_DOMAIN));
        JSONObject tierInfo =
                (JSONObject) jwtValidationInfo.getClaims().get(APIConstants.JwtTokenConstants.TIER_INFO);
        authContext.setApiName(api.getAsString(APIConstants.JwtTokenConstants.API_NAME));
        authContext.setApiPublisher(api.getAsString(APIConstants.JwtTokenConstants.API_PUBLISHER));
        if (tierInfo.get(subscriptionTier) != null) {
            JSONObject subscriptionTierObj = (JSONObject) tierInfo.get(subscriptionTier);
            authContext.setStopOnQuotaReach(
                    Boolean.parseBoolean(
                            subscriptionTierObj.getAsString(APIConstants.JwtTokenConstants.STOP_ON_QUOTA_REACH)));
            authContext.setSpikeArrestLimit
                    (subscriptionTierObj.getAsNumber(APIConstants.JwtTokenConstants.SPIKE_ARREST_LIMIT).intValue());
            if (!"null".equals(
                    subscriptionTierObj.getAsString(APIConstants.JwtTokenConstants.SPIKE_ARREST_UNIT))) {
                authContext.setSpikeArrestUnit(
                        subscriptionTierObj.getAsString(APIConstants.JwtTokenConstants.SPIKE_ARREST_UNIT));
            }
            //check whether the quota type is there and it is equal to bandwithVolume type.
            if (subscriptionTierObj.containsKey(APIConstants.JwtTokenConstants.QUOTA_TYPE)
                    && APIConstants.JwtTokenConstants.QUOTA_TYPE_BANDWIDTH
                    .equals(subscriptionTierObj.getAsString(APIConstants.JwtTokenConstants.QUOTA_TYPE))) {
                authContext.setIsContentAware(true);;
            }
        }
    }
    // Set JWT token sent to the backend
    if (StringUtils.isNotEmpty(endUserToken)) {
        authContext.setCallerToken(endUserToken);
    }

    return authContext;
}
 
Example 9
Source File: GatewayUtils.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
private static void constructJWTContent(JSONObject subscribedAPI,
                                        APIKeyValidationInfoDTO apiKeyValidationInfoDTO, JWTInfoDto jwtInfoDto) {
    if (jwtInfoDto.getJwtValidationInfo() != null){
        jwtInfoDto.setEnduser(jwtInfoDto.getJwtValidationInfo().getUser());
    }
    if (apiKeyValidationInfoDTO != null) {
        jwtInfoDto.setApplicationid(apiKeyValidationInfoDTO.getApplicationId());
        jwtInfoDto.setApplicationname(apiKeyValidationInfoDTO.getApplicationName());
        jwtInfoDto.setApplicationtier(apiKeyValidationInfoDTO.getApplicationTier());
        jwtInfoDto.setKeytype(apiKeyValidationInfoDTO.getType());
        jwtInfoDto.setSubscriber(apiKeyValidationInfoDTO.getSubscriber());
        jwtInfoDto.setSubscriptionTier(apiKeyValidationInfoDTO.getTier());
        jwtInfoDto.setApiName(apiKeyValidationInfoDTO.getApiName());
        jwtInfoDto.setEndusertenantid(
                APIUtil.getTenantIdFromTenantDomain(apiKeyValidationInfoDTO.getSubscriberTenantDomain()));
    } else if (subscribedAPI != null) {
        // If the user is subscribed to the API
        String apiName = subscribedAPI.getAsString(APIConstants.JwtTokenConstants.API_NAME);
        jwtInfoDto.setApiName(apiName);
        String subscriptionTier = subscribedAPI.getAsString(APIConstants.JwtTokenConstants.SUBSCRIPTION_TIER);
        String subscriptionTenantDomain =
                subscribedAPI.getAsString(APIConstants.JwtTokenConstants.SUBSCRIBER_TENANT_DOMAIN);
        jwtInfoDto.setSubscriptionTier(subscriptionTier);
        jwtInfoDto.setEndusertenantid(APIUtil.getTenantIdFromTenantDomain(subscriptionTenantDomain));
        if (jwtInfoDto.getJwtValidationInfo() != null) {
            if (jwtInfoDto.getJwtValidationInfo().getClaims().get(APIConstants.JwtTokenConstants.APPLICATION) !=
                    null) {
                JSONObject applicationObj = (JSONObject) jwtInfoDto.getJwtValidationInfo().getClaims()
                        .get(APIConstants.JwtTokenConstants.APPLICATION);
                jwtInfoDto.setApplicationid(
                        String.valueOf(applicationObj.getAsNumber(APIConstants.JwtTokenConstants.APPLICATION_ID)));
                jwtInfoDto
                        .setApplicationname(
                                applicationObj.getAsString(APIConstants.JwtTokenConstants.APPLICATION_NAME));
                jwtInfoDto
                        .setApplicationtier(
                                applicationObj.getAsString(APIConstants.JwtTokenConstants.APPLICATION_TIER));
                jwtInfoDto.setSubscriber(
                        applicationObj.getAsString(APIConstants.JwtTokenConstants.APPLICATION_OWNER));
            }
        }
    }
}