Skip to content

Commit b19ed17

Browse files
committed
Fix enable_audit_log configuration not taking effect
The audit log configuration (enable_audit_log) was not taking effect because the configuration values were stored as static final fields in AbstractAuditLogger, which were initialized at class loading time before the configuration file was fully loaded. This fix changes the static final fields to dynamic method calls: - IS_AUDIT_LOG_ENABLED -> isAuditLogEnabled() - AUDITABLE_OPERATION_TYPE -> getAuditableOperationType() - AUDITABLE_OPERATION_LEVEL -> getAuditableOperationLevel() - AUDITABLE_OPERATION_RESULT -> getAuditableOperationResult() This ensures that the configuration values are read dynamically at runtime, after the configuration file has been properly loaded. Fixes: #16706
1 parent bd813d8 commit b19ed17

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/audit/CNAuditLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public CNAuditLogger(ConfigManager configManager) {
5151

5252
@Override
5353
public void log(IAuditEntity auditLogFields, Supplier<String> log) {
54-
if (!IS_AUDIT_LOG_ENABLED) {
54+
if (!isAuditLogEnabled()) {
5555
return;
5656
}
5757
if (noNeedInsertAuditLog(auditLogFields)) {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/audit/DNAuditLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public void createViewIfNecessary() {
356356

357357
@Override
358358
public synchronized void log(IAuditEntity auditLogFields, Supplier<String> log) {
359-
if (!IS_AUDIT_LOG_ENABLED) {
359+
if (!isAuditLogEnabled()) {
360360
return;
361361
}
362362
try {
@@ -419,7 +419,7 @@ public synchronized void log(IAuditEntity auditLogFields, Supplier<String> log)
419419

420420
public void logFromCN(AuditLogFields auditLogFields, String log, int nodeId)
421421
throws IllegalPathException {
422-
if (!IS_AUDIT_LOG_ENABLED) {
422+
if (!isAuditLogEnabled()) {
423423
return;
424424
}
425425
createViewIfNecessary();

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/audit/AbstractAuditLogger.java

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,43 @@ public abstract class AbstractAuditLogger {
4242
public static final String AUDIT_LOG_LOG = "log";
4343

4444
private static final CommonConfig CONFIG = CommonDescriptor.getInstance().getConfig();
45-
protected static final boolean IS_AUDIT_LOG_ENABLED = CONFIG.isEnableAuditLog();
46-
private static final List<AuditLogOperation> AUDITABLE_OPERATION_TYPE =
47-
CONFIG.getAuditableOperationType();
48-
private static final PrivilegeLevel AUDITABLE_OPERATION_LEVEL =
49-
CONFIG.getAuditableOperationLevel();
50-
private static final String AUDITABLE_OPERATION_RESULT = CONFIG.getAuditableOperationResult();
45+
46+
/**
47+
* Check if audit log is enabled. This method reads the configuration dynamically instead of using
48+
* a static final field to ensure that the configuration is properly loaded before being used.
49+
*
50+
* @return true if audit log is enabled, false otherwise
51+
*/
52+
protected static boolean isAuditLogEnabled() {
53+
return CONFIG.isEnableAuditLog();
54+
}
55+
56+
/**
57+
* Get the list of auditable operation types. This method reads the configuration dynamically.
58+
*
59+
* @return the list of auditable operation types
60+
*/
61+
private static List<AuditLogOperation> getAuditableOperationType() {
62+
return CONFIG.getAuditableOperationType();
63+
}
64+
65+
/**
66+
* Get the auditable operation level. This method reads the configuration dynamically.
67+
*
68+
* @return the auditable operation level
69+
*/
70+
private static PrivilegeLevel getAuditableOperationLevel() {
71+
return CONFIG.getAuditableOperationLevel();
72+
}
73+
74+
/**
75+
* Get the auditable operation result. This method reads the configuration dynamically.
76+
*
77+
* @return the auditable operation result
78+
*/
79+
private static String getAuditableOperationResult() {
80+
return CONFIG.getAuditableOperationResult();
81+
}
5182

5283
public abstract void log(IAuditEntity auditLogFields, Supplier<String> log);
5384

@@ -58,22 +89,25 @@ public boolean noNeedInsertAuditLog(IAuditEntity auditLogFields) {
5889
// to do: check whether this event should be logged.
5990
// if whitelist or blacklist is used, only ip on the whitelist or blacklist can be logged
6091

61-
if (AUDITABLE_OPERATION_TYPE == null || !AUDITABLE_OPERATION_TYPE.contains(operation)) {
92+
List<AuditLogOperation> auditableOperationType = getAuditableOperationType();
93+
if (auditableOperationType == null || !auditableOperationType.contains(operation)) {
6294
return true;
6395
}
6496
if (auditLogFields.getPrivilegeTypes() != null) {
97+
PrivilegeLevel auditableOperationLevel = getAuditableOperationLevel();
6598
for (PrivilegeType privilegeType : auditLogFields.getPrivilegeTypes()) {
6699
PrivilegeLevel privilegeLevel = judgePrivilegeLevel(privilegeType);
67-
if (AUDITABLE_OPERATION_LEVEL == PrivilegeLevel.OBJECT
100+
if (auditableOperationLevel == PrivilegeLevel.OBJECT
68101
&& privilegeLevel == PrivilegeLevel.GLOBAL) {
69102
return true;
70103
}
71104
}
72105
}
73-
if (result && !AUDITABLE_OPERATION_RESULT.contains("SUCCESS")) {
106+
String auditableOperationResult = getAuditableOperationResult();
107+
if (result && !auditableOperationResult.contains("SUCCESS")) {
74108
return true;
75109
}
76-
return !result && !AUDITABLE_OPERATION_RESULT.contains("FAIL");
110+
return !result && !auditableOperationResult.contains("FAIL");
77111
}
78112

79113
public static PrivilegeLevel judgePrivilegeLevel(PrivilegeType type) {

0 commit comments

Comments
 (0)