Class BehaviorCaptchaValidator
java.lang.Object
cloud.opencode.base.captcha.validator.BehaviorCaptchaValidator
- All Implemented Interfaces:
CaptchaValidator
Behavior Captcha Validator - Validation with behavior analysis
行为验证码验证器 - 带行为分析的验证
This validator combines answer validation with behavior analysis to detect automated attacks and suspicious patterns.
此验证器结合答案验证和行为分析来检测自动攻击和可疑模式。
Features | 主要功能:
- Response time analysis - 响应时间分析
- Failure rate tracking - 失败率跟踪
- Consistent timing detection - 一致时间检测
- Bot behavior identification - 机器人行为识别
Usage Example | 使用示例:
CaptchaStore store = CaptchaStore.memory();
BehaviorCaptchaValidator validator = new BehaviorCaptchaValidator(store);
// Record creation time
validator.recordCreation(captchaId, clientId);
// (validation continues...)
// Later, validate with behavior check
ValidationResult result = validator.validate(captchaId, answer, clientId);
if (result.code() == ResultCode.SUSPICIOUS_BEHAVIOR) {
// Handle bot detection
}
Security | 安全性:
- Thread-safe: Yes (uses ConcurrentHashMap) - 线程安全: 是(使用ConcurrentHashMap)
- Null-safe: No (store, id, and answer must not be null) - 空值安全: 否(存储、ID和答案不能为null)
- Since:
- JDK 25, opencode-base-captcha V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new behavior validator with the specified store.BehaviorCaptchaValidator(CaptchaStore store, BehaviorAnalyzer analyzer) Creates a new behavior validator with custom analyzer. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears old creation records.Gets the behavior analyzer.voidrecordCreation(String captchaId, String clientId) Records CAPTCHA creation for a client.Validates a CAPTCHA answer.Validates a CAPTCHA answer with case sensitivity option.Validates with explicit client ID.Validates with explicit client ID and case sensitivity.
-
Constructor Details
-
BehaviorCaptchaValidator
Creates a new behavior validator with the specified store. 使用指定存储创建新行为验证器。- Parameters:
store- the CAPTCHA store | 验证码存储
-
BehaviorCaptchaValidator
Creates a new behavior validator with custom analyzer. 使用自定义分析器创建新行为验证器。- Parameters:
store- the CAPTCHA store | 验证码存储analyzer- the behavior analyzer | 行为分析器
-
-
Method Details
-
recordCreation
-
validate
Description copied from interface:CaptchaValidatorValidates a CAPTCHA answer. 验证验证码答案。- Specified by:
validatein interfaceCaptchaValidator- Parameters:
id- the CAPTCHA ID | 验证码 IDanswer- the provided answer | 提供的答案- Returns:
- the validation result | 验证结果
-
validate
Description copied from interface:CaptchaValidatorValidates a CAPTCHA answer with case sensitivity option. 验证验证码答案(带大小写敏感选项)。- Specified by:
validatein interfaceCaptchaValidator- Parameters:
id- the CAPTCHA ID | 验证码 IDanswer- the provided answer | 提供的答案caseSensitive- whether case sensitive | 是否区分大小写- Returns:
- the validation result | 验证结果
-
validate
Validates with explicit client ID. 使用明确的客户端 ID 进行验证。- Parameters:
id- the CAPTCHA ID | 验证码 IDanswer- the provided answer | 提供的答案clientId- the client identifier | 客户端标识符- Returns:
- the validation result | 验证结果
-
validate
Validates with explicit client ID and case sensitivity. 使用明确的客户端 ID 和大小写敏感选项进行验证。- Parameters:
id- the CAPTCHA ID | 验证码 IDanswer- the provided answer | 提供的答案clientId- the client identifier | 客户端标识符caseSensitive- whether case sensitive | 是否区分大小写- Returns:
- the validation result | 验证结果
-
getAnalyzer
Gets the behavior analyzer. 获取行为分析器。- Returns:
- the behavior analyzer | 行为分析器
-
clearOldRecords
public void clearOldRecords()Clears old creation records. 清除旧的创建记录。
-