Exemple #1
0
  @Post
  @Auth(roles = "admin")
  public Boundary save() throws Exception {
    List<ValidateError> errors = new ArrayList<>();
    errors.addAll(ProxyConfigsEntity.get().validate(getParams()));

    String type = getParam("proxyAuthType");
    // 認証がONの場合のチェック
    if (!type.equals(String.valueOf(AuthType.None.getValue()))) {
      if (StringUtils.isEmpty(getParam("proxyAuthUserId"))) {
        ValidateError error = new ValidateError("errors.required", getResource("label.auth.id"));
        errors.add(error);
      }
      if (StringUtils.isEmpty(getParam("proxyAuthPassword"))) {
        ValidateError error =
            new ValidateError("errors.required", getResource("label.auth.password"));
        errors.add(error);
      }
    }
    if (!errors.isEmpty()) {
      setResult(null, errors);
      return forward("config.jsp");
    }

    ProxyConfigsEntity entity = super.getParamOnProperty(ProxyConfigsEntity.class);
    ProxyConfigsDao dao = ProxyConfigsDao.get();

    if (entity.getProxyAuthPassword().equals(NO_CHANGE_PASSWORD)) {
      // パスワード変更無し
      ProxyConfigsEntity db = dao.selectOnKey(AppConfig.get().getSystemName());
      entity.setProxyAuthPassword(db.getProxyAuthPassword());
      entity.setProxyAuthSalt(db.getProxyAuthSalt());
    } else {
      // パスワードは暗号化する
      String salt = PasswordUtil.getSalt();
      entity.setProxyAuthPassword(PasswordUtil.encrypt(entity.getProxyAuthPassword(), salt));
      entity.setProxyAuthSalt(salt);
    }

    entity = dao.save(entity);

    String successMsg = "message.success.save";
    setResult(successMsg, errors);
    return config();
  }
Exemple #2
0
  @Post
  @Auth(roles = "admin")
  public Boundary test() throws Exception {
    try {
      ProxyConfigsEntity entity;
      String testUrl = getParam("testUrl");
      Integer testType = getParam("testType", Integer.class);
      if (INT_FLAG.OFF.getValue() == testType.intValue()) {
        entity = new ProxyConfigsEntity();
      } else {
        List<ValidateError> errors = new ArrayList<>();
        errors.addAll(ProxyConfigsEntity.get().validate(getParams()));

        String type = getParam("proxyAuthType");
        // 認証がONの場合のチェック
        if (!type.equals(String.valueOf(AuthType.None.getValue()))) {
          if (StringUtils.isEmpty(getParam("proxyAuthUserId"))) {
            ValidateError error =
                new ValidateError("errors.required", getResource("label.auth.id"));
            errors.add(error);
          }
          if (StringUtils.isEmpty(getParam("proxyAuthPassword"))) {
            ValidateError error =
                new ValidateError("errors.required", getResource("label.auth.password"));
            errors.add(error);
          }
        }
        if (!errors.isEmpty()) {
          setResult(null, errors);
          return forward("config.jsp");
        }

        entity = super.getParamOnProperty(ProxyConfigsEntity.class);
        ProxyConfigsDao dao = ProxyConfigsDao.get();

        if (entity.getProxyAuthPassword().equals(NO_CHANGE_PASSWORD)) {
          // パスワード変更無し
          ProxyConfigsEntity db = dao.selectOnKey(AppConfig.get().getSystemName());
          entity.setProxyAuthPassword(db.getProxyAuthPassword());
          entity.setProxyAuthSalt(db.getProxyAuthSalt());
        } else {
          // パスワードは暗号化する
          String salt = PasswordUtil.getSalt();
          entity.setProxyAuthPassword(PasswordUtil.encrypt(entity.getProxyAuthPassword(), salt));
          entity.setProxyAuthSalt(salt);
        }
      }

      // 確認用のURLで通信出来るか確認
      CrawlerLogic crawlerLogic = CrawlerLogic.get();
      String content = crawlerLogic.crawle(entity, testUrl);
      setAttribute("content", content);

      addMsgInfo("knowledge.proxy.test.done");

    } catch (Exception e) {
      LOG.warn("knowledge.proxy.test.fail", e);
      addMsgError("knowledge.proxy.test.fail");
      addMsgError(e.getClass().getSimpleName());
      if (StringUtils.isNotEmpty(e.getMessage())) {
        addMsgError(e.getMessage());
      }
    }
    return forward("config.jsp");
  }