Commit 0969167d by Billy Larru

Correcion de errores

parent 37b3bc91
...@@ -10,9 +10,7 @@ import java.io.PrintStream; ...@@ -10,9 +10,7 @@ import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; import javax.servlet.FilterConfig;
...@@ -39,11 +37,6 @@ import asistencia.utilities.HttpRequest; ...@@ -39,11 +37,6 @@ import asistencia.utilities.HttpRequest;
@WebFilter(filterName = "RequestFilter", urlPatterns = {"/*"}) @WebFilter(filterName = "RequestFilter", urlPatterns = {"/*"})
public class RequestFilter implements Filter { public class RequestFilter implements Filter {
private static final String OWN_DOMAIN = "http://172.16.2.102:7070/Asistencia";
private static final String OWN_DOMAIN_ = OWN_DOMAIN + "/";
private static final String OWN_IP = "http://localhost:7070/Asistencia" ;
private static final String OWN_IP_ = OWN_IP + "/";
// The filter configuration object we are associated with. If // The filter configuration object we are associated with. If
// this value is null, this filter instance is not currently // this value is null, this filter instance is not currently
// configured. // configured.
...@@ -57,68 +50,75 @@ public class RequestFilter implements Filter { ...@@ -57,68 +50,75 @@ public class RequestFilter implements Filter {
HttpServletRequest request = (HttpServletRequest) req; HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp; HttpServletResponse response = (HttpServletResponse) resp;
String uri = request.getRequestURI(); String uri = request.getRequestURI();
String url = String.valueOf(request.getRequestURL());
if (url.equalsIgnoreCase(OWN_DOMAIN) || url.equalsIgnoreCase(OWN_DOMAIN_) if (uri.endsWith("Asistencia") || uri.endsWith("Asistencia/")
||url.equalsIgnoreCase(OWN_IP)|| url.equalsIgnoreCase(OWN_IP_)
|| uri.contains("vistas/index.jsp") || uri.contains("vistas/index.jsp")
|| uri.contains("vistas/templates")
|| uri.contains("plantilla/assets") || uri.endsWith(".js") || uri.endsWith(".css") || uri.contains("plantilla/assets") || uri.endsWith(".js") || uri.endsWith(".css")
|| uri.endsWith(".png") || uri.endsWith(".jpg") || uri.endsWith(".gif") || uri.endsWith(".png") || uri.endsWith(".jpg") || uri.endsWith(".gif")
|| uri.contains("/login") || uri.contains("vistas/redireccionarServlet") || uri.contains("/login") || uri.contains("vistas/redireccionarServlet")
|| uri.contains("vistas/interceptar")) { || uri.contains("vistas/interceptar")) {
chain.doFilter(request, response); chain.doFilter(request, response);
} else { } else {
String respuesta = ""; if (request.getSession().getAttribute("codigo") != null) {
HttpSession session = request.getSession(); if (uri.endsWith(".jsp")) {
if (session.getAttribute("codigo") != null) { HttpSession session = request.getSession();
HttpRequest httpRequest = new HttpRequest(); HttpRequest httpRequest = new HttpRequest();
JSONObject valid = null; JSONObject valid = null;
String auth = ""; String respuesta = "";
if (session.getAttribute("Authorization") != null) { String auth = "";
auth = (String) session.getAttribute("Authorization"); try {
} else { if (session.getAttribute("Authorization") != null) {
setError(response); auth = (String) session.getAttribute("Authorization");
} } else {
try {
respuesta = httpRequest.getRespuesta(RequestPath.VERIFICAR_LOGIN, HttpRequest.POST, new JSONObject("{}"), auth);
} catch (Exception ex) {
setError(response);
}
valid = new JSONObject(respuesta);
if (valid.getBoolean("status")) {
List<Object> vistas = new ArrayList<>();
JSONObject menu = new JSONObject(valid.getString("menu"));//Obtiene el menu
System.out.println("valid " + valid);
JSONObject rolvista = valid.getJSONObject("rolvista");
JSONArray urls = rolvista.getJSONArray("vistas");
vistas = urls.toList();
vistas.add("main.jsp");//Agregando la vista principal
String ruta = request.getRequestURI();
int indice = GeneralUtils.obtenerIndex(ruta);
String rutaJsp = ruta.substring(indice, ruta.length());
if (url.endsWith(".jsp")) {
boolean acceso = vistas.contains(rutaJsp);
if (!acceso) {
setError(response); setError(response);
} }
respuesta = httpRequest.getRespuesta(RequestPath.VERIFICAR_LOGIN, HttpRequest.POST, new JSONObject("{}"), auth);
valid = new JSONObject(respuesta);
if (valid.getBoolean("status")) {
JSONObject menu = new JSONObject(valid.getString("menu"));//Obtiene el menu
List<Object> vistas = new ArrayList<>();
JSONObject rolvista = valid.getJSONObject("rolvista");
JSONArray urls = rolvista.getJSONArray("vistas");
for (int i = 0; i < urls.length(); i++) {
vistas.add(urls.get(i));
}
vistas.add("main.jsp");
String ruta = request.getRequestURI();
int indice = GeneralUtils.obtenerIndex(ruta);
String rutaJsp = ruta.substring(indice, ruta.length());
boolean acceso = vistas.contains(rutaJsp);
if (!acceso) {
request.getSession().setAttribute("error", "no tiene acceso a la vista solicitada");//Esta session se elimina en el jsp (para que no ocupe memoria)
// request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
response.sendRedirect("error.jsp");
return;
}
session.setAttribute("menu", menu.toString());
} else {
deleteCredenciales(response, request);
request.getSession().setAttribute("error", "no tiene credenciales validas");
// request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
response.sendRedirect("error.jsp");
return;
// setError(response);
}
} catch (Exception ex) {
request.getSession().setAttribute("error", ex.getMessage());
// request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
response.sendRedirect("error.jsp");
return;
// setError(response);
} }
session.setAttribute("menu", menu.toString());
chain.doFilter(request, response);
} else {
deleteCredenciales(request, response);
request.getRequestDispatcher("/vistas/index.jsp").forward(request, response);
} }
chain.doFilter(request, response);
} else { } else {
request.getRequestDispatcher("/vistas/index.jsp").forward(request, response); deleteCredenciales(response, request);
response.sendRedirect("index.jsp");
} }
} }
} }
private void deleteCredenciales(HttpServletRequest request, HttpServletResponse response) { private void deleteCredenciales(HttpServletResponse response, HttpServletRequest request) {
Cookie cookieAuth = new Cookie("Authorization", ""); Cookie cookieAuth = new Cookie("Authorization", "");
cookieAuth.setMaxAge(0); cookieAuth.setMaxAge(0);
request.getSession().invalidate(); request.getSession().invalidate();
......
...@@ -33,12 +33,12 @@ ...@@ -33,12 +33,12 @@
<url-pattern>/vistas/redireccionarServlet</url-pattern> <url-pattern>/vistas/redireccionarServlet</url-pattern>
</servlet-mapping> </servlet-mapping>
<error-page> <error-page>
<error-code>404</error-code> <error-code>404</error-code>
<location>/vistas/404.jsp</location> <location>/vistas/404.jsp</location>
</error-page> </error-page>
<session-config> <session-config>
<session-timeout> <session-timeout>
30 30
......
...@@ -147,6 +147,6 @@ let block = () => { ...@@ -147,6 +147,6 @@ let block = () => {
let logOut = () => { let logOut = () => {
document.querySelector('#logOut').addEventListener('click', (e) => { document.querySelector('#logOut').addEventListener('click', (e) => {
window.location.href = PATH_IP + 'vistas/logout'; window.location.href = '../vistas/logout';
}); });
}; };
\ No newline at end of file
...@@ -47,7 +47,7 @@ const DOMEvents = { ...@@ -47,7 +47,7 @@ const DOMEvents = {
$.unblockUI(); $.unblockUI();
console.log(data) console.log(data)
if(data.status){ if(data.status){
window.location.href=PATH_IP+"vistas/main.jsp"; window.location.href="../vistas/main.jsp";
}else{ }else{
customSwal.alert('¡Error!', "Usuario o contraseña incorrecto.", 'error') customSwal.alert('¡Error!', "Usuario o contraseña incorrecto.", 'error')
} }
......
<%-- <%--
Document : error Document : 404
Created on : 23/06/2018, 12:18:11 PM Created on : 25/06/2018, 10:21:24 AM
Author : sistem19user Author : sistem19user
--%> --%>
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
<title>JSP Page</title> <title>JSP Page</title>
</head> </head>
<body> <body>
<h1>Pagina no encontrada</h1> <h1>PAGINA NO ENCONTRADA</h1>
</body> </body>
</html> </html>
<%--
Document : error
Created on : 23/06/2018, 12:18:11 PM
Author : sistem19user
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>OCURRIÓ UN ERROR EN LA PAGINA</h1>
</body>
</html>
<%--<%@include file="templates/validar.jsp" %>--%> <%@include file="templates/validar.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
......
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