Пример #1
0
 /** @return 系统是否启用安全机制 */
 public static boolean isSecurity() {
   String security = PropertyHolder.getProperty("security");
   if (security != null && "true".equals(security.trim())) {
     return true;
   }
   return false;
 }
Пример #2
0
  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);
    }
  }
Пример #3
0
 @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)");
   }
 }
Пример #4
0
  /** 初始化系统安全拦截信息 */
  @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("完成初始化权限子系统...");
  }