package com.yunfeiyun.agmp.common.framework.validator;

import com.yunfeiyun.agmp.common.framework.validator.annotation.ParamSqlInjection;
import org.springframework.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class ParmSqlValidator implements ConstraintValidator<ParamSqlInjection, String> {
    private final static String xssStr = "'and exec insert select delete update drop count chr mid master truncate char declare ;or + -- ？";

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (StringUtils.hasLength(value)) {
            String[] split = value.split(",");
            for (int i=0; i < split.length; i++) {
                if (xssStr.contains(split[i].trim())) {
                    return false;
                }
            }
        }
        return true;
    }
}
