예제 #1
0
  /**
   * updates existing public key
   *
   * @param publicKey key object
   */
  public static void updatePublicKey(PublicKey publicKey) {

    Connection con = null;
    try {
      con = DBUtils.getConn();
      PreparedStatement stmt =
          con.prepareStatement(
              "update public_keys set key_nm=?, type=?, fingerprint=?, public_key=?, profile_id=? where id=? and user_id=? and enabled=true");
      stmt.setString(1, publicKey.getKeyNm());
      stmt.setString(2, SSHUtil.getKeyType(publicKey.getPublicKey()));
      stmt.setString(3, SSHUtil.getFingerprint(publicKey.getPublicKey()));
      stmt.setString(4, publicKey.getPublicKey().trim());
      if (publicKey.getProfile() == null || publicKey.getProfile().getId() == null) {
        stmt.setNull(5, Types.NULL);
      } else {
        stmt.setLong(5, publicKey.getProfile().getId());
      }
      stmt.setLong(6, publicKey.getId());
      stmt.setLong(7, publicKey.getUserId());
      stmt.execute();
      DBUtils.closeStmt(stmt);

    } catch (Exception e) {
      log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);
  }
예제 #2
0
  /**
   * inserts new public key
   *
   * @param publicKey key object
   */
  public static void insertPublicKey(PublicKey publicKey) {

    Connection con = null;
    try {
      con = DBUtils.getConn();
      PreparedStatement stmt =
          con.prepareStatement(
              "insert into public_keys(key_nm, type, fingerprint, public_key, profile_id, user_id) values (?,?,?,?,?,?)");
      stmt.setString(1, publicKey.getKeyNm());
      stmt.setString(2, SSHUtil.getKeyType(publicKey.getPublicKey()));
      stmt.setString(3, SSHUtil.getFingerprint(publicKey.getPublicKey()));
      stmt.setString(4, publicKey.getPublicKey().trim());
      if (publicKey.getProfile() == null || publicKey.getProfile().getId() == null) {
        stmt.setNull(5, Types.NULL);
      } else {
        stmt.setLong(5, publicKey.getProfile().getId());
      }
      stmt.setLong(6, publicKey.getUserId());
      stmt.execute();

      DBUtils.closeStmt(stmt);

    } catch (Exception e) {
      log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);
  }