Commit 7918d928 by Percy Quispe

correcciones

parent de2ba4b5
package demojsoncrud.servlets; package demojsoncrud.servlets;
import demojsoncrud.utilities.GeneralUtils;
import demojsoncrud.utilities.PostRequest; import demojsoncrud.utilities.PostRequest;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
...@@ -72,7 +73,7 @@ public class RequestFilter implements Filter, ServletContextListener { ...@@ -72,7 +73,7 @@ public class RequestFilter implements Filter, ServletContextListener {
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
List<Object> salida=views.toList(); List<Object> salida=views.toList();
String ruta = request.getRequestURI(); String ruta = request.getRequestURI();
int indice = obtenerIndex(ruta); int indice = GeneralUtils.obtenerIndex(ruta);
String rutaJsp = ruta.substring(indice, ruta.length()); String rutaJsp = ruta.substring(indice, ruta.length());
if(url.contains(".jsp")){ if(url.contains(".jsp")){
boolean acceso = false; boolean acceso = false;
...@@ -85,8 +86,7 @@ public class RequestFilter implements Filter, ServletContextListener { ...@@ -85,8 +86,7 @@ public class RequestFilter implements Filter, ServletContextListener {
} }
if(!acceso){ if(!acceso){
Response.ResponseBuilder builder = null; Response.ResponseBuilder builder = null;
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); sendError(response);
response.sendError(401);
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());
} }
...@@ -94,28 +94,17 @@ public class RequestFilter implements Filter, ServletContextListener { ...@@ -94,28 +94,17 @@ public class RequestFilter implements Filter, ServletContextListener {
// List<String> views = (List<String>) ; // List<String> views = (List<String>) ;
chain.doFilter(request, response); chain.doFilter(request, response);
} else { } else {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); sendError(response);
response.sendError(401);
} }
} }
} else { } else {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); sendError(response);
response.sendError(401);
} }
} }
private int obtenerIndex(String ruta){
char[] c = ruta.toCharArray(); private void sendError (HttpServletResponse response) throws IOException{
int salida = 0; response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
for (int i = c.length-1; i >= 0; i--) { response.sendError(401);
String help = c[i]+"";
if(!help.equals("/")){
salida = i;
}else{
break;
}
}
return salida;
} }
@Override @Override
public void destroy() { public void destroy() {
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package demojsoncrud.utilities;
/**
*
* @author sistem08user
*/
public class GeneralUtils {
public static int obtenerIndex(String ruta){
char[] c = ruta.toCharArray();
int salida = 0;
for (int i = c.length-1; i >= 0; i--) {
String help = c[i]+"";
if(!help.equals("/")){
salida = i;
}else{
break;
}
}
return salida;
}
}
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