禁止路径
| 18 | * |
| 19 | */ |
| 20 | public class DisablePath { |
| 21 | private static final Logger logger = LogManager.getLogger(DisablePath.class); |
| 22 | |
| 23 | private static final Set<String> disablePathSet = new HashSet<String>();//URL禁止路径 |
| 24 | |
| 25 | /** |
| 26 | * 禁止路径初始化 |
| 27 | */ |
| 28 | static{ |
| 29 | Properties props = new Properties(); |
| 30 | //取得当前系统使用的目录 |
| 31 | |
| 32 | org.springframework.core.io.Resource resource = new ClassPathResource("/disablePath.properties");//读取配置文件 |
| 33 | |
| 34 | try (InputStream is = resource.getInputStream()){ |
| 35 | props.load(is);//得到当前类的类加载器,以流的方式读取配置文件 |
| 36 | |
| 37 | Iterator itr = props.entrySet().iterator(); |
| 38 | while (itr.hasNext()){ |
| 39 | Entry e = (Entry)itr.next(); |
| 40 | |
| 41 | if(e.getKey().toString().startsWith("path")){//path为禁止路径前缀 |
| 42 | disablePathSet.add(e.getValue().toString().trim().toLowerCase()); |
| 43 | } |
| 44 | } |
| 45 | } catch (IOException e) { |
| 46 | if (logger.isErrorEnabled()) { |
| 47 | logger.error("禁止路径初始化",e); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | public static Set<String> getPath(){ |
| 53 | return disablePathSet; |
| 54 | } |
| 55 | } |