Commit 95cd8819 by Percy Quispe

Correcciones

parent 6e93dd29
...@@ -16,7 +16,7 @@ public class PersonaBean implements Serializable { ...@@ -16,7 +16,7 @@ public class PersonaBean implements Serializable {
public PersonaBean() { public PersonaBean() {
} }
public PersonaBean(PersonaBean persona) { public PersonaBean(PersonaBean persona) {
this.codigo = persona.getCodigo(); this.codigo = persona.getCodigo();
this.dni = persona.getDni(); this.dni = persona.getDni();
......
...@@ -4,6 +4,7 @@ import demojsoncrud.utilities.PostRequest; ...@@ -4,6 +4,7 @@ import demojsoncrud.utilities.PostRequest;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.List;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; import javax.servlet.FilterConfig;
...@@ -16,11 +17,14 @@ import javax.servlet.ServletResponse; ...@@ -16,11 +17,14 @@ import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter; import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@WebFilter("/*") @WebFilter("/*")
public class RequestFilter implements Filter, ServletContextListener { public class RequestFilter implements Filter, ServletContextListener {
private final String BASE = "http://localhost:8080/proyecto-estandar/";
@Override @Override
public void init(FilterConfig filterConfig) throws ServletException { public void init(FilterConfig filterConfig) throws ServletException {
...@@ -35,14 +39,16 @@ public class RequestFilter implements Filter, ServletContextListener { ...@@ -35,14 +39,16 @@ public class RequestFilter implements Filter, ServletContextListener {
String indexPath = "http://localhost:8080/proyecto-estandar/vistas/index.jsp"; String indexPath = "http://localhost:8080/proyecto-estandar/vistas/index.jsp";
String index = "vistas/index.jsp"; String index = "vistas/index.jsp";
String urlRequested = "http://172.16.2.53:8080/security-rest/api/user/verificarLogin"; String urlRequested = "http://172.16.2.53:8080/security-rest/api/user/verificarLogin";
System.out.println("URI "+request.getRequestURI());
if (String.valueOf(request.getRequestURL()).contains("http://localhost:8080/proyecto-estandar/")) { if (String.valueOf(request.getRequestURL()).contains(BASE)) {
String login = request.getContextPath() + "/vistas/index.jsp"; String login = request.getContextPath() + "/vistas/index.jsp";
String main = request.getContextPath() + "/vistas/main.jsp"; String main = request.getContextPath() + "/vistas/main.jsp";
String plantilla = request.getContextPath() + "/plantilla"; String plantilla = request.getContextPath() + "/plantilla";
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(main) || url.contains(".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"); String auth = request.getHeader("Authorization");
...@@ -50,6 +56,29 @@ public class RequestFilter implements Filter, ServletContextListener { ...@@ -50,6 +56,29 @@ public class RequestFilter implements Filter, ServletContextListener {
respuesta = postRequest.getRespueta(auth); respuesta = postRequest.getRespueta(auth);
JSONObject valid = new JSONObject(respuesta); JSONObject valid = new JSONObject(respuesta);
if (valid.getBoolean("status")) { if (valid.getBoolean("status")) {
JSONObject menu=new JSONObject(valid.getString("menu"));//Obtiene el menu
JSONArray views = new JSONArray(menu.get("vistas").toString());//Obtiene las vistas disponibles del usuario
List<Object> salida=views.toList();
String ruta = request.getRequestURI();
int indice = obtenerIndex(ruta);
String rutaJsp = ruta.substring(indice, ruta.length());
boolean acceso = false;
for(Object vista :views){
System.out.println("Vista : "+vista +"rutaJSP : "+rutaJsp);
if(vista.toString().equalsIgnoreCase(rutaJsp)){
acceso=true;
}
}
if(!acceso){
Response.ResponseBuilder builder = null;
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.sendError(401);
builder = Response.status(Response.Status.UNAUTHORIZED).entity(response);
throw new WebApplicationException(builder.build());
}
// List<String> views = (List<String>) ;
chain.doFilter(request, response); chain.doFilter(request, response);
} else { } else {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
...@@ -61,6 +90,20 @@ public class RequestFilter implements Filter, ServletContextListener { ...@@ -61,6 +90,20 @@ public class RequestFilter implements Filter, ServletContextListener {
response.sendError(401); response.sendError(401);
} }
} }
private 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;
}
@Override @Override
public void destroy() { public void destroy() {
......
...@@ -68,8 +68,16 @@ let getClosest = (elem, selector) => { ...@@ -68,8 +68,16 @@ let getClosest = (elem, selector) => {
return null return null
} }
let logOut = () =>{
document.querySelector('#logOut').addEventListener('click', (e) => {
Cookies.clear("menu");
Cookies.clear("Authorization");
// location.reload();
window.location.href = 'index.jsp'
})
}
logOut();
//document.querySelector('#logOut').addEventListener('click', (e) => { //document.querySelector('#logOut').addEventListener('click', (e) => {
// Cookies.clear('Authorization') // Cookies.clear('Authorization')
// Cookies.clear('menu') // Cookies.clear('menu')
......
...@@ -119,7 +119,6 @@ ubigeo ...@@ -119,7 +119,6 @@ ubigeo
}) })
.catch(err => { .catch(err => {
console.log(err) console.log(err)
debugger
window.location.replace("http://localhost:8080/proyecto-estandar/vistas/index.jsp"); window.location.replace("http://localhost:8080/proyecto-estandar/vistas/index.jsp");
//window.location.href("http://localhost:8080/proyecto-estandar/vistas/index.jsp"); //window.location.href("http://localhost:8080/proyecto-estandar/vistas/index.jsp");
......
///* global Cookies */ /* global Cookies */
//((window, Cookies) => { ((window, Cookies) => {
// console.log(Cookies.get('Authorization')) console.log(Cookies.get('Authorization'))
// if (Cookies.get('Authorization') === undefined) { if (Cookies.get('Authorization') === undefined) {
// window.location.href = "index.jsp" window.location.href = "index.jsp"
// } else { } else {
// console.log("Estas logueado") console.log("Estas logueado")
// } }
//})(window, Cookies); })(window, Cookies);
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