|
@@ -15,6 +15,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Modifier;
|
|
import java.lang.reflect.Modifier;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 敏感词过滤
|
|
* 敏感词过滤
|
|
@@ -27,7 +28,7 @@ public class SensitiveWordConfig {
|
|
@Autowired
|
|
@Autowired
|
|
WordFilter wordFilter;
|
|
WordFilter wordFilter;
|
|
|
|
|
|
- @Around("@annotation(org.springframework.web.bind.annotation.PostMapping)||@annotation(org.springframework.web.bind.annotation.PutMapping)")
|
|
|
|
|
|
+ @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)||@annotation(org.springframework.web.bind.annotation.PutMapping)||@annotation(org.springframework.web.bind.annotation.PostMapping)")
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
public Object doBefore(ProceedingJoinPoint point) {
|
|
public Object doBefore(ProceedingJoinPoint point) {
|
|
System.out.println("####################进入敏感词检测#######");
|
|
System.out.println("####################进入敏感词检测#######");
|
|
@@ -36,13 +37,30 @@ public class SensitiveWordConfig {
|
|
return point.proceed();
|
|
return point.proceed();
|
|
}
|
|
}
|
|
//所有的参数对象
|
|
//所有的参数对象
|
|
- for (Object arg : point.getArgs()) {
|
|
|
|
|
|
+ boolean hasSentiveWords = false;
|
|
|
|
+ for (int i=0;i<point.getArgs().length; i++) {
|
|
|
|
+ Object arg = point.getArgs()[i];
|
|
//参数对象,通过反射将String类型的值进行敏感词过滤
|
|
//参数对象,通过反射将String类型的值进行敏感词过滤
|
|
- Class<?> aClass = arg.getClass();
|
|
|
|
- //递归遍历,将所有String参数进行敏感词匹配
|
|
|
|
- foundString(aClass,arg);
|
|
|
|
|
|
+ System.out.println("获取到参数:");
|
|
|
|
+ if (arg != null) {
|
|
|
|
+ Class<?> aClass = arg.getClass();
|
|
|
|
+ System.out.println("获取到aClass:"+aClass);
|
|
|
|
+ if(aClass == String.class) {
|
|
|
|
+ //本身就是string类型
|
|
|
|
+ String afterValue = wordFilter.replaceWords((String)(arg));
|
|
|
|
+ System.out.println("替换后=" + afterValue);
|
|
|
|
+ point.getArgs()[i] = afterValue;
|
|
|
|
+ if (!afterValue.equals(arg)) {
|
|
|
|
+ hasSentiveWords = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } else if (aClass != Integer.class && aClass != LocalDate.class) {
|
|
|
|
+ //递归遍历,将所有String参数进行敏感词匹配
|
|
|
|
+ foundString(aClass,arg);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return point.proceed();
|
|
|
|
|
|
+ return point.proceed(point.getArgs());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -60,6 +78,7 @@ public class SensitiveWordConfig {
|
|
//如果是String类型,进行关键词匹配 且要排除final修饰的字段
|
|
//如果是String类型,进行关键词匹配 且要排除final修饰的字段
|
|
declaredField.setAccessible(true);
|
|
declaredField.setAccessible(true);
|
|
String value=(String)declaredField.get(arg);
|
|
String value=(String)declaredField.get(arg);
|
|
|
|
+ System.out.println("参数值:"+value);
|
|
declaredField.set(arg, wordFilter.replaceWords(value));
|
|
declaredField.set(arg, wordFilter.replaceWords(value));
|
|
}else if (type.getPackage()!=null&&type.getPackage().getName().contains("com.bysk")){
|
|
}else if (type.getPackage()!=null&&type.getPackage().getName().contains("com.bysk")){
|
|
Method[] methods = clazz.getMethods();
|
|
Method[] methods = clazz.getMethods();
|