Exemplo n.º 1
0
  /**
   * Change connection configuration.
   *
   * @param req HTTP request
   * @param id forward id to change
   * @return service response.
   */
  @POST
  @Path("connection/update/{id}")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public ServiceResponse updateConnection(
      @Context HttpServletRequest req, @PathParam("id") String id, Connection forwardReq) {

    Configuration cfg = getEditConfiguration(req);
    for (Connection account : cfg.getConnection()) {
      if (account.getId().equals(id)) {

        account.setName(forwardReq.getName());
        account.setHost(forwardReq.getHost());
        account.setPort(forwardReq.getPort());
        account.setUser(forwardReq.getUser());
        account.setPassword(
            forwardReq.getPassword().endsWith("==")
                ? forwardReq.getPassword()
                : DrillServer.getEncDecorder().encrypt(forwardReq.getPassword()));
        account.setProxy(forwardReq.getProxy());

        return ServiceUtils.createOKResponse("Connection changed");
      }
    }
    return ServiceUtils.createOKResponse("Connection not found: " + id);
  }
Exemplo n.º 2
0
  /**
   * Delete connection from configuration.
   *
   * @param req HTTP request
   * @param id forward id to delete
   * @return service response.
   */
  @DELETE
  @Path("connection/delete/{id}")
  @Produces(MediaType.APPLICATION_JSON)
  public ServiceResponse deleteConnection(
      @Context HttpServletRequest req, @PathParam("id") String id) {

    Configuration cfg = getEditConfiguration(req);
    for (SshSession sshClient : cfg.getSshSession()) {
      for (Forward fwd : sshClient.getForward()) {
        if (((Connection) fwd.getConnection()).getId().equals(id)) {
          return ServiceUtils.createNOKResponse(
              "Connection is in use by session " + sshClient.getName());
        }
      }
    }
    Iterator<Connection> iter = cfg.getConnection().iterator();
    while (iter.hasNext()) {
      Connection connection = iter.next();
      if (connection.getId().equals(id)) {
        iter.remove();
        return ServiceUtils.createOKResponse("Connection deleted");
      }
    }

    return ServiceUtils.createOKResponse("Connection not found: " + id);
  }
Exemplo n.º 3
0
  private Connection getConnectionById(String connectionId, Configuration cfg) {

    for (Connection mAccount : cfg.getConnection()) {
      if (mAccount.getId().equals(connectionId)) {
        return mAccount;
      }
    }
    return null;
  }
Exemplo n.º 4
0
  /**
   * Add new connection to configuration.
   *
   * @param req HTTP request
   * @param connectionCfg forward data
   * @return service response.
   */
  @POST
  @Path("connection/add")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public ServiceResponse addConnection(@Context HttpServletRequest req, Connection connectionCfg) {
    Configuration cfg = getEditConfiguration(req);

    connectionCfg.setId(StringUtils.createUUID());
    connectionCfg.setPassword(DrillServer.getEncDecorder().encrypt(connectionCfg.getPassword()));
    cfg.getConnection().add(connectionCfg);

    return ServiceUtils.createOKResponse("Connection added");
  }