Skip to content

Commit 09c9a4e

Browse files
committed
Merge branch 'master' of github.com:networknt/light-4j
2 parents f351736 + 4b06195 commit 09c9a4e

File tree

198 files changed

+1440
-1235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+1440
-1235
lines changed

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Change Log
22

3+
## [2.2.1](https://github.com/networknt/light-4j/tree/2.2.1) (2025-03-22)
4+
5+
6+
**Merged pull requests:**
7+
8+
9+
- JSON Schema & YAML Config Generation Enhancement [\#2482](https://github.com/networknt/light-4j/pull/2482) ([KalevGonvick](https://github.com/KalevGonvick))
10+
- fixes \#2478 update dependency of mysql [\#2479](https://github.com/networknt/light-4j/pull/2479) ([stevehu](https://github.com/stevehu))
11+
- fixes \#2476 update email dependency from javax to jakarta [\#2477](https://github.com/networknt/light-4j/pull/2477) ([stevehu](https://github.com/stevehu))
12+
- Sync [\#2475](https://github.com/networknt/light-4j/pull/2475) ([stevehu](https://github.com/stevehu))
13+
- 2473 remaining config conversion [\#2474](https://github.com/networknt/light-4j/pull/2474) ([KalevGonvick](https://github.com/KalevGonvick))
14+
- 2469 client config module refactor [\#2472](https://github.com/networknt/light-4j/pull/2472) ([KalevGonvick](https://github.com/KalevGonvick))
15+
- 2467 multi module schema generation [\#2468](https://github.com/networknt/light-4j/pull/2468) ([KalevGonvick](https://github.com/KalevGonvick))
16+
- 2463 add configuration schema generation to basic config [\#2466](https://github.com/networknt/light-4j/pull/2466) ([KalevGonvick](https://github.com/KalevGonvick))
17+
- 2459 mirroredtypeexceptions occur when using config generator annotations [\#2465](https://github.com/networknt/light-4j/pull/2465) ([stevehu](https://github.com/stevehu))
18+
- 2459 mirroredtypeexceptions occur when using config generator annotations [\#2461](https://github.com/networknt/light-4j/pull/2461) ([stevehu](https://github.com/stevehu))
19+
- MirroredTypeException Fix [\#2460](https://github.com/networknt/light-4j/pull/2460) ([KalevGonvick](https://github.com/KalevGonvick))
20+
- 2452 create config file generator so configurations are always in sync with the pojo [\#2458](https://github.com/networknt/light-4j/pull/2458) ([stevehu](https://github.com/stevehu))
21+
- Added metrics attachment for handler execution. [\#2454](https://github.com/networknt/light-4j/pull/2454) ([KalevGonvick](https://github.com/KalevGonvick))
22+
23+
324
## [2.2.0](https://github.com/networknt/light-4j/tree/2.2.0) (2025-02-12)
425

526

api-key/pom.xml

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

apikey-config/pom.xml

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

apikey-config/src/main/java/com/networknt/apikey/ApiKeyConfig.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
import java.util.List;
1515
import java.util.Map;
1616

17-
@ConfigSchema(configKey = "apikey", configName = "apikey", outputFormats = { OutputFormat.JSON_SCHEMA, OutputFormat.YAML })
17+
@ConfigSchema(
18+
configKey = "apikey",
19+
configName = "apikey",
20+
configDescription = "ApiKey Authentication Security Configuration for light-4j",
21+
outputFormats = {
22+
OutputFormat.JSON_SCHEMA,
23+
OutputFormat.YAML
24+
}
25+
)
1826
public class ApiKeyConfig {
1927
private static final Logger logger = LoggerFactory.getLogger(ApiKeyConfig.class);
2028

@@ -30,7 +38,8 @@ public class ApiKeyConfig {
3038
configFieldName = ENABLED,
3139
externalizedKeyName = ENABLED,
3240
externalized = true,
33-
description = "Enable or disable the api key filter."
41+
defaultValue = true,
42+
description = "Enable ApiKey Authentication Handler, default is false."
3443
)
3544
boolean enabled;
3645

@@ -49,7 +58,12 @@ public class ApiKeyConfig {
4958
configFieldName = PATH_PREFIX_AUTHS,
5059
externalizedKeyName = PATH_PREFIX_AUTHS,
5160
externalized = true,
52-
items = ApiKey.class
61+
items = ApiKey.class,
62+
description = "path prefix to the api key mapping. It is a list of map between the path prefix and the api key\n" +
63+
"for apikey authentication. In the handler, it loops through the list and find the matching path\n" +
64+
"prefix. Once found, it will check if the apikey is equal to allow the access or return an error.\n" +
65+
"The map object has three properties: pathPrefix, headerName and apiKey. Take a look at the test\n" +
66+
"resources/config folder for configuration examples.\n"
5367
)
5468
List<ApiKey> pathPrefixAuths;
5569

apikey-config/src/main/resources/config/apikey.json renamed to apikey-config/src/main/resources/config/apikey-schema.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
"properties" : {
66
"enabled" : {
77
"type" : "boolean",
8-
"description" : "Enable or disable the api key filter."
8+
"description" : "Enable ApiKey Authentication Handler, default is false.",
9+
"default" : true
910
},
1011
"hashEnabled" : {
1112
"type" : "boolean",
1213
"description" : "If API key hash is enabled. The API key will be hashed with PBKDF2WithHmacSHA1 before it is\nstored in the config file. It is more secure than put the encrypted key into the config file.\nThe default value is false. If you want to enable it, you need to use the following repo\nhttps://github.com/networknt/light-hash command line tool to hash the clear text key."
1314
},
1415
"pathPrefixAuths" : {
1516
"type" : "array",
17+
"description" : "path prefix to the api key mapping. It is a list of map between the path prefix and the api key\nfor apikey authentication. In the handler, it loops through the list and find the matching path\nprefix. Once found, it will check if the apikey is equal to allow the access or return an error.\nThe map object has three properties: pathPrefix, headerName and apiKey. Take a look at the test\nresources/config folder for configuration examples.\n",
1618
"items" : {
1719
"type" : "object",
1820
"properties" : {
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
#Enable or disable the api key filter.
2-
enabled: ${apikey.enabled:false}
3-
#If API key hash is enabled. The API key will be hashed with PBKDF2WithHmacSHA1 before it is
4-
#stored in the config file. It is more secure than put the encrypted key into the config file.
5-
#The default value is false. If you want to enable it, you need to use the following repo
6-
#https://github.com/networknt/light-hash command line tool to hash the clear text key.
1+
# ApiKey Authentication Security Configuration for light-4j
2+
# Enable ApiKey Authentication Handler, default is false.
3+
enabled: ${apikey.enabled:true}
4+
# If API key hash is enabled. The API key will be hashed with PBKDF2WithHmacSHA1 before it is
5+
# stored in the config file. It is more secure than put the encrypted key into the config file.
6+
# The default value is false. If you want to enable it, you need to use the following repo
7+
# https://github.com/networknt/light-hash command line tool to hash the clear text key.
78
hashEnabled: ${apikey.hashEnabled:false}
9+
# path prefix to the api key mapping. It is a list of map between the path prefix and the api key
10+
# for apikey authentication. In the handler, it loops through the list and find the matching path
11+
# prefix. Once found, it will check if the apikey is equal to allow the access or return an error.
12+
# The map object has three properties: pathPrefix, headerName and apiKey. Take a look at the test
13+
# resources/config folder for configuration examples.
814
pathPrefixAuths: ${apikey.pathPrefixAuths:}

audit-config/pom.xml

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

audit-config/src/main/java/com/networknt/audit/AuditConfig.java

+66-43
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@
3333
*
3434
* @author Steve Hu
3535
*/
36-
@ConfigSchema(configKey = "audit", configName = "audit", outputFormats = {OutputFormat.JSON_SCHEMA, OutputFormat.YAML})
36+
@ConfigSchema(
37+
configKey = "audit",
38+
configName = "audit",
39+
configDescription = "AuditHandler will pick some important fields from headers and tokens and logs into an audit appender\n" +
40+
"defined in the logback.xml configuration file.",
41+
outputFormats = {OutputFormat.JSON_SCHEMA, OutputFormat.YAML}
42+
)
3743
public class AuditConfig {
3844
private static final Logger logger = LoggerFactory.getLogger(AuditConfig.class);
3945

@@ -55,31 +61,23 @@ public class AuditConfig {
5561
private Map<String, Object> mappedConfig;
5662
public static final String CONFIG_NAME = "audit";
5763

58-
@ArrayField(
59-
configFieldName = HEADERS,
60-
externalizedKeyName = HEADERS,
61-
description = "Output header elements. You can add more if you want. If multiple values, you can use a comma separated\n" +
62-
"string as default value in the template and values.yml. You can also use a list of strings in YAML format.",
64+
@BooleanField(
65+
configFieldName = ENABLED,
66+
externalizedKeyName = ENABLED,
67+
description = "Enable Audit Logging",
6368
externalized = true,
64-
items = String.class,
65-
defaultValue = "[\"X-Correlation-Id\", \"X-Traceability-Id\",\"caller_id\"]"
69+
defaultValue = true
6670
)
67-
private List<String> headerList;
71+
private boolean enabled;
6872

69-
@ArrayField(
70-
configFieldName = AUDIT,
71-
externalizedKeyName = AUDIT,
72-
description = "Output audit elements. You can add more if you want. If multiple values, you can use a comma separated\n" +
73-
"string as default value in the template and values.yml. You can also use a list of strings in YAML format.",
73+
@BooleanField(
74+
configFieldName = MASK,
75+
externalizedKeyName = MASK,
76+
description = "Enable mask in the audit log",
7477
externalized = true,
75-
items = String.class,
76-
defaultValue = "[\"client_id\", \"user_id\", \"scope_client_id\", \"endpoint\", \"serviceId\"]"
78+
defaultValue = true
7779
)
78-
private List<String> auditList;
79-
80-
private final Config config;
81-
// A customized logger appender defined in default logback.xml
82-
private Consumer<String> auditFunc;
80+
private boolean mask;
8381

8482
@BooleanField(
8583
configFieldName = STATUS_CODE,
@@ -99,6 +97,10 @@ public class AuditConfig {
9997
)
10098
private boolean responseTime;
10199

100+
private final Config config;
101+
// A customized logger appender defined in default logback.xml
102+
private Consumer<String> auditFunc;
103+
102104
@BooleanField(
103105
configFieldName = AUDIT_ON_ERROR,
104106
externalizedKeyName = AUDIT_ON_ERROR,
@@ -111,15 +113,6 @@ public class AuditConfig {
111113
)
112114
private boolean auditOnError;
113115

114-
@BooleanField(
115-
configFieldName = MASK,
116-
externalizedKeyName = MASK,
117-
description = "Enable mask in the audit log",
118-
externalized = true,
119-
defaultValue = true
120-
)
121-
private boolean mask;
122-
123116
@StringField(
124117
configFieldName = TIMESTAMP_FORMAT,
125118
externalizedKeyName = TIMESTAMP_FORMAT,
@@ -129,6 +122,48 @@ public class AuditConfig {
129122
)
130123
private String timestampFormat;
131124

125+
@ArrayField(
126+
configFieldName = HEADERS,
127+
externalizedKeyName = HEADERS,
128+
description = "Output header elements. You can add more if you want. If multiple values, you can use a comma separated\n" +
129+
"string as default value in the template and values.yml. You can also use a list of strings in YAML format.\n" +
130+
"Correlation Id\n" +
131+
"- X-Correlation-Id\n" +
132+
"Traceability Id\n" +
133+
"- X-Traceability-Id\n" +
134+
"caller id for metrics\n" +
135+
"- caller_id\n",
136+
externalized = true,
137+
items = String.class,
138+
defaultValue = "[\"X-Correlation-Id\", \"X-Traceability-Id\",\"caller_id\"]"
139+
)
140+
private List<String> headerList;
141+
142+
@ArrayField(
143+
configFieldName = AUDIT,
144+
externalizedKeyName = AUDIT,
145+
description = "Output audit elements. You can add more if you want. If multiple values, you can use a comma separated\n" +
146+
"string as default value in the template and values.yml. You can also use a list of strings in YAML format.\n" +
147+
"Client Id\n" +
148+
"- client_id\n" +
149+
"User Id in id token, this is optional\n" +
150+
"- user_id\n" +
151+
"Client Id in scope/access token, this is optional\n" +
152+
"- scope_client_id\n" +
153+
"Request endpoint uri@method.\n" +
154+
"- endpoint\n" +
155+
"Service ID assigned to the service, this is optional and must be set by the service in its implementation\n" +
156+
"- serviceId\n" +
157+
"Request Body, this is optional and must be set by the service in its implementation\n" +
158+
"- requestBody\n" +
159+
"Response payload, this is optional and must be set by the service in its implementation\n" +
160+
"- responseBody\n",
161+
externalized = true,
162+
items = String.class,
163+
defaultValue = "[\"client_id\", \"user_id\", \"scope_client_id\", \"endpoint\", \"serviceId\"]"
164+
)
165+
private List<String> auditList;
166+
132167
@IntegerField(
133168
configFieldName = REQUEST_BODY_MAX_SIZE,
134169
externalizedKeyName = REQUEST_BODY_MAX_SIZE,
@@ -149,14 +184,6 @@ public class AuditConfig {
149184
)
150185
private int responseBodyMaxSize;
151186

152-
@BooleanField(
153-
configFieldName = ENABLED,
154-
externalizedKeyName = ENABLED,
155-
description = "Enable Audit Logging",
156-
externalized = true,
157-
defaultValue = true
158-
)
159-
private boolean enabled;
160187

161188
private AuditConfig() {
162189
this(CONFIG_NAME);
@@ -248,11 +275,7 @@ Config getConfig() {
248275
}
249276

250277
private void setLogLevel() {
251-
Object object = getMappedConfig().get(LOG_LEVEL_IS_ERROR);
252-
if (object != null) {
253-
auditOnError = Config.loadBooleanValue(LOG_LEVEL_IS_ERROR, object);
254-
auditFunc = auditOnError ? LoggerFactory.getLogger(Constants.AUDIT_LOGGER)::error : LoggerFactory.getLogger(Constants.AUDIT_LOGGER)::info;
255-
}
278+
auditFunc = auditOnError ? LoggerFactory.getLogger(Constants.AUDIT_LOGGER)::error : LoggerFactory.getLogger(Constants.AUDIT_LOGGER)::info;
256279
}
257280

258281
private void setLists() {
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
{
22
"$schema" : "http://json-schema.org/draft-07/schema#",
33
"type" : "object",
4-
"required" : [ "headers", "audit", "statusCode", "responseTime", "auditOnError", "mask", "timestampFormat", "requestBodyMaxSize", "responseBodyMaxSize", "enabled" ],
4+
"required" : [ "enabled", "mask", "statusCode", "responseTime", "auditOnError", "timestampFormat", "headers", "audit", "requestBodyMaxSize", "responseBodyMaxSize" ],
55
"properties" : {
6-
"headers" : {
7-
"type" : "array",
8-
"description" : "Output header elements. You can add more if you want. If multiple values, you can use a comma separated\nstring as default value in the template and values.yml. You can also use a list of strings in YAML format.",
9-
"default" : [ "X-Correlation-Id", "X-Traceability-Id", "caller_id" ],
10-
"items" : {
11-
"type" : "string"
12-
}
6+
"enabled" : {
7+
"type" : "boolean",
8+
"description" : "Enable Audit Logging",
9+
"default" : true
1310
},
14-
"audit" : {
15-
"type" : "array",
16-
"description" : "Output audit elements. You can add more if you want. If multiple values, you can use a comma separated\nstring as default value in the template and values.yml. You can also use a list of strings in YAML format.",
17-
"default" : [ "client_id", "user_id", "scope_client_id", "endpoint", "serviceId" ],
18-
"items" : {
19-
"type" : "string"
20-
}
11+
"mask" : {
12+
"type" : "boolean",
13+
"description" : "Enable mask in the audit log",
14+
"default" : true
2115
},
2216
"statusCode" : {
2317
"type" : "boolean",
@@ -33,15 +27,26 @@
3327
"type" : "boolean",
3428
"description" : "when auditOnError is true:\n - it will only log when status code >= 400\nwhen auditOnError is false:\n - it will log on every request\nlog level is controlled by logLevel"
3529
},
36-
"mask" : {
37-
"type" : "boolean",
38-
"description" : "Enable mask in the audit log",
39-
"default" : true
40-
},
4130
"timestampFormat" : {
4231
"type" : "string",
4332
"description" : "the format for outputting the timestamp, if the format is not specified or invalid, will use a long value.\nfor some users that will process the audit log manually, you can use yyyy-MM-dd'T'HH:mm:ss.SSSZ as format."
4433
},
34+
"headers" : {
35+
"type" : "array",
36+
"description" : "Output header elements. You can add more if you want. If multiple values, you can use a comma separated\nstring as default value in the template and values.yml. You can also use a list of strings in YAML format.\nCorrelation Id\n- X-Correlation-Id\nTraceability Id\n- X-Traceability-Id\ncaller id for metrics\n- caller_id\n",
37+
"default" : [ "X-Correlation-Id", "X-Traceability-Id", "caller_id" ],
38+
"items" : {
39+
"type" : "string"
40+
}
41+
},
42+
"audit" : {
43+
"type" : "array",
44+
"description" : "Output audit elements. You can add more if you want. If multiple values, you can use a comma separated\nstring as default value in the template and values.yml. You can also use a list of strings in YAML format.\nClient Id\n- client_id\nUser Id in id token, this is optional\n- user_id\nClient Id in scope/access token, this is optional\n- scope_client_id\nRequest endpoint uri@method.\n- endpoint\nService ID assigned to the service, this is optional and must be set by the service in its implementation\n- serviceId\nRequest Body, this is optional and must be set by the service in its implementation\n- requestBody\nResponse payload, this is optional and must be set by the service in its implementation\n- responseBody\n",
45+
"default" : [ "client_id", "user_id", "scope_client_id", "endpoint", "serviceId" ],
46+
"items" : {
47+
"type" : "string"
48+
}
49+
},
4550
"requestBodyMaxSize" : {
4651
"type" : "integer",
4752
"description" : "The limit of the request body to put into the audit entry if requestBody is in the list of audit. If the\nrequest body is bigger than the max size, it will be truncated to the max size. The default value is 4096.",
@@ -51,11 +56,6 @@
5156
"type" : "integer",
5257
"description" : "The limit of the response body to put into the audit entry if responseBody is in the list of audit. If the\nresponse body is bigger than the max size, it will be truncated to the max size. The default value is 4096.",
5358
"default" : 4096
54-
},
55-
"enabled" : {
56-
"type" : "boolean",
57-
"description" : "Enable Audit Logging",
58-
"default" : true
5959
}
6060
}
6161
}

0 commit comments

Comments
 (0)