Skip to content

Commit

Permalink
Merge pull request #95 from ankitmashu/fix/time_limit_removed
Browse files Browse the repository at this point in the history
Fix/time limit removed
  • Loading branch information
ankitmashu authored Jul 12, 2024
2 parents 01deb29 + 1b952e6 commit ccfead4
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 89 deletions.
6 changes: 4 additions & 2 deletions examples/configs/config-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"commonConfig": {
"dxApiBasePath": "/ngsi-ld/v1",
"dxCatalogueBasePath": "/iudx/cat/v1",
"dxAuthBasePath": "/auth/v1"
"dxAuthBasePath": "/auth/v1",
"isTimeLimitEnabled": false
},
"modules": [
{
Expand All @@ -27,7 +28,8 @@
"keystorePassword": "",
"audience": "",
"authServerHost": "",
"jwtIgnoreExpiry": true
"jwtIgnoreExpiry": true,
"jwtLeeWay": 90
},
{
"id": "iudx.rs.proxy.cache.CacheVerticle",
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/iudx/rs/proxy/apiserver/ApiServerVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ private void handleEntitiesQuery(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
MultiMap params = getQueryParams(routingContext, response).get();
MultiMap headerParams = request.headers();
boolean isTimeLimitEnabled = config().getBoolean(IS_TIME_LIMIT_ENABLED);
Future<Boolean> validationResult = validator.validate(params);
validationResult.onComplete(
validationHandler -> {
Expand All @@ -337,7 +338,7 @@ private void handleEntitiesQuery(RoutingContext routingContext) {
"Temporal parameters are not allowed in entities query.");
routingContext.fail(ex);
}
QueryMapper queryMapper = new QueryMapper(routingContext);
QueryMapper queryMapper = new QueryMapper(routingContext,isTimeLimitEnabled);
JsonObject json = queryMapper.toJson(ngsildQuery, false);
if (json.containsKey(ERROR)) {
return;
Expand Down Expand Up @@ -394,11 +395,12 @@ public void handleTemporalQuery(RoutingContext routingContext) {
String instanceId = request.getHeader(HEADER_HOST);
MultiMap params = getQueryParams(routingContext, response).get();
Future<Boolean> validationResult = validator.validate(params);
boolean isTimeLimitEnabled = config().getBoolean(IS_TIME_LIMIT_ENABLED);
validationResult.onComplete(
validationHandler -> {
if (validationHandler.succeeded()) {
NGSILDQueryParams ngsildquery = new NGSILDQueryParams(params);
QueryMapper queryMapper = new QueryMapper(routingContext);
QueryMapper queryMapper = new QueryMapper(routingContext, isTimeLimitEnabled);
JsonObject json = queryMapper.toJson(ngsildquery, true);
if (json.containsKey(ERROR)) {
LOGGER.error(json.getString(ERROR));
Expand Down Expand Up @@ -710,11 +712,12 @@ private void handlePostEntitiesQuery(RoutingContext routingContext) {
MultiMap headerParams = request.headers();
MultiMap params = getQueryParams(routingContext, response).get();
Future<Boolean> validationResult = validator.validate(requestJson);
boolean isTimeLimitEnabled = config().getBoolean(IS_TIME_LIMIT_ENABLED);
validationResult.onComplete(
validationHandler -> {
if (validationHandler.succeeded()) {
NGSILDQueryParams ngsildquery = new NGSILDQueryParams(requestJson);
QueryMapper queryMapper = new QueryMapper(routingContext);
QueryMapper queryMapper = new QueryMapper(routingContext, isTimeLimitEnabled);
JsonObject json = queryMapper.toJson(ngsildquery, requestJson.containsKey("temporalQ"));
if (json.containsKey(ERROR)) {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/iudx/rs/proxy/apiserver/AsyncRestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class AsyncRestApi {
private final MeteringService meteringService;
private final ConsentLoggingService consentLoggingService;
private final ParamsValidator validator;
boolean isTimeLimitEnabled;
private CacheService cacheService;
private boolean isAdexInstance;
private Api api;
Expand All @@ -73,6 +74,7 @@ public class AsyncRestApi {
this.validator = new ParamsValidator(cacheService);
this.api = api;
isAdexInstance = config.getBoolean("isAdexInstance");
this.isTimeLimitEnabled = config.getBoolean(IS_TIME_LIMIT_ENABLED);
}

Router init() {
Expand Down Expand Up @@ -174,7 +176,7 @@ private void handleAsyncSearchRequest(RoutingContext routingContext) {
validationHandler -> {
if (validationHandler.succeeded()) {
NGSILDQueryParams ngsildquery = new NGSILDQueryParams(params);
QueryMapper queryMapper = new QueryMapper(routingContext);
QueryMapper queryMapper = new QueryMapper(routingContext, isTimeLimitEnabled);
JsonObject json = queryMapper.toJson(ngsildquery, true, true);
if (json.containsKey(ERROR)) {
LOGGER.error(json.getString(ERROR));
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/iudx/rs/proxy/apiserver/query/QueryMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
public class QueryMapper {

private static final Logger LOGGER = LogManager.getLogger(QueryMapper.class);
private final boolean isTimeLimitEnabled;
private boolean isTemporal = false;
private boolean isAttributeSearch = false;
private boolean isGeoSearch = false;
private RoutingContext context;

public QueryMapper(RoutingContext context) {
public QueryMapper(RoutingContext context, boolean isTimeLimitEnabled) {
this.context = context;
this.isTimeLimitEnabled = isTimeLimitEnabled;
}

public JsonObject toJson(NGSILDQueryParams params, boolean isTemporal) {
Expand Down Expand Up @@ -92,7 +94,7 @@ public JsonObject toJson(NGSILDQueryParams params, boolean isTemporal, boolean i
}
LOGGER.debug("Info : json " + geoJson);
} else {
json.put(ERROR,INVALID_GEO_PARAM_URN);
json.put(ERROR, INVALID_GEO_PARAM_URN);
DxRuntimeException ex =
new DxRuntimeException(
BAD_REQUEST.getValue(),
Expand Down Expand Up @@ -198,7 +200,11 @@ private boolean isValidTimeInterval(
} else if (timeRel.equalsIgnoreCase("before")) {

}
if (!isAsyncQuery && totalDaysAllowed > VALIDATION_MAX_DAYS_INTERVAL_ALLOWED) {
LOGGER.debug("isTimeLimitEnabled : {}", isTimeLimitEnabled);

if (isTimeLimitEnabled
&& !isAsyncQuery
&& totalDaysAllowed > VALIDATION_MAX_DAYS_INTERVAL_ALLOWED) {
isValid = false;
DxRuntimeException ex =
new DxRuntimeException(
Expand All @@ -207,15 +213,17 @@ private boolean isValidTimeInterval(
"time interval greater than 10 days is not allowed");
this.context.fail(400, ex);
}
if (isAsyncQuery && totalDaysAllowed > VALIDATION_MAX_DAYS_INTERVAL_ALLOWED_FOR_ASYNC) {

if (isTimeLimitEnabled
&& isAsyncQuery
&& totalDaysAllowed > VALIDATION_MAX_DAYS_INTERVAL_ALLOWED_FOR_ASYNC) {
isValid = false;
DxRuntimeException ex =
new DxRuntimeException(
BAD_REQUEST.getValue(),
INVALID_TEMPORAL_PARAM_URN,
"time interval greater than 365 days is not allowed");
context.fail(400, ex);

}
return isValid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public class ApiServerConstants {
public static final String ITEM_TYPE_RESOURCE_SERVER = "ResourceServer";
public static final String ITEM_TYPE_PROVIDER = "Provider";
public static final String MIME_APPLICATION_JSON = "application/json";

public static final String IS_TIME_LIMIT_ENABLED = "isTimeLimitEnabled";
public static final ArrayList<String> ITEM_TYPES =
new ArrayList<String>(
Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package iudx.rs.proxy.authenticator;

import static iudx.rs.proxy.authenticator.Constants.AUTH_CERTIFICATE_PATH;
import static iudx.rs.proxy.authenticator.Constants.LEE_WAY;
import static iudx.rs.proxy.common.Constants.*;

import io.vertx.core.AbstractVerticle;
Expand Down Expand Up @@ -72,7 +73,10 @@ public void start() throws Exception {
binder = new ServiceBinder(vertx);

JWTAuthOptions jwtAuthOptions = new JWTAuthOptions();
jwtAuthOptions.getJWTOptions().addAudience(config().getString("audience"));
jwtAuthOptions
.getJWTOptions()
.addAudience(config().getString("audience"))
.setLeeway(config().getInteger(LEE_WAY));
jwtAuthOptions.addPubSecKey(
new PubSecKeyOptions().setAlgorithm("ES256").setBuffer(cert));
/*
Expand All @@ -82,7 +86,10 @@ public void start() throws Exception {
config().getBoolean("jwtIgnoreExpiry") != null
&& config().getBoolean("jwtIgnoreExpiry");
if (jwtIgnoreExpiry) {
jwtAuthOptions.getJWTOptions().setIgnoreExpiration(true);
jwtAuthOptions
.getJWTOptions()
.setIgnoreExpiration(true)
.setLeeway(config().getInteger(LEE_WAY));
LOGGER.warn(
"JWT ignore expiration set to true, do not set IgnoreExpiration in production!!");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/iudx/rs/proxy/authenticator/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Constants {
"/entityOperations/query",
"/async/search",
"/async/status");
public static final long CACHE_TIMEOUT_AMOUNT = 30;
public static final String LEE_WAY = "jwtLeeWay";
public static final String CAT_SEARCH_PATH = "/search";
public static final String AUTH_CERTIFICATE_PATH = "/cert";
public static final String CAT_ITEM_PATH = "/item";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class QueryMapperTest {
private QueryMapper qm;
@Mock
RoutingContext context;
boolean isTimeLimitEnabled = true;

@BeforeEach
public void setup(Vertx vertx, VertxTestContext testContext) {
qm = new QueryMapper(context);
qm = new QueryMapper(context, isTimeLimitEnabled);
testContext.completeNow();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"info": {
"_postman_id": "a4127943-5452-4aea-a843-701ffd05d29b",
"_postman_id": "cb5954ea-4364-45be-89c2-851354c0d5b7",
"name": "TEST-SERVER-ADEXX-RS-PROXY-APIs Final NEW",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "20457128"
},
"item": [
{
Expand Down Expand Up @@ -13072,78 +13073,6 @@
},
"response": []
},
{
"name": "400 (Bad request) invalid interval",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// Test the response code\r",
"pm.test(\"response is 400 (Bad request)\", function () {\r",
" pm.response.to.have.status(400);\r",
"});\r",
"\r",
"// Test the response header\r",
"pm.test(\"Check response header\", function () {\r",
" pm.response.to.have.header(\"Content-Type\",\"application/json\");\r",
"});\r",
"\r",
"// Test the response\r",
"pm.test(\"Check response body\", function () { \r",
" const body = pm.response.json();\r",
" pm.expect(body).to.have.property(\"title\", \"Bad Request\");\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "token",
"value": "{{personalResourceToken_pune}}",
"type": "text"
}
],
"url": {
"raw": "{{base_url}}/{{basePath}}/temporal/entities?id=b58da193-23d9-43eb-b98a-a103d4b6103c&timerel=during&time=2020-09-01T14:20:00Z&endtime=2020-09-19T14:20:00Z&q=Ppbno=={{ppbNumber}}",
"host": [
"{{base_url}}"
],
"path": [
"{{basePath}}",
"temporal",
"entities"
],
"query": [
{
"key": "id",
"value": "b58da193-23d9-43eb-b98a-a103d4b6103c"
},
{
"key": "timerel",
"value": "during"
},
{
"key": "time",
"value": "2020-09-01T14:20:00Z"
},
{
"key": "endtime",
"value": "2020-09-19T14:20:00Z"
},
{
"key": "q",
"value": "Ppbno=={{ppbNumber}}"
}
]
}
},
"response": []
},
{
"name": "400 (Bad request) invalid operator in <q> query",
"event": [
Expand Down

0 comments on commit ccfead4

Please sign in to comment.