diff --git a/turms-server-common/src/main/java/im/turms/server/common/domain/blocklist/manager/AutoBlockManager.java b/turms-server-common/src/main/java/im/turms/server/common/domain/blocklist/manager/AutoBlockManager.java index c765a5dde1..e5beb58f7c 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/domain/blocklist/manager/AutoBlockManager.java +++ b/turms-server-common/src/main/java/im/turms/server/common/domain/blocklist/manager/AutoBlockManager.java @@ -21,12 +21,15 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.function.ObjLongConsumer; +import jakarta.annotation.Nullable; import lombok.AllArgsConstructor; +import lombok.Data; import im.turms.server.common.infra.collection.CollectionUtil; +import im.turms.server.common.infra.lang.MathUtil; import im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties; -import im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties.BlockLevel; +import im.turms.server.common.infra.test.VisibleForTesting; import im.turms.server.common.infra.time.DateTimeUtil; /** @@ -34,14 +37,14 @@ */ public class AutoBlockManager { - private static final int UNSET_BLOCK_LEVEL = -1; + @VisibleForTesting + public static final int UNSET_BLOCK_LEVEL = -1; private final ObjLongConsumer onClientBlocked; private final boolean isEnabled; - private final List levels; + private final List blockLevelPropertiesList; private final int maxLevel; - private final int blockTriggerTimes; private final ConcurrentHashMap blockedClientIdToStatus; @@ -49,59 +52,83 @@ public AutoBlockManager( AutoBlockItemProperties autoBlockProperties, ObjLongConsumer onClientBlocked) { this.onClientBlocked = onClientBlocked; - levels = CollectionUtil.toListSupportRandomAccess(autoBlockProperties.getBlockLevels()); - isEnabled = autoBlockProperties.isEnabled() && !levels.isEmpty(); + blockLevelPropertiesList = + CollectionUtil.transformAsList(autoBlockProperties.getBlockLevels(), + properties -> new ParsedBlockLevelProperties( + properties.getBlockDurationSeconds(), + DateTimeUtil.millisToNanos( + properties.getReduceOneTriggerTimeIntervalMillis()), + properties.getTriggerTimesThreshold())); + isEnabled = autoBlockProperties.isEnabled() && !blockLevelPropertiesList.isEmpty(); if (!isEnabled) { blockedClientIdToStatus = null; maxLevel = UNSET_BLOCK_LEVEL; - blockTriggerTimes = 0; return; } blockedClientIdToStatus = new ConcurrentHashMap<>(1024); - maxLevel = levels.size() - 1; - blockTriggerTimes = autoBlockProperties.getBlockTriggerTimes(); + maxLevel = blockLevelPropertiesList.size() - 1; } - public void tryBlockClient(T id) { + @Nullable + public BlockStatus tryBlockClient(T id) { if (!isEnabled) { - return; + return null; } - blockedClientIdToStatus.compute(id, (key, status) -> { + return blockedClientIdToStatus.compute(id, (key, status) -> { long now = System.nanoTime(); if (status == null) { - status = new BlockStatus(UNSET_BLOCK_LEVEL, null, 0, now); - } else { + status = new BlockStatus( + UNSET_BLOCK_LEVEL, + null, + blockLevelPropertiesList.getFirst(), + 0, + now); + } + ParsedBlockLevelProperties nextLevelProperties = status.nextLevelProperties; + // If already reaching the max level, + // notify the callback to refresh the block end time. + if (nextLevelProperties == null) { status.lastBlockTriggerTimeNanos = now; + status.triggerTimes++; + onClientBlocked.accept(id, status.currentLevelProperties.blockDurationSeconds); + return status; } - // Update status + long previousBlockTriggerTimeNanos = status.lastBlockTriggerTimeNanos; - int reduceOneTriggerTimeIntervalMillis = - status.currentLevelProperties.getReduceOneTriggerTimeIntervalMillis(); - int times = status.triggerTimes; - if (reduceOneTriggerTimeIntervalMillis > 0) { - times -= (int) ((status.lastBlockTriggerTimeNanos - previousBlockTriggerTimeNanos) - / (reduceOneTriggerTimeIntervalMillis * DateTimeUtil.NANOS_PER_MILLI)); - if (times < 0) { - times = 0; + status.lastBlockTriggerTimeNanos = now; + // Update the trigger times + long reduceOneTriggerTimeIntervalNanos = + nextLevelProperties.reduceOneTriggerTimeIntervalNanos; + int triggerTimes = status.triggerTimes; + if (reduceOneTriggerTimeIntervalNanos > 0) { + triggerTimes -= MathUtil.toInt(((now - previousBlockTriggerTimeNanos) + / reduceOneTriggerTimeIntervalNanos)); + if (triggerTimes <= 0) { + status.triggerTimes = 1; + } else { + status.triggerTimes = triggerTimes + 1; } + } else { + status.triggerTimes++; } - status.triggerTimes = times + 1; - boolean isBlocked = status.currentLevel != UNSET_BLOCK_LEVEL; - if (isBlocked) { - if (status.triggerTimes >= status.currentLevelProperties - .getGoNextLevelTriggerTimes() && status.currentLevel < maxLevel) { - status.currentLevel++; - status.currentLevelProperties = levels.get(status.currentLevel); - status.triggerTimes = 0; + ParsedBlockLevelProperties currentLevelProperties = status.currentLevelProperties; + // Check if the status needs to advance to the next level + if (status.triggerTimes >= nextLevelProperties.triggerTimesThreshold + && status.currentLevel < maxLevel) { + status.currentLevel++; + status.currentLevelProperties = blockLevelPropertiesList.get(status.currentLevel); + if (status.currentLevel + 1 <= maxLevel) { + status.nextLevelProperties = + blockLevelPropertiesList.get(status.currentLevel + 1); + } else { + status.nextLevelProperties = null; } - onClientBlocked.accept(id, status.currentLevelProperties.getBlockDurationSeconds()); - } else if (status.triggerTimes >= blockTriggerTimes) { - status.currentLevel = 0; - status.currentLevelProperties = levels.getFirst(); status.triggerTimes = 0; - onClientBlocked.accept(id, status.currentLevelProperties.getBlockDurationSeconds()); - } else { - status.triggerTimes++; + onClientBlocked.accept(id, status.currentLevelProperties.blockDurationSeconds); + } else if (currentLevelProperties != null) { + // If already blocked, + // notify the callback to refresh the block end time. + onClientBlocked.accept(id, currentLevelProperties.blockDurationSeconds); } return status; }); @@ -123,12 +150,25 @@ public void evictExpiredBlockedClients() { .iterator(); while (iterator.hasNext()) { BlockStatus status = iterator.next(); - int reduceOneTriggerTimeInterval = - status.currentLevelProperties.getReduceOneTriggerTimeIntervalMillis(); - if (reduceOneTriggerTimeInterval > 0) { - int times = status.triggerTimes - (int) ((now - status.lastBlockTriggerTimeNanos) - / (reduceOneTriggerTimeInterval * DateTimeUtil.NANOS_PER_MILLI)); - if (times <= 0) { + ParsedBlockLevelProperties currentLevelProperties = status.currentLevelProperties; + // If the client has been blocked, + // remove if the block duration has expired. + if (currentLevelProperties != null) { + if ((now - status.lastBlockTriggerTimeNanos) + / DateTimeUtil.NANOS_PER_SECOND > currentLevelProperties.blockDurationSeconds) { + iterator.remove(); + } + continue; + } + // If the client is not blocked, + // remove if the trigger times have expired. + long reduceOneTriggerTimeIntervalNanos = + status.nextLevelProperties.reduceOneTriggerTimeIntervalNanos; + if (reduceOneTriggerTimeIntervalNanos > 0) { + int triggerTimes = status.triggerTimes + - MathUtil.toInt((now - status.lastBlockTriggerTimeNanos) + / reduceOneTriggerTimeIntervalNanos); + if (triggerTimes <= 0) { iterator.remove(); } } @@ -136,11 +176,28 @@ public void evictExpiredBlockedClients() { } @AllArgsConstructor - private static class BlockStatus { + @Data + public static class BlockStatus { private int currentLevel; - private BlockLevel currentLevelProperties; + /** + * Null if the client is not blocked. + */ + @Nullable + private ParsedBlockLevelProperties currentLevelProperties; + /** + * Null if the current level is the max level. + */ + @Nullable + private ParsedBlockLevelProperties nextLevelProperties; private int triggerTimes; private long lastBlockTriggerTimeNanos; } + public record ParsedBlockLevelProperties( + long blockDurationSeconds, + long reduceOneTriggerTimeIntervalNanos, + int triggerTimesThreshold + ) { + } + } \ No newline at end of file diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/security/AutoBlockItemProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/security/AutoBlockItemProperties.java index 0aa630f8a4..d7086066bb 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/security/AutoBlockItemProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/security/AutoBlockItemProperties.java @@ -36,38 +36,37 @@ @NoArgsConstructor public class AutoBlockItemProperties { - public static final List DEFAULT_BLOCK_LEVELS = - List.of(new BlockLevel(10 * 60, 60 * 1000, 1), - new BlockLevel(30 * 60, 60 * 1000, 1), - new BlockLevel(60 * 60, 60 * 1000, 0)); + public static final List DEFAULT_BLOCK_LEVELS = + List.of(new BlockLevelProperties(10 * 60, 60 * 1000, 5), + new BlockLevelProperties(30 * 60, 60 * 1000, 1), + new BlockLevelProperties(60 * 60, 60 * 1000, 1)); - protected boolean enabled; + protected boolean enabled = true; - @Description("Block the client when the block condition is triggered the times") - @Min(0) - protected int blockTriggerTimes = 5; - - protected List blockLevels = DEFAULT_BLOCK_LEVELS; + protected List blockLevels = DEFAULT_BLOCK_LEVELS; @AllArgsConstructor @Builder(toBuilder = true) @Data @NoArgsConstructor - public static class BlockLevel { + public static class BlockLevelProperties { - @Description("Block the client for the specified duration in seconds") + @Description("Block the client for the specified duration in seconds. " + + "After the block duration, the block level will be reset, " + + "and the client will be unblocked automatically") @Min(1) protected long blockDurationSeconds = 10L * 60; - @Description("Reduce the trigger time by 1 when the time passes. " + @Description("If a user's block level is the previous level of this level, " + + "reduce the trigger time by 1 when the time passes. " + "If 0, never reduce the trigger times and " + "the block status will remain in the memory until the server is closed") @Min(0) protected int reduceOneTriggerTimeIntervalMillis = 60 * 1000; - @Description("Go to the next block level when the block condition is triggered the times") - @Min(0) - protected int goNextLevelTriggerTimes = 1; + @Description("When the block condition is triggered the specified times, advance to this block level") + @Min(1) + protected int triggerTimesThreshold = 1; } diff --git a/turms-server-common/src/test/java/unit/im/turms/server/common/domain/blocklist/manager/AutoBlockManagerTest.java b/turms-server-common/src/test/java/unit/im/turms/server/common/domain/blocklist/manager/AutoBlockManagerTest.java new file mode 100644 index 0000000000..aea2e8d1ff --- /dev/null +++ b/turms-server-common/src/test/java/unit/im/turms/server/common/domain/blocklist/manager/AutoBlockManagerTest.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2019 The Turms Project + * https://github.com/turms-im/turms + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package unit.im.turms.server.common.domain.blocklist.manager; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.ObjLongConsumer; + +import org.junit.jupiter.api.Test; + +import im.turms.server.common.domain.blocklist.manager.AutoBlockManager; +import im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author James Chen + */ +class AutoBlockManagerTest { + + @Test + void tryBlockClient() { + Map clientIdToBlockStats = new HashMap<>(); + ObjLongConsumer onClientBlocked = + (clientId, blockDurationSeconds) -> clientIdToBlockStats.compute(clientId, + (id, stats) -> stats == null + ? new BlockStats(1, blockDurationSeconds) + : new BlockStats(stats.triggerTimes + 1, blockDurationSeconds)); + AutoBlockItemProperties properties = new AutoBlockItemProperties(); + List blockLevelPropertiesList = + properties.getBlockLevels(); + AutoBlockManager manager = new AutoBlockManager<>(properties, onClientBlocked); + + AutoBlockManager.BlockStatus blockStatus; + Long clientIdToBlock = 1L; + + // The client should not be blocked before reaching the threshold + blockStatus = manager.tryBlockClient(clientIdToBlock); + assertThat(clientIdToBlockStats).isEmpty(); + assertThat(blockStatus.getCurrentLevel()).isEqualTo(AutoBlockManager.UNSET_BLOCK_LEVEL); + assertThat(blockStatus.getCurrentLevelProperties()).isNull(); + assertThat(blockStatus.getNextLevelProperties()).isNotNull(); + + blockStatus = manager.tryBlockClient(clientIdToBlock); + assertThat(clientIdToBlockStats).isEmpty(); + assertThat(blockStatus.getCurrentLevel()).isEqualTo(AutoBlockManager.UNSET_BLOCK_LEVEL); + assertThat(blockStatus.getCurrentLevelProperties()).isNull(); + assertThat(blockStatus.getNextLevelProperties()).isNotNull(); + + blockStatus = manager.tryBlockClient(clientIdToBlock); + assertThat(clientIdToBlockStats).isEmpty(); + assertThat(blockStatus.getCurrentLevel()).isEqualTo(AutoBlockManager.UNSET_BLOCK_LEVEL); + assertThat(blockStatus.getCurrentLevelProperties()).isNull(); + assertThat(blockStatus.getNextLevelProperties()).isNotNull(); + + blockStatus = manager.tryBlockClient(clientIdToBlock); + assertThat(clientIdToBlockStats).isEmpty(); + assertThat(blockStatus.getCurrentLevel()).isEqualTo(AutoBlockManager.UNSET_BLOCK_LEVEL); + assertThat(blockStatus.getCurrentLevelProperties()).isNull(); + assertThat(blockStatus.getNextLevelProperties()).isNotNull(); + + // The client should be blocked when reaching the threshold + blockStatus = manager.tryBlockClient(clientIdToBlock); + assertThat(clientIdToBlockStats).isNotEmpty(); + assertThat(clientIdToBlockStats.get(clientIdToBlock).triggerTimes).isOne(); + assertThat(clientIdToBlockStats.get(clientIdToBlock).lastBlockTriggerSeconds) + .isEqualTo(blockLevelPropertiesList.getFirst() + .getBlockDurationSeconds()); + assertThat(blockStatus.getCurrentLevel()).isZero(); + assertThat(blockStatus.getCurrentLevelProperties()).isNotNull(); + assertThat(blockStatus.getNextLevelProperties()).isNotNull(); + assertThat(blockStatus.getTriggerTimes()).isZero(); + + // The client should be blocked with the second level + blockStatus = manager.tryBlockClient(clientIdToBlock); + assertThat(clientIdToBlockStats).isNotEmpty(); + assertThat(clientIdToBlockStats.get(clientIdToBlock).triggerTimes).isEqualTo(2); + assertThat(clientIdToBlockStats.get(clientIdToBlock).lastBlockTriggerSeconds) + .isEqualTo(blockLevelPropertiesList.get(1) + .getBlockDurationSeconds()); + assertThat(blockStatus.getCurrentLevel()).isOne(); + assertThat(blockStatus.getCurrentLevelProperties()).isNotNull(); + assertThat(blockStatus.getNextLevelProperties()).isNotNull(); + assertThat(blockStatus.getTriggerTimes()).isZero(); + + // The client should be blocked with the third level + blockStatus = manager.tryBlockClient(clientIdToBlock); + assertThat(clientIdToBlockStats).isNotEmpty(); + assertThat(clientIdToBlockStats.get(clientIdToBlock).triggerTimes).isEqualTo(3); + assertThat(clientIdToBlockStats.get(clientIdToBlock).lastBlockTriggerSeconds) + .isEqualTo(blockLevelPropertiesList.get(2) + .getBlockDurationSeconds()); + assertThat(blockStatus.getCurrentLevel()).isEqualTo(2); + assertThat(blockStatus.getCurrentLevelProperties()).isNotNull(); + assertThat(blockStatus.getNextLevelProperties()).isNull(); + assertThat(blockStatus.getTriggerTimes()).isZero(); + + // The client should be blocked with the third level + blockStatus = manager.tryBlockClient(clientIdToBlock); + assertThat(clientIdToBlockStats).isNotEmpty(); + assertThat(clientIdToBlockStats.get(clientIdToBlock).triggerTimes).isEqualTo(4); + assertThat(clientIdToBlockStats.get(clientIdToBlock).lastBlockTriggerSeconds) + .isEqualTo(blockLevelPropertiesList.get(2) + .getBlockDurationSeconds()); + assertThat(blockStatus.getCurrentLevel()).isEqualTo(2); + assertThat(blockStatus.getCurrentLevelProperties()).isNotNull(); + assertThat(blockStatus.getNextLevelProperties()).isNull(); + assertThat(blockStatus.getTriggerTimes()).isEqualTo(1); + + // The client should be blocked with the third level + blockStatus = manager.tryBlockClient(clientIdToBlock); + assertThat(clientIdToBlockStats).isNotEmpty(); + assertThat(clientIdToBlockStats.get(clientIdToBlock).triggerTimes).isEqualTo(5); + assertThat(clientIdToBlockStats.get(clientIdToBlock).lastBlockTriggerSeconds) + .isEqualTo(blockLevelPropertiesList.get(2) + .getBlockDurationSeconds()); + assertThat(blockStatus.getCurrentLevel()).isEqualTo(2); + assertThat(blockStatus.getCurrentLevelProperties()).isNotNull(); + assertThat(blockStatus.getNextLevelProperties()).isNull(); + assertThat(blockStatus.getTriggerTimes()).isEqualTo(2); + } + + record BlockStats( + int triggerTimes, + long lastBlockTriggerSeconds + ) { + } + +} \ No newline at end of file diff --git a/turms-server-common/src/test/resources/application-full-example.yaml b/turms-server-common/src/test/resources/application-full-example.yaml index b01a2f8461..51898bc592 100644 --- a/turms-server-common/src/test/resources/application-full-example.yaml +++ b/turms-server-common/src/test/resources/application-full-example.yaml @@ -976,6 +976,11 @@ turms: # global property: false # mutable property: false allow-save: false + # The strategy to handle duplicate classes defined by both the Turms server and the plugin when loading classes by the plugin classloader. + # global property: false + # mutable property: false + # enum values: [throw_exception, parent_first] + duplicate-class-load-strategy: parent_first js: # Whether to allow saving plugins using HTTP API. # global property: false @@ -1041,61 +1046,49 @@ turms: # mutable property: false block-levels: - block-duration-seconds: 600 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 5 - block-duration-seconds: 1800 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 1 - block-duration-seconds: 3600 - go-next-level-trigger-times: 0 reduce-one-trigger-time-interval-millis: 60000 - # Block the client when the block condition is triggered the times. + trigger-times-threshold: 1 # global property: false # mutable property: false - block-trigger-times: 5 - # global property: false - # mutable property: false - enabled: false + enabled: true corrupted-request: # global property: false # mutable property: false block-levels: - block-duration-seconds: 600 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 5 - block-duration-seconds: 1800 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 1 - block-duration-seconds: 3600 - go-next-level-trigger-times: 0 reduce-one-trigger-time-interval-millis: 60000 - # Block the client when the block condition is triggered the times. + trigger-times-threshold: 1 # global property: false # mutable property: false - block-trigger-times: 5 - # global property: false - # mutable property: false - enabled: false + enabled: true frequent-request: # global property: false # mutable property: false block-levels: - block-duration-seconds: 600 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 5 - block-duration-seconds: 1800 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 1 - block-duration-seconds: 3600 - go-next-level-trigger-times: 0 reduce-one-trigger-time-interval-millis: 60000 - # Block the client when the block condition is triggered the times. - # global property: false - # mutable property: false - block-trigger-times: 5 + trigger-times-threshold: 1 # global property: false # mutable property: false - enabled: false + enabled: true # global property: false # mutable property: false enabled: true @@ -1109,61 +1102,49 @@ turms: # mutable property: false block-levels: - block-duration-seconds: 600 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 5 - block-duration-seconds: 1800 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 1 - block-duration-seconds: 3600 - go-next-level-trigger-times: 0 reduce-one-trigger-time-interval-millis: 60000 - # Block the client when the block condition is triggered the times. - # global property: false - # mutable property: false - block-trigger-times: 5 + trigger-times-threshold: 1 # global property: false # mutable property: false - enabled: false + enabled: true corrupted-request: # global property: false # mutable property: false block-levels: - block-duration-seconds: 600 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 5 - block-duration-seconds: 1800 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 1 - block-duration-seconds: 3600 - go-next-level-trigger-times: 0 reduce-one-trigger-time-interval-millis: 60000 - # Block the client when the block condition is triggered the times. - # global property: false - # mutable property: false - block-trigger-times: 5 + trigger-times-threshold: 1 # global property: false # mutable property: false - enabled: false + enabled: true frequent-request: # global property: false # mutable property: false block-levels: - block-duration-seconds: 600 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 5 - block-duration-seconds: 1800 - go-next-level-trigger-times: 1 reduce-one-trigger-time-interval-millis: 60000 + trigger-times-threshold: 1 - block-duration-seconds: 3600 - go-next-level-trigger-times: 0 reduce-one-trigger-time-interval-millis: 60000 - # Block the client when the block condition is triggered the times. + trigger-times-threshold: 1 # global property: false # mutable property: false - block-trigger-times: 5 - # global property: false - # mutable property: false - enabled: false + enabled: true # global property: false # mutable property: false enabled: true diff --git a/turms-server-common/src/test/resources/turms-properties-metadata-with-property-value.json b/turms-server-common/src/test/resources/turms-properties-metadata-with-property-value.json index ee234e9321..8955780404 100644 --- a/turms-server-common/src/test/resources/turms-properties-metadata-with-property-value.json +++ b/turms-server-common/src/test/resources/turms-properties-metadata-with-property-value.json @@ -2678,7 +2678,7 @@ "corruptedFrame": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, @@ -2686,43 +2686,34 @@ "value": [ { "blockDurationSeconds": 600, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 5 }, { "blockDurationSeconds": 1800, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 }, { "blockDurationSeconds": 3600, - "goNextLevelTriggerTimes": 0, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 } ] }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int", - "value": 5 - }, "enabled": { "deprecated": false, "global": false, "mutable": false, "sensitive": false, "type": "boolean", - "value": false + "value": true } }, "corruptedRequest": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, @@ -2730,43 +2721,34 @@ "value": [ { "blockDurationSeconds": 600, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 5 }, { "blockDurationSeconds": 1800, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 }, { "blockDurationSeconds": 3600, - "goNextLevelTriggerTimes": 0, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 } ] }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int", - "value": 5 - }, "enabled": { "deprecated": false, "global": false, "mutable": false, "sensitive": false, "type": "boolean", - "value": false + "value": true } }, "frequentRequest": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, @@ -2774,37 +2756,28 @@ "value": [ { "blockDurationSeconds": 600, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 5 }, { "blockDurationSeconds": 1800, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 }, { "blockDurationSeconds": 3600, - "goNextLevelTriggerTimes": 0, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 } ] }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int", - "value": 5 - }, "enabled": { "deprecated": false, "global": false, "mutable": false, "sensitive": false, "type": "boolean", - "value": false + "value": true } } }, @@ -2830,7 +2803,7 @@ "corruptedFrame": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, @@ -2838,43 +2811,34 @@ "value": [ { "blockDurationSeconds": 600, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 5 }, { "blockDurationSeconds": 1800, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 }, { "blockDurationSeconds": 3600, - "goNextLevelTriggerTimes": 0, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 } ] }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int", - "value": 5 - }, "enabled": { "deprecated": false, "global": false, "mutable": false, "sensitive": false, "type": "boolean", - "value": false + "value": true } }, "corruptedRequest": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, @@ -2882,43 +2846,34 @@ "value": [ { "blockDurationSeconds": 600, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 5 }, { "blockDurationSeconds": 1800, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 }, { "blockDurationSeconds": 3600, - "goNextLevelTriggerTimes": 0, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 } ] }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int", - "value": 5 - }, "enabled": { "deprecated": false, "global": false, "mutable": false, "sensitive": false, "type": "boolean", - "value": false + "value": true } }, "frequentRequest": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, @@ -2926,37 +2881,28 @@ "value": [ { "blockDurationSeconds": 600, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 5 }, { "blockDurationSeconds": 1800, - "goNextLevelTriggerTimes": 1, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 }, { "blockDurationSeconds": 3600, - "goNextLevelTriggerTimes": 0, - "reduceOneTriggerTimeIntervalMillis": 60000 + "reduceOneTriggerTimeIntervalMillis": 60000, + "triggerTimesThreshold": 1 } ] }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int", - "value": 5 - }, "enabled": { "deprecated": false, "global": false, "mutable": false, "sensitive": false, "type": "boolean", - "value": false + "value": true } } }, diff --git a/turms-server-common/src/test/resources/turms-properties-metadata.json b/turms-server-common/src/test/resources/turms-properties-metadata.json index ad93097692..bd908e0ef4 100644 --- a/turms-server-common/src/test/resources/turms-properties-metadata.json +++ b/turms-server-common/src/test/resources/turms-properties-metadata.json @@ -2404,20 +2404,12 @@ "corruptedFrame": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, "type": "java.util.List" }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int" - }, "enabled": { "deprecated": false, "global": false, @@ -2429,20 +2421,12 @@ "corruptedRequest": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, "type": "java.util.List" }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int" - }, "enabled": { "deprecated": false, "global": false, @@ -2454,20 +2438,12 @@ "frequentRequest": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, "type": "java.util.List" }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int" - }, "enabled": { "deprecated": false, "global": false, @@ -2497,20 +2473,12 @@ "corruptedFrame": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, "type": "java.util.List" }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int" - }, "enabled": { "deprecated": false, "global": false, @@ -2522,20 +2490,12 @@ "corruptedRequest": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, "type": "java.util.List" }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int" - }, "enabled": { "deprecated": false, "global": false, @@ -2547,20 +2507,12 @@ "frequentRequest": { "blockLevels": { "deprecated": false, - "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevel", + "elementType": "im.turms.server.common.infra.property.env.common.security.AutoBlockItemProperties$BlockLevelProperties", "global": false, "mutable": false, "sensitive": false, "type": "java.util.List" }, - "blockTriggerTimes": { - "deprecated": false, - "description": "Block the client when the block condition is triggered the times", - "global": false, - "mutable": false, - "sensitive": false, - "type": "int" - }, "enabled": { "deprecated": false, "global": false,