Skip to content

Commit 719ec06

Browse files
committed
Merge branch 'master' of github.com:networknt/light-rest-4j
2 parents 77e8895 + b318ad2 commit 719ec06

File tree

21 files changed

+379
-13
lines changed

21 files changed

+379
-13
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change Log
22

3+
## [2.2.1](https://github.com/networknt/light-rest-4j/tree/2.2.1) (2025-03-22)
4+
5+
6+
**Merged pull requests:**
7+
8+
9+
- Added generated json-schema and yaml annotations to REST configs. [\#412](https://github.com/networknt/light-rest-4j/pull/412) ([KalevGonvick](https://github.com/KalevGonvick))
10+
11+
312
## [2.2.0](https://github.com/networknt/light-rest-4j/tree/2.2.0) (2025-02-12)
413

514

access-control/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.networknt</groupId>
2323
<artifactId>light-rest-4j</artifactId>
24-
<version>2.2.1-SNAPSHOT</version>
24+
<version>2.2.1</version>
2525
<relativePath>../pom.xml</relativePath>
2626
</parent>
2727

access-control/src/main/java/com/networknt/openapi/AccessControlConfig.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fasterxml.jackson.core.type.TypeReference;
1919
import com.networknt.config.Config;
2020
import com.networknt.config.ConfigException;
21+
import com.networknt.config.schema.*;
2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
2324

@@ -26,6 +27,13 @@
2627
import java.util.List;
2728
import java.util.Map;
2829

30+
@ConfigSchema(
31+
configName = "access-control",
32+
configKey = "access-control",
33+
configDescription = "AccessControlHandler will be the last middleware handler before the proxy on the sidecar or the last\n" +
34+
"one before the business handler to handle the fine-grained authorization in the business domain.",
35+
outputFormats = {OutputFormat.JSON_SCHEMA, OutputFormat.YAML}
36+
)
2937
class AccessControlConfig {
3038
private static final Logger logger = LoggerFactory.getLogger(AccessControlConfig.class);
3139
public static final String CONFIG_NAME = "access-control";
@@ -37,11 +45,48 @@ class AccessControlConfig {
3745
private Map<String, Object> mappedConfig;
3846
private final Config config;
3947

48+
@BooleanField(
49+
configFieldName = ENABLED,
50+
externalizedKeyName = ENABLED,
51+
externalized = true,
52+
defaultValue = true,
53+
description = "Enable Access Control Handler"
54+
)
4055
boolean enabled;
56+
57+
@StringField(
58+
configFieldName = ACCESS_RULE_LOGIC,
59+
externalizedKeyName = ACCESS_RULE_LOGIC,
60+
externalized = true,
61+
defaultValue = "any",
62+
description = "If there are multiple rules, the logic to combine them can be any or all. The default is any, and it\n" +
63+
"means that any rule is satisfied, the access is granted. If all is set, all rules must be satisfied."
64+
)
4165
String accessRuleLogic;
66+
67+
@BooleanField(
68+
configFieldName = DEFAULT_DENY,
69+
externalizedKeyName = DEFAULT_DENY,
70+
externalized = true,
71+
defaultValue = true,
72+
description = "If there is no access rule defined for the endpoint, default access is denied. Users can overwrite\n" +
73+
"this default action by setting this config value to false. If true, the handle will force users to\n" +
74+
"define the rules for each endpoint when the access control handler is enabled."
75+
)
4276
boolean defaultDeny;
43-
private List<String> skipPathPrefixes;
4477

78+
@ArrayField(
79+
configFieldName = SKIP_PATH_PREFIXES,
80+
externalizedKeyName = SKIP_PATH_PREFIXES,
81+
externalized = true,
82+
description = "Define a list of path prefixes to skip the access-control to ease the configuration for the handler.yml\n" +
83+
"so that users can define some endpoint without fine-grained access-control security even through it uses\n" +
84+
"the default chain. This is useful if some endpoints want to skip the fine-grained access control in the\n" +
85+
"application. The format is a list of strings separated with commas or a JSON list in values.yml definition\n" +
86+
"from config server, or you can use yaml format in externalized access-control.yml file.",
87+
items = String.class
88+
)
89+
private List<String> skipPathPrefixes;
4590

4691
private AccessControlConfig() {
4792
this(CONFIG_NAME);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema" : "http://json-schema.org/draft-07/schema#",
3+
"type" : "object",
4+
"required" : [ "enabled", "accessRuleLogic", "defaultDeny", "skipPathPrefixes" ],
5+
"properties" : {
6+
"enabled" : {
7+
"type" : "boolean",
8+
"description" : "Enable Access Control Handler",
9+
"default" : true
10+
},
11+
"accessRuleLogic" : {
12+
"type" : "string",
13+
"description" : "If there are multiple rules, the logic to combine them can be any or all. The default is any, and it\nmeans that any rule is satisfied, the access is granted. If all is set, all rules must be satisfied.",
14+
"default" : "any"
15+
},
16+
"defaultDeny" : {
17+
"type" : "boolean",
18+
"description" : "If there is no access rule defined for the endpoint, default access is denied. Users can overwrite\nthis default action by setting this config value to false. If true, the handle will force users to\ndefine the rules for each endpoint when the access control handler is enabled.",
19+
"default" : true
20+
},
21+
"skipPathPrefixes" : {
22+
"type" : "array",
23+
"description" : "Define a list of path prefixes to skip the access-control to ease the configuration for the handler.yml\nso that users can define some endpoint without fine-grained access-control security even through it uses\nthe default chain. This is useful if some endpoints want to skip the fine-grained access control in the\napplication. The format is a list of strings separated with commas or a JSON list in values.yml definition\nfrom config server, or you can use yaml format in externalized access-control.yml file.",
24+
"items" : {
25+
"type" : "string"
26+
}
27+
}
28+
}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# AccessControlHandler will be the last middleware handler before the proxy on the sidecar or the last
2+
# one before the business handler to handle the fine-grained authorization in the business domain.
3+
# Enable Access Control Handler
4+
enabled: ${access-control.enabled:true}
5+
# If there are multiple rules, the logic to combine them can be any or all. The default is any, and it
6+
# means that any rule is satisfied, the access is granted. If all is set, all rules must be satisfied.
7+
accessRuleLogic: ${access-control.accessRuleLogic:any}
8+
# If there is no access rule defined for the endpoint, default access is denied. Users can overwrite
9+
# this default action by setting this config value to false. If true, the handle will force users to
10+
# define the rules for each endpoint when the access control handler is enabled.
11+
defaultDeny: ${access-control.defaultDeny:true}
12+
# Define a list of path prefixes to skip the access-control to ease the configuration for the handler.yml
13+
# so that users can define some endpoint without fine-grained access-control security even through it uses
14+
# the default chain. This is useful if some endpoints want to skip the fine-grained access control in the
15+
# application. The format is a list of strings separated with commas or a JSON list in values.yml definition
16+
# from config server, or you can use yaml format in externalized access-control.yml file.
17+
skipPathPrefixes: ${access-control.skipPathPrefixes:}

openapi-config/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.networknt</groupId>
2323
<artifactId>light-rest-4j</artifactId>
24-
<version>2.2.1-SNAPSHOT</version>
24+
<version>2.2.1</version>
2525
<relativePath>../pom.xml</relativePath>
2626
</parent>
2727

openapi-config/src/main/java/com/networknt/openapi/OpenApiHandlerConfig.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,63 @@
33
import com.networknt.config.Config;
44
import com.networknt.config.ConfigException;
55
import com.networknt.config.JsonMapper;
6+
import com.networknt.config.schema.BooleanField;
7+
import com.networknt.config.schema.ConfigSchema;
8+
import com.networknt.config.schema.MapField;
9+
import com.networknt.config.schema.OutputFormat;
610
import org.slf4j.Logger;
711
import org.slf4j.LoggerFactory;
812

913
import java.util.*;
1014

15+
@ConfigSchema(
16+
configName = "openapi-handler",
17+
configKey = "openapi-handler",
18+
configDescription = "openapi-handler.yml",
19+
outputFormats = {OutputFormat.JSON_SCHEMA, OutputFormat.YAML}
20+
)
1121
public class OpenApiHandlerConfig {
1222
private static final Logger logger = LoggerFactory.getLogger(OpenApiHandlerConfig.class);
1323
public static final String CONFIG_NAME = "openapi-handler";
1424
private static final String MULTIPLE_SPEC = "multipleSpec";
1525
private static final String IGNORE_INVALID_PATH = "ignoreInvalidPath";
1626
private static final String PATH_SPEC_MAPPING = "pathSpecMapping";
1727

28+
@BooleanField(
29+
configFieldName = MULTIPLE_SPEC,
30+
externalizedKeyName = MULTIPLE_SPEC,
31+
externalized = true,
32+
description = "This configuration file is used to support multiple OpenAPI " +
33+
"specifications in the same light-rest-4j instance.\n" +
34+
"An indicator to allow multiple openapi specifications. " +
35+
"Default to false which only allow one spec named openapi.yml or openapi.yaml or openapi.json."
36+
)
1837
boolean multipleSpec;
38+
39+
@BooleanField(
40+
configFieldName = IGNORE_INVALID_PATH,
41+
externalizedKeyName = IGNORE_INVALID_PATH,
42+
externalized = true,
43+
description = "When the OpenApiHandler is used in a shared gateway and some backend APIs have no " +
44+
"specifications deployed on the gateway, the handler will return\n" +
45+
"an invalid request path error to the client. " +
46+
"To allow the call to pass through the OpenApiHandler and route to the backend APIs, you can set this\n" +
47+
"flag to true. In this mode, the handler will only add the endpoint " +
48+
"specification to the auditInfo if it can find it. " +
49+
"Otherwise, it will pass through."
50+
)
1951
boolean ignoreInvalidPath;
52+
53+
@MapField(
54+
configFieldName = PATH_SPEC_MAPPING,
55+
externalizedKeyName = PATH_SPEC_MAPPING,
56+
externalized = true,
57+
description = "Path to spec mapping. One or more base paths can map to the same specifications. " +
58+
"The key is the base path and the value is the specification name.\n" +
59+
"If users want to use multiple specification files in the same instance, " +
60+
"each specification must have a unique base path and it must be set as key.",
61+
valueType = String.class
62+
)
2063
Map<String, Object> pathSpecMapping;
2164

2265
private final Config config;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema" : "http://json-schema.org/draft-07/schema#",
3+
"type" : "object",
4+
"required" : [ "multipleSpec", "ignoreInvalidPath", "pathSpecMapping" ],
5+
"properties" : {
6+
"multipleSpec" : {
7+
"type" : "boolean",
8+
"description" : "This configuration file is used to support multiple OpenAPI specifications in the same light-rest-4j instance.\nAn indicator to allow multiple openapi specifications. Default to false which only allow one spec named openapi.yml or openapi.yaml or openapi.json."
9+
},
10+
"ignoreInvalidPath" : {
11+
"type" : "boolean",
12+
"description" : "When the OpenApiHandler is used in a shared gateway and some backend APIs have no specifications deployed on the gateway, the handler will return\nan invalid request path error to the client. To allow the call to pass through the OpenApiHandler and route to the backend APIs, you can set this\nflag to true. In this mode, the handler will only add the endpoint specification to the auditInfo if it can find it. Otherwise, it will pass through."
13+
},
14+
"pathSpecMapping" : {
15+
"type" : "object",
16+
"description" : "Path to spec mapping. One or more base paths can map to the same specifications. The key is the base path and the value is the specification name.\nIf users want to use multiple specification files in the same instance, each specification must have a unique base path and it must be set as key.",
17+
"additionalProperties" : {
18+
"type" : "string"
19+
}
20+
}
21+
}
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# openapi-handler.yml
2+
# This configuration file is used to support multiple OpenAPI specifications in the same light-rest-4j instance.
3+
# An indicator to allow multiple openapi specifications. Default to false which only allow one spec named openapi.yml or openapi.yaml or openapi.json.
4+
multipleSpec: ${openapi-handler.multipleSpec:false}
5+
# When the OpenApiHandler is used in a shared gateway and some backend APIs have no specifications deployed on the gateway, the handler will return
6+
# an invalid request path error to the client. To allow the call to pass through the OpenApiHandler and route to the backend APIs, you can set this
7+
# flag to true. In this mode, the handler will only add the endpoint specification to the auditInfo if it can find it. Otherwise, it will pass through.
8+
ignoreInvalidPath: ${openapi-handler.ignoreInvalidPath:false}
9+
# Path to spec mapping. One or more base paths can map to the same specifications. The key is the base path and the value is the specification name.
10+
# If users want to use multiple specification files in the same instance, each specification must have a unique base path and it must be set as key.
11+
pathSpecMapping: ${openapi-handler.pathSpecMapping:}

openapi-meta/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.networknt</groupId>
2323
<artifactId>light-rest-4j</artifactId>
24-
<version>2.2.1-SNAPSHOT</version>
24+
<version>2.2.1</version>
2525
<relativePath>../pom.xml</relativePath>
2626
</parent>
2727

0 commit comments

Comments
 (0)