changes

parent d9f407d5
...@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Provider;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
...@@ -35,6 +36,7 @@ public class CorsFilter implements Filter{ ...@@ -35,6 +36,7 @@ public class CorsFilter implements Filter{
response.setHeader("Access-Control-Allow-Headers","x-requested-with, Content-Type, Authorization"); response.setHeader("Access-Control-Allow-Headers","x-requested-with, Content-Type, Authorization");
response.setHeader("Access-Control-Allow-Credentials","true"); response.setHeader("Access-Control-Allow-Credentials","true");
try {
if((response.getHeader("Access-Control-Allow-Origin").equals("*") || if((response.getHeader("Access-Control-Allow-Origin").equals("*") ||
response.getHeader("Access-Control-Allow-Origin").contains(request.getRemoteHost())) && response.getHeader("Access-Control-Allow-Origin").contains(request.getRemoteHost())) &&
(Arrays.asList(ExcelIds).contains(request.getHeader("Authorization")) || existeId(request.getHeader("Authorization")))){ (Arrays.asList(ExcelIds).contains(request.getHeader("Authorization")) || existeId(request.getHeader("Authorization")))){
...@@ -46,6 +48,9 @@ public class CorsFilter implements Filter{ ...@@ -46,6 +48,9 @@ public class CorsFilter implements Filter{
response.setStatus(401); response.setStatus(401);
response.getWriter().write("{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}"); response.getWriter().write("{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}");
} }
} catch (SQLException e) {
throw new RuntimeException(e);
}
} }
...@@ -53,7 +58,7 @@ public class CorsFilter implements Filter{ ...@@ -53,7 +58,7 @@ public class CorsFilter implements Filter{
public void destroy(){ public void destroy(){
} }
private Boolean existeId(String id){ private Boolean existeId(String id) throws SQLException{
AtomicReference<Boolean> existe=new AtomicReference<>(false); AtomicReference<Boolean> existe=new AtomicReference<>(false);
JSONArray data=new PostgreSqlTabla().tablaIds(new JSONObject().put("tabla","ac_encuesta_plc")).getJSONArray("data"); JSONArray data=new PostgreSqlTabla().tablaIds(new JSONObject().put("tabla","ac_encuesta_plc")).getJSONArray("data");
......
...@@ -6,12 +6,13 @@ import pe.so.api.formulario.dao.TablasDAO; ...@@ -6,12 +6,13 @@ import pe.so.api.formulario.dao.TablasDAO;
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
public class PostgreSqlTabla implements TablasDAO{ public class PostgreSqlTabla implements TablasDAO{
@Override @Override
public JSONObject tablaIds(JSONObject json){ public JSONObject tablaIds(JSONObject json) throws SQLException{
JSONArray data = new JSONArray(); JSONArray data = new JSONArray();
JSONObject respuesta = new JSONObject(); JSONObject respuesta = new JSONObject();
Connection conexion = null; Connection conexion = null;
...@@ -50,6 +51,10 @@ public class PostgreSqlTabla implements TablasDAO{ ...@@ -50,6 +51,10 @@ public class PostgreSqlTabla implements TablasDAO{
}catch (Exception e){ }catch (Exception e){
respuesta.put("mensaje", e.getMessage()); respuesta.put("mensaje", e.getMessage());
return respuesta; return respuesta;
}finally {
if (conexion != null) {
conexion.close();
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment