コード例 #1
0
ファイル: WhitelistService.java プロジェクト: robinwuwu/lemon
  public void processHost(WhitelistApp whitelistApp, List<String> hosts) {
    hosts = this.trim(hosts);
    logger.info("hosts : {}", hosts);

    List<WhitelistHost> whitelistHosts =
        new ArrayList<WhitelistHost>(whitelistApp.getWhitelistHosts());
    logger.info("whitelistHosts : {}", whitelistHosts);

    for (WhitelistHost whitelistHost : whitelistHosts) {
      String value = whitelistHost.getValue();

      logger.info("hosts.contains(value) : {}", hosts.contains(value));

      if (!hosts.contains(value)) {
        whitelistHostManager.remove(whitelistHost);
        whitelistApp.getWhitelistHosts().remove(whitelistHost);
      }
    }

    logger.info("whitelistApp.getWhitelistHosts() : {}", whitelistApp.getWhitelistHosts());

    int index = 0;

    for (String host : hosts) {
      index++;

      boolean isExists = false;

      for (WhitelistHost whitelistHost : whitelistApp.getWhitelistHosts()) {
        String value = whitelistHost.getValue();

        if (host.equals(value)) {
          isExists = true;
          whitelistHost.setPriority(index);
          whitelistHostManager.save(whitelistHost);

          break;
        }
      }

      if (!isExists) {
        WhitelistHost whitelistHost = new WhitelistHost();
        whitelistHost.setValue(host);
        whitelistHost.setPriority(index);
        whitelistHost.setWhitelistApp(whitelistApp);
        whitelistHost.setTenantId(whitelistApp.getTenantId());
        whitelistHostManager.save(whitelistHost);
      }
    }
  }
コード例 #2
0
ファイル: WhitelistService.java プロジェクト: robinwuwu/lemon
  public void saveWhitelistApp(
      WhitelistApp whitelistApp,
      Long whitelistTypeId,
      String hostContent,
      String ipContent,
      String username,
      String tenantId) {
    Long id = whitelistApp.getId();
    WhitelistApp dest = null;

    if (id != null) {
      whitelistApp.setWhitelistHosts(null);
      whitelistApp.setWhitelistIps(null);
      dest = whitelistAppManager.get(id);
      beanMapper.copy(whitelistApp, dest);
    } else {
      dest = whitelistApp;
      dest.setUserId(username);
      dest.setTenantId(tenantId);
    }

    // type
    WhitelistType whitelistType = whitelistTypeManager.get(whitelistTypeId);
    dest.setWhitelistType(whitelistType);

    // host
    this.processHost(dest, Arrays.asList(hostContent.split("\n")));

    // ip
    this.processIp(dest, Arrays.asList(ipContent.split("\n")));

    whitelistAppManager.save(dest);
  }
コード例 #3
0
ファイル: WhitelistService.java プロジェクト: robinwuwu/lemon
  public void processIp(WhitelistApp whitelistApp, List<String> ips) {
    ips = this.trim(ips);

    List<WhitelistIp> whitelistIps = new ArrayList<WhitelistIp>(whitelistApp.getWhitelistIps());

    for (WhitelistIp whitelistIp : whitelistIps) {
      String value = whitelistIp.getValue();

      if (!ips.contains(value)) {
        whitelistIpManager.remove(whitelistIp);
        whitelistApp.getWhitelistIps().remove(whitelistIp);
      }
    }

    int index = 0;

    for (String ip : ips) {
      index++;

      boolean isExists = false;

      for (WhitelistIp whitelistIp : whitelistApp.getWhitelistIps()) {
        String value = whitelistIp.getValue();

        if (ip.equals(value)) {
          isExists = true;
          whitelistIp.setPriority(index);
          whitelistIpManager.save(whitelistIp);

          break;
        }
      }

      if (!isExists) {
        WhitelistIp whitelistIp = new WhitelistIp();
        whitelistIp.setValue(ip);
        whitelistIp.setPriority(index);
        whitelistIp.setWhitelistApp(whitelistApp);
        whitelistIp.setTenantId(whitelistApp.getTenantId());
        whitelistIpManager.save(whitelistIp);
      }
    }
  }