Commit 0969167d by Billy Larru

Correcion de errores

parent 37b3bc91
......@@ -10,9 +10,7 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
......@@ -39,11 +37,6 @@ import asistencia.utilities.HttpRequest;
@WebFilter(filterName = "RequestFilter", urlPatterns = {"/*"})
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
// this value is null, this filter instance is not currently
// configured.
......@@ -57,68 +50,75 @@ public class RequestFilter implements Filter {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
String uri = request.getRequestURI();
String url = String.valueOf(request.getRequestURL());
if (url.equalsIgnoreCase(OWN_DOMAIN) || url.equalsIgnoreCase(OWN_DOMAIN_)
||url.equalsIgnoreCase(OWN_IP)|| url.equalsIgnoreCase(OWN_IP_)
if (uri.endsWith("Asistencia") || uri.endsWith("Asistencia/")
|| uri.contains("vistas/index.jsp")
|| uri.contains("vistas/templates")
|| uri.contains("plantilla/assets") || uri.endsWith(".js") || uri.endsWith(".css")
|| uri.endsWith(".png") || uri.endsWith(".jpg") || uri.endsWith(".gif")
|| uri.contains("/login") || uri.contains("vistas/redireccionarServlet")
|| uri.contains("vistas/interceptar")) {
chain.doFilter(request, response);
} else {
String respuesta = "";
if (request.getSession().getAttribute("codigo") != null) {
if (uri.endsWith(".jsp")) {
HttpSession session = request.getSession();
if (session.getAttribute("codigo") != null) {
HttpRequest httpRequest = new HttpRequest();
JSONObject valid = null;
String respuesta = "";
String auth = "";
try {
if (session.getAttribute("Authorization") != null) {
auth = (String) session.getAttribute("Authorization");
} else {
setError(response);
}
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);
List<Object> vistas = new ArrayList<>();
JSONObject rolvista = valid.getJSONObject("rolvista");
JSONArray urls = rolvista.getJSONArray("vistas");
vistas = urls.toList();
vistas.add("main.jsp");//Agregando la vista principal
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());
if (url.endsWith(".jsp")) {
boolean acceso = vistas.contains(rutaJsp);
if (!acceso) {
setError(response);
}
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());
chain.doFilter(request, response);
} else {
deleteCredenciales(request, response);
request.getRequestDispatcher("/vistas/index.jsp").forward(request, response);
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);
}
}
chain.doFilter(request, response);
} 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", "");
cookieAuth.setMaxAge(0);
request.getSession().invalidate();
......
......@@ -33,12 +33,12 @@
<url-pattern>/vistas/redireccionarServlet</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/vistas/404.jsp</location>
</error-page>
<session-config>
<session-timeout>
30
......
......@@ -147,6 +147,6 @@ let block = () => {
let logOut = () => {
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 = {
$.unblockUI();
console.log(data)
if(data.status){
window.location.href=PATH_IP+"vistas/main.jsp";
window.location.href="../vistas/main.jsp";
}else{
customSwal.alert('¡Error!', "Usuario o contraseña incorrecto.", 'error')
}
......
<%--
Document : error
Created on : 23/06/2018, 12:18:11 PM
Document : 404
Created on : 25/06/2018, 10:21:24 AM
Author : sistem19user
--%>
......@@ -12,6 +12,6 @@
<title>JSP Page</title>
</head>
<body>
<h1>Pagina no encontrada</h1>
<h1>PAGINA NO ENCONTRADA</h1>
</body>
</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"%>
<!DOCTYPE html>
<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