changes

parent d9f407d5
......@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;
......@@ -35,16 +36,20 @@ public class CorsFilter implements Filter{
response.setHeader("Access-Control-Allow-Headers","x-requested-with, Content-Type, Authorization");
response.setHeader("Access-Control-Allow-Credentials","true");
if((response.getHeader("Access-Control-Allow-Origin").equals("*") ||
response.getHeader("Access-Control-Allow-Origin").contains(request.getRemoteHost())) &&
(Arrays.asList(ExcelIds).contains(request.getHeader("Authorization")) || existeId(request.getHeader("Authorization")))){
try {
if((response.getHeader("Access-Control-Allow-Origin").equals("*") ||
response.getHeader("Access-Control-Allow-Origin").contains(request.getRemoteHost())) &&
(Arrays.asList(ExcelIds).contains(request.getHeader("Authorization")) || existeId(request.getHeader("Authorization")))){
filterChain.doFilter(servletRequest,response);
} else {
filterChain.doFilter(servletRequest,response);
} else {
response.setContentType("application/json");
response.setStatus(401);
response.getWriter().write("{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}");
response.setContentType("application/json");
response.setStatus(401);
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{
public void destroy(){
}
private Boolean existeId(String id){
private Boolean existeId(String id) throws SQLException{
AtomicReference<Boolean> existe=new AtomicReference<>(false);
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;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PostgreSqlTabla implements TablasDAO{
@Override
public JSONObject tablaIds(JSONObject json){
public JSONObject tablaIds(JSONObject json) throws SQLException{
JSONArray data = new JSONArray();
JSONObject respuesta = new JSONObject();
Connection conexion = null;
......@@ -50,6 +51,10 @@ public class PostgreSqlTabla implements TablasDAO{
}catch (Exception e){
respuesta.put("mensaje", e.getMessage());
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