@Override public void init(FilterConfig fc) throws ServletException { LOG.info("初始化性能过滤器(Initialize the filter performance)"); enabled = PropertyHolder.getBooleanProperty("monitor.performance"); if (enabled) { LOG.info("启用性能分析日志(Enable performance analyzing log)"); } else { LOG.info("禁用性能分析日志(Disable performance analyzing log)"); } }
private boolean filter(HttpServletRequest req) { String path = req.getRequestURI(); if (path.contains("/log/")) { LOG.info("路径包含/log/,不执行性能分析(/log/ in path, not execute performance analysis) " + path); return false; } if (path.contains("/monitor/")) { LOG.info("路径包含/monitor/,不执行性能分析(/log/ in path, not execute performance analysis) " + path); return false; } return true; }
protected void initParameters(final FilterConfig fConfig) { failureUrl = PropertyHolder.getProperty("login.page") + "?state=checkCodeError"; if ("true".equals(PropertyHolder.getProperty("login.code"))) { log.info("启用登录验证码机制"); filter = true; } else { filter = false; log.info("禁用登录验证码机制"); } if (StringUtils.isNotBlank(fConfig.getInitParameter(PARAM_FILTER_PROCESSES_URL))) { filterProcessesUrl = fConfig.getInitParameter(PARAM_FILTER_PROCESSES_URL); } if (StringUtils.isNotBlank(fConfig.getInitParameter(PARAM_CAPTCHA_PARAMTER_NAME))) { captchaParamterName = fConfig.getInitParameter(PARAM_CAPTCHA_PARAMTER_NAME); } }
@Override public Object convertFromString(Map context, String[] values, Class toClass) { if (values[0] == null || values[0].trim().equals("")) { return 0; } try { return Integer.parseInt(values[0].trim()); } catch (Exception e) { LOG.info("字符串:" + values[0].trim() + "转换为数字失败"); } return 0; }
@Override public void destroy() { LOG.info("销毁性能过滤器(Destroy the filter performance)"); }
/** 初始化系统安全拦截信息 */ @PostConstruct public void initSecurityConfigInfo() { String security = PropertyHolder.getProperty("security"); if (security == null || !"true".equals(security.trim())) { log.info("当前系统禁用安全机制"); return; } log.info("开始初始化权限子系统..."); LinkedHashMap<RequestKey, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<>(); SecurityConfig manager = new SecurityConfig("ROLE_MANAGER"); SecurityConfig superManager = new SecurityConfig("ROLE_SUPERMANAGER"); Collection<ConfigAttribute> value = new ArrayList<>(); value.add(manager); value.add(superManager); Collection<String> urls = new LinkedHashSet<>(); String[] urlFiles = PropertyHolder.getProperty("manager.default.url").split(","); for (String urlFile : urlFiles) { Collection<String> url = FileUtils.getClassPathTextFileContent(urlFile); urls.addAll(url); } for (String url : urls) { if (url.contains("=")) { String[] attr = url.split("="); url = attr[0]; String[] roles = attr[1].split(","); Collection<ConfigAttribute> v = new ArrayList<>(); for (String role : roles) { v.add(new SecurityConfig(role)); } // POST RequestKey key = new RequestKey(url, "POST"); requestMap.put(key, v); // GET key = new RequestKey(url, "GET"); requestMap.put(key, v); } else { // POST RequestKey key = new RequestKey(url, "POST"); requestMap.put(key, value); // GET key = new RequestKey(url, "GET"); requestMap.put(key, value); } } for (Command command : serviceFacade.query(Command.class).getModels()) { List<String> paths = ModuleService.getCommandPath(command); Map<String, String> map = ModuleService.getCommandPathToRole(command); for (String path : paths) { RequestKey key = new RequestKey(path.toString().toLowerCase() + ".action*", "POST"); value = new ArrayList<>(); value.add(new SecurityConfig("ROLE_MANAGER" + map.get(path))); value.add(superManager); requestMap.put(key, value); // GET key = new RequestKey(path.toString().toLowerCase() + ".action*", "GET"); requestMap.put(key, value); } } RequestKey key = new RequestKey("/**", "POST"); value = new ArrayList<>(); value.add(superManager); requestMap.put(key, value); // GET key = new RequestKey("/**", "GET"); requestMap.put(key, value); DefaultFilterInvocationSecurityMetadataSource source = new DefaultFilterInvocationSecurityMetadataSource(new AntUrlPathMatcher(), requestMap); filterSecurityInterceptor.setSecurityMetadataSource(source); log.debug("system privilege info:\n"); for (Map.Entry<RequestKey, Collection<ConfigAttribute>> entry : requestMap.entrySet()) { log.debug(entry.getKey().toString()); for (ConfigAttribute att : entry.getValue()) { log.debug("\t" + att.toString()); } } log.info("完成初始化权限子系统..."); }