package com.cf.imes.module.report.validation.datasource;

import com.baomidou.mybatisplus.core.toolkit.sql.SqlInjectionUtils;
import org.apache.commons.lang3.StringUtils;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * sql参数注入攻击校验器
 *
 * @author Gqr
 * @since 2024/10/25 10:30
 */
public class SqlParamInjectionValidator implements ConstraintValidator<SqlParamInjectionValid, String> {
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (StringUtils.isEmpty(value)) {
            return true;
        }
        // mybatisplus工具校验注入攻击
        return !SqlInjectionUtils.check(value);
    }
}
