From fbec7745e7358a12cfb8414f6e005be98f96e3db Mon Sep 17 00:00:00 2001 From: Pedro Rolon Date: Mon, 17 Dec 2018 14:43:24 -0300 Subject: [PATCH] se agregó api key --- Api-e004/WebContent/vista/js/borrarPunto.js | 3 +++ Api-e004/WebContent/vista/js/buscarPunto.js | 3 +++ Api-e004/WebContent/vista/js/buscarPuntosCercanos.js | 3 +++ Api-e004/WebContent/vista/js/guardarPunto.js | 3 +++ Api-e004/build/classes/controlador/GeoConexion.class | Bin 10178 -> 0 bytes Api-e004/build/classes/controlador/Prueba.class | Bin 1874 -> 0 bytes Api-e004/src/api/GeoApi.java | 16 ++++++++++++++++ Api-e004/src/controlador/GeoConexion.java | 12 ++++-------- Api-e004/src/controlador/Prueba.java | 60 ------------------------------------------------------------ README.md | 3 ++- 10 files changed, 34 insertions(+), 69 deletions(-) delete mode 100644 Api-e004/build/classes/controlador/Prueba.class delete mode 100644 Api-e004/src/controlador/Prueba.java diff --git a/Api-e004/WebContent/vista/js/borrarPunto.js b/Api-e004/WebContent/vista/js/borrarPunto.js index 6bfccd2..482eabd 100644 --- a/Api-e004/WebContent/vista/js/borrarPunto.js +++ b/Api-e004/WebContent/vista/js/borrarPunto.js @@ -6,6 +6,9 @@ jQuery(function($){ //url: 'http://192.168.67.126:8095/ApiGeolocalizacion/punto/81', //URL de Albaro url: 'http://localhost:8080/Api-e004/punto/'+$("#idBaja").val(), type: "DELETE", + headers:{ + apiKey: "pqntslc" + }, //dataType:"json", success: function(result, textStatus, jqXHR) { //En result se guarda lo que retorna el servlet diff --git a/Api-e004/WebContent/vista/js/buscarPunto.js b/Api-e004/WebContent/vista/js/buscarPunto.js index 9b8de7f..7917ba6 100644 --- a/Api-e004/WebContent/vista/js/buscarPunto.js +++ b/Api-e004/WebContent/vista/js/buscarPunto.js @@ -5,6 +5,9 @@ jQuery(function($){ $.ajax({ url: 'http://localhost:8080/Api-e004/punto/'+$("#idConsulta").val(), type: 'GET', + headers:{ + apiKey: "pqntslc" + }, success: function(result){ console.log(result); }, diff --git a/Api-e004/WebContent/vista/js/buscarPuntosCercanos.js b/Api-e004/WebContent/vista/js/buscarPuntosCercanos.js index 31e7470..d59da65 100644 --- a/Api-e004/WebContent/vista/js/buscarPuntosCercanos.js +++ b/Api-e004/WebContent/vista/js/buscarPuntosCercanos.js @@ -5,6 +5,9 @@ jQuery(function($){ $.ajax({ url:'http://localhost:8080/Api-e004/buscar_puntos', type: 'GET', + headers:{ + apiKey: "pqntslc" + }, data:{ "lat": $("#latitudConsulta").val(), "lon": $('#longitudConsulta').val() diff --git a/Api-e004/WebContent/vista/js/guardarPunto.js b/Api-e004/WebContent/vista/js/guardarPunto.js index 14d29c0..f5f05eb 100644 --- a/Api-e004/WebContent/vista/js/guardarPunto.js +++ b/Api-e004/WebContent/vista/js/guardarPunto.js @@ -8,6 +8,9 @@ jQuery(function($){ url: 'http://localhost:8080/Api-e004/guardar', type: "POST", //dataType:"json", + headers:{ + apiKey: "pqntslc" + }, data:{ "lat": $("#latitudAlta").val(),//-25.2820464, "lon": $("#longitudAlta").val(),//-57.6129376, diff --git a/Api-e004/build/classes/controlador/GeoConexion.class b/Api-e004/build/classes/controlador/GeoConexion.class index b82db4d..633e732 100644 Binary files a/Api-e004/build/classes/controlador/GeoConexion.class and b/Api-e004/build/classes/controlador/GeoConexion.class differ diff --git a/Api-e004/build/classes/controlador/Prueba.class b/Api-e004/build/classes/controlador/Prueba.class deleted file mode 100644 index abf7a53..0000000 Binary files a/Api-e004/build/classes/controlador/Prueba.class and /dev/null differ diff --git a/Api-e004/src/api/GeoApi.java b/Api-e004/src/api/GeoApi.java index 7d9aa05..c742491 100644 --- a/Api-e004/src/api/GeoApi.java +++ b/Api-e004/src/api/GeoApi.java @@ -23,12 +23,15 @@ import modelo.PuntoGeografico; @WebServlet({ "/GeoApi", "/punto/*", "/guardar", "/buscar_puntos" }) public class GeoApi extends HttpServlet { private static final long serialVersionUID = 1L; + //El valor del api key + private String apiKey = "pqntslc"; /** * @see HttpServlet#HttpServlet() */ public GeoApi() { super(); + // TODO Auto-generated constructor stub } @@ -36,6 +39,11 @@ public class GeoApi extends HttpServlet { * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + //Para la validacion del api key + if(!request.getHeader("apiKey").equals(this.apiKey)) + response.sendError(401, "El api key es incorrecto"); + String url = request.getRequestURI(); String[] partes = url.split("/"); @@ -135,6 +143,10 @@ public class GeoApi extends HttpServlet { * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //Para la validacion del api key + if(!request.getHeader("apiKey").equals(this.apiKey)) + response.sendError(401, "El api key es incorrecto"); + // TODO Auto-generated method stub response.setContentType("application/json"); @@ -170,6 +182,10 @@ public class GeoApi extends HttpServlet { * @see HttpServlet#doDelete(HttpServletRequest, HttpServletResponse) */ protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //Para la validacion del api key + if(!request.getHeader("apiKey").equals(this.apiKey)) + response.sendError(401, "El api key es incorrecto"); + System.out.println("Ejecutando el delete"); //Extrae los parámetros del URL. ya que el url que llama a este servlet es diff --git a/Api-e004/src/controlador/GeoConexion.java b/Api-e004/src/controlador/GeoConexion.java index f1b41b6..010035c 100644 --- a/Api-e004/src/controlador/GeoConexion.java +++ b/Api-e004/src/controlador/GeoConexion.java @@ -4,21 +4,17 @@ package controlador; * @author pedro rolón */ -import java.util.ArrayList; + import java.sql.Connection; -import java.sql.DriverManager; + import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.SQLException; + import javax.naming.Context; import javax.naming.InitialContext; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; + import javax.sql.DataSource; import modelo.PuntoGeografico; diff --git a/Api-e004/src/controlador/Prueba.java b/Api-e004/src/controlador/Prueba.java deleted file mode 100644 index c48588a..0000000 --- a/Api-e004/src/controlador/Prueba.java +++ /dev/null @@ -1,60 +0,0 @@ -package controlador; - -import java.io.IOException; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import modelo.PuntoGeografico; -import controlador.GeoConexion; -/** - * Servlet implementation class Prueba - */ -@WebServlet({ "/Prueba", "/prueba","/prueba/*" }) -public class Prueba extends HttpServlet { - private static final long serialVersionUID = 1L; - - /** - * @see HttpServlet#HttpServlet() - */ - public Prueba() { - super(); - // TODO Auto-generated constructor stub - } - - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // TODO Auto-generated method stub - response.getWriter().append("Served at: ").append(request.getContextPath()); - - GeoConexion con = new GeoConexion(); - - float latitud=-25.2820216f; - float longitud=-57.6130814f; - String nombre="Cancha de tenis Herminio Gimenez"; - - - String url = request.getRequestURL().toString(); - String method = request.getMethod(); - - //System.out.println(request.getPathInfo().toString()); - - System.out.println(method); - System.out.println(url); - //hola - - } - - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // TODO Auto-generated method stub - doGet(request, response); - } - -} diff --git a/README.md b/README.md index 698ff4b..cfd3a31 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # Consideraciones * El API es un servlet llamado GeoApi, que utiliza la clase GeoConexion para interactuar con la base de datos. -* El proyecto posee interfaz gráfica, pero para ver lo que retorna es necesario abrir la consola del navegador por el momento. \ No newline at end of file +* El proyecto posee interfaz gráfica, pero para ver lo que retorna es necesario abrir la consola del navegador por el momento. +* El api key es "pqntslc". \ No newline at end of file -- libgit2 0.26.0