Commit de2ba4b5 by Percy Quispe

Correciones

parent 95cd8819
...@@ -47,14 +47,26 @@ public class RequestFilter implements Filter, ServletContextListener { ...@@ -47,14 +47,26 @@ public class RequestFilter implements Filter, ServletContextListener {
String js = request.getContextPath() + "/js"; String js = request.getContextPath() + "/js";
String url = String.valueOf(request.getRequestURL()); String url = String.valueOf(request.getRequestURL());
if (url.contains(login) || url.contains(plantilla) || url.contains(js)|| url.contains("index.jsp")||url.contains("main.jsp") if (url.contains(login) || url.contains(plantilla) || url.contains(js)|| url.contains("index.jsp")||url.contains("main.jsp")) {
|| url.contains(BASE)) {
chain.doFilter(request, response); chain.doFilter(request, response);
} else { } else {
String auth = request.getHeader("Authorization"); JSONObject valid = null;
String auth = "";
if(url.contains(".jsp")){
auth = request.getHeader("Cookie");
if(auth.contains("Bearer")){
String[] parts = auth.split(";");
String authorization = parts[0];
parts = authorization.split("%20");
auth = "Bearer "+parts[1];
System.out.println(auth);
}
}else{
auth = request.getHeader("Authorization");
}
PostRequest postRequest = new PostRequest(urlRequested); PostRequest postRequest = new PostRequest(urlRequested);
respuesta = postRequest.getRespueta(auth); respuesta = postRequest.getRespueta(auth);
JSONObject valid = new JSONObject(respuesta); valid = new JSONObject(respuesta);
if (valid.getBoolean("status")) { if (valid.getBoolean("status")) {
JSONObject menu=new JSONObject(valid.getString("menu"));//Obtiene el menu JSONObject menu=new JSONObject(valid.getString("menu"));//Obtiene el menu
JSONArray views = new JSONArray(menu.get("vistas").toString());//Obtiene las vistas disponibles del usuario JSONArray views = new JSONArray(menu.get("vistas").toString());//Obtiene las vistas disponibles del usuario
...@@ -62,12 +74,13 @@ public class RequestFilter implements Filter, ServletContextListener { ...@@ -62,12 +74,13 @@ public class RequestFilter implements Filter, ServletContextListener {
String ruta = request.getRequestURI(); String ruta = request.getRequestURI();
int indice = obtenerIndex(ruta); int indice = obtenerIndex(ruta);
String rutaJsp = ruta.substring(indice, ruta.length()); String rutaJsp = ruta.substring(indice, ruta.length());
if(url.contains(".jsp")){
boolean acceso = false; boolean acceso = false;
for(Object vista :views){ for(Object vista :views){
System.out.println("Vista : "+vista +"rutaJSP : "+rutaJsp); System.out.println("Vista : "+vista +"rutaJSP : "+rutaJsp);
if(vista.toString().equalsIgnoreCase(rutaJsp)){ if(vista.toString().equalsIgnoreCase(rutaJsp)){
acceso=true; acceso=true;
break;
} }
} }
if(!acceso){ if(!acceso){
...@@ -77,7 +90,7 @@ public class RequestFilter implements Filter, ServletContextListener { ...@@ -77,7 +90,7 @@ public class RequestFilter implements Filter, ServletContextListener {
builder = Response.status(Response.Status.UNAUTHORIZED).entity(response); builder = Response.status(Response.Status.UNAUTHORIZED).entity(response);
throw new WebApplicationException(builder.build()); throw new WebApplicationException(builder.build());
} }
}
// List<String> views = (List<String>) ; // List<String> views = (List<String>) ;
chain.doFilter(request, response); chain.doFilter(request, response);
} else { } else {
......
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