* 表示匹配0或多个不是/的字符
** 表示匹配0或多个任意字符
? 表示匹配1个任意字符
/**
* 将通配符表达式转化为正则表达式
* @param path
* @return
*/
private static String getRegPath(String path) {
char[] chars = path.toCharArray();
int len = chars.length;
StringBuilder sb = new StringBuilder();
boolean preX = false;
for(int i=0;i
/**
* 通配符模式
* @param whitePath - 白名单地址
* @param reqPath - 请求地址
* @return
*/
private static boolean wildcardEquals(String whitePath, String reqPath) {
String regPath = getRegPath(whitePath);
return Pattern.compile(regPath).matcher(reqPath).matches();
}
public static void main(String[] args) {
String[] whiteList = new String[]{
"/abc/?df/ddd", "/abc/df/dfd", "/abc/***/dfd", "/abc/*", "/abd/**", "/g??gle", "/*.do","/ttt"
};
boolean r = FilterUtil.checkWhiteList("/abc/1/ss/dfd",whiteList);
System.out.println(r);
}