Search in sources :

Example 91 with JSONObject

use of net.minidev.json.JSONObject in project ddf by codice.

the class GeoJsonQueryResponseTransformer method convertToJSON.

private JSONObject convertToJSON(Result result) throws CatalogTransformerException {
    JSONObject rootObject = new JSONObject();
    addNonNullObject(rootObject, "distance", result.getDistanceInMeters());
    addNonNullObject(rootObject, "relevance", result.getRelevanceScore());
    addNonNullObject(rootObject, "metacard", createGeoJSON(result.getMetacard()));
    return rootObject;
}
Also used : JSONObject(net.minidev.json.JSONObject)

Example 92 with JSONObject

use of net.minidev.json.JSONObject in project ddf by codice.

the class OAuthPluginTest method getRefreshTokenBuilder.

private JWTCreator.Builder getRefreshTokenBuilder() {
    String[] audience = { "master-realm", "account" };
    JSONObject realmAccess = new JSONObject();
    realmAccess.put("roles", ImmutableList.of("create-realm", "offline_access", "admin", "uma_authorization"));
    return JWT.create().withJWTId(UUID.randomUUID().toString()).withExpiresAt(new Date(Instant.now().plus(Duration.ofDays(3)).toEpochMilli())).withNotBefore(new Date(0)).withIssuedAt(new Date()).withIssuer("http://localhost:8080/auth/realms/master").withAudience("http://localhost:8080/auth/realms/master").withArrayClaim("aud", audience).withSubject("subject").withClaim("typ", "Refresh").withClaim(AZP, DDF_CLIENT).withClaim("auth_time", 0).withClaim("realm_access", realmAccess.toString()).withClaim("scope", "openid profile email");
}
Also used : JSONObject(net.minidev.json.JSONObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date)

Example 93 with JSONObject

use of net.minidev.json.JSONObject in project ddf by codice.

the class OAuthPluginTest method getResponse.

private InputStream getResponse(String accessToken) {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("access_token", accessToken);
    jsonObject.put("token_type", "bearer");
    jsonObject.put("refresh_token", getRefreshTokenBuilder().sign(validAlgorithm));
    jsonObject.put("expires_in", 60);
    jsonObject.put("scope", "openid profile email");
    return new ByteArrayInputStream(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8));
}
Also used : JSONObject(net.minidev.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 94 with JSONObject

use of net.minidev.json.JSONObject in project ddf by codice.

the class GeoCoderServiceImpl method doQuery.

JSONObject doQuery(String query) {
    GeoCoder geoCoder = geoCoderFactory.getService();
    GeoResult geoResult = null;
    if (geoCoder != null) {
        geoResult = geoCoder.getLocation(query);
    }
    JSONObject jsonObject = new JSONObject();
    JSONArray resourceSets = new JSONArray();
    JSONObject resourceSet = new JSONObject();
    jsonObject.put("resourceSets", resourceSets);
    resourceSets.add(resourceSet);
    JSONArray resources = new JSONArray();
    resourceSet.put("resources", resources);
    if (geoResult != null) {
        transformGeoResult(geoResult, resources);
    }
    return jsonObject;
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) GeoResult(org.codice.ddf.spatial.geocoder.GeoResult)

Example 95 with JSONObject

use of net.minidev.json.JSONObject in project ddf by codice.

the class GeoJsonQueryResponseTransformerTest method testGoodResponse.

@Test
public void testGoodResponse() throws CatalogTransformerException, IOException, ParseException {
    final int resultCount = 3;
    final int hitCount = 12;
    SourceResponse sourceResponse = setupResponse(resultCount, hitCount);
    JSONObject obj = transform(sourceResponse);
    verifyResponse(obj, resultCount, hitCount);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) JSONObject(net.minidev.json.JSONObject) Test(org.junit.Test)

Aggregations

JSONObject (net.minidev.json.JSONObject)257 JSONArray (net.minidev.json.JSONArray)51 Test (org.junit.Test)39 Test (org.testng.annotations.Test)38 JSONParser (net.minidev.json.parser.JSONParser)26 HashMap (java.util.HashMap)22 MockFlowFile (org.apache.nifi.util.MockFlowFile)16 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)14 ParseException (net.minidev.json.parser.ParseException)14 Test (org.junit.jupiter.api.Test)14 Map (java.util.Map)13 JSONConverterException (org.btrplace.json.JSONConverterException)13 SignedJWT (com.nimbusds.jwt.SignedJWT)12 Node (org.btrplace.model.Node)12 VM (org.btrplace.model.VM)12 JWSHeader (com.nimbusds.jose.JWSHeader)10 RSASSASigner (com.nimbusds.jose.crypto.RSASSASigner)10 ArrayList (java.util.ArrayList)10 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)10 OpenAPI (io.swagger.v3.oas.models.OpenAPI)9