Gestión de excepciones y fin de sesión
This commit is contained in:
@@ -2,4 +2,10 @@
|
|||||||
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd" version="2.3">
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd" version="2.3">
|
||||||
|
|
||||||
|
<!-- <factory> -->
|
||||||
|
<!-- <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory> -->
|
||||||
|
<!-- </factory> -->
|
||||||
|
<factory>
|
||||||
|
<exception-handler-factory>org.omnifaces.exceptionhandler.FacesMessageExceptionHandlerFactory</exception-handler-factory>
|
||||||
|
</factory>
|
||||||
</faces-config>
|
</faces-config>
|
||||||
|
|||||||
@@ -18,7 +18,10 @@
|
|||||||
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
|
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
|
||||||
<param-value>true</param-value>
|
<param-value>true</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
|
||||||
|
<param-value>client</param-value>
|
||||||
|
</context-param>
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
|
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
|
||||||
<param-value>.xhtml</param-value>
|
<param-value>.xhtml</param-value>
|
||||||
@@ -59,14 +62,29 @@
|
|||||||
<url-pattern>*.xhtml</url-pattern>
|
<url-pattern>*.xhtml</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<error-page>
|
||||||
|
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
|
||||||
|
<location>/error.xhtml?type=expired</location>
|
||||||
|
</error-page>
|
||||||
|
<error-page>
|
||||||
|
<exception-type>java.sql.SQLException</exception-type>
|
||||||
|
<location>/error.xhtml?type=sql</location>
|
||||||
|
</error-page>
|
||||||
|
<error-page>
|
||||||
|
<exception-type>java.lang.RuntimeException</exception-type>
|
||||||
|
<location>/error.xhtml?type=runtime</location>
|
||||||
|
</error-page>
|
||||||
<error-page>
|
<error-page>
|
||||||
<error-code>500</error-code>
|
<error-code>500</error-code>
|
||||||
<location>/error.xhtml</location>
|
<location>/error.xhtml</location>
|
||||||
</error-page>
|
</error-page>
|
||||||
|
<error-page>
|
||||||
|
<error-code>401</error-code>
|
||||||
|
<location>/error.xhtml?type=expired</location>
|
||||||
|
</error-page>
|
||||||
|
|
||||||
<session-config>
|
<session-config>
|
||||||
<session-timeout>30</session-timeout>
|
<session-timeout>1</session-timeout>
|
||||||
|
|
||||||
</session-config>
|
</session-config>
|
||||||
|
|
||||||
<!-- The Welcome File List -->
|
<!-- The Welcome File List -->
|
||||||
|
|||||||
@@ -13,14 +13,17 @@
|
|||||||
<p:panel id="ErrorPanel">
|
<p:panel id="ErrorPanel">
|
||||||
<f:facet name="header">
|
<f:facet name="header">
|
||||||
<p:outputLabel value="Se ha producido un error de autorización" rendered="#{param.type == 'auth'}" />
|
<p:outputLabel value="Se ha producido un error de autorización" rendered="#{param.type == 'auth'}" />
|
||||||
|
<p:outputLabel value="Su sesión ha caducado" rendered="#{param.type == 'expired'}" />
|
||||||
<p:outputLabel value="Se ha producido un error desconocido" rendered="#{param.type == null}" />
|
<p:outputLabel value="Se ha producido un error desconocido" rendered="#{param.type == null}" />
|
||||||
</f:facet>
|
</f:facet>
|
||||||
<div class="ui-g ui-fluid">
|
<div class="ui-g ui-fluid">
|
||||||
<div class="ui-g-12">La acción que estaba realizando a causado un error inesperado en el sistema. A continuación podrá ver un descripción detallada del error para que
|
<div class="ui-g-12">
|
||||||
pueda comunicarlo al equipo de soporte.</div>
|
<p:outputLabel rendered="#{param.type != 'expired'}"
|
||||||
|
value="La acción que estaba realizando a causado un error inesperado en el sistema. A continuación podrá ver un descripción detallada del error para que pueda comunicarlo al equipo de soporte." />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="ui-g-12" style="font-weight: bold;">
|
<div class="ui-g-12" style="font-weight: bold;">
|
||||||
<!-- <p:outputLabel value="No está autorizado a acceder a la página solicitada. Por favor, utilice el menú principal de la aplicación." rendered="#{param.type == 'auth'}" /> -->
|
<p:outputLabel value="Su sesión ha caducado. Por favor, incie sesión de nuevo en el sistema." rendered="#{param.type == 'expired'}" />
|
||||||
<!-- <p:outputLabel value="Se ha producido un error desconocido. Si vuelve a repetirse, por favor, contacte con el equipo de soporte." rendered="#{param.type == null}" /> -->
|
<!-- <p:outputLabel value="Se ha producido un error desconocido. Si vuelve a repetirse, por favor, contacte con el equipo de soporte." rendered="#{param.type == null}" /> -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,9 @@
|
|||||||
}
|
}
|
||||||
</h:outputScript>
|
</h:outputScript>
|
||||||
<h:body>
|
<h:body>
|
||||||
|
<p:growl id="messages" globalOnly="true" sticky="false" showDetail="true" life="15000" />
|
||||||
<div id="layout">
|
<div id="layout">
|
||||||
<div id="top" class="top">
|
<div id="top" class="top">
|
||||||
<p:growl id="messages" globalOnly="true" sticky="false" showDetail="true" life="15000" />
|
|
||||||
<h:graphicImage library="images" name="logo-small.png" />
|
<h:graphicImage library="images" name="logo-small.png" />
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
@@ -39,9 +39,7 @@
|
|||||||
<i id="loginSpin" class="pi pi-spin pi-spinner" style="font-size: 3em"></i>
|
<i id="loginSpin" class="pi pi-spin pi-spinner" style="font-size: 3em"></i>
|
||||||
</f:facet>
|
</f:facet>
|
||||||
|
|
||||||
<f:facet name="complete">
|
<f:facet name="error">Se ha producido un error!</f:facet>
|
||||||
<h:outputText value="" />
|
|
||||||
</f:facet>
|
|
||||||
</p:ajaxStatus>
|
</p:ajaxStatus>
|
||||||
|
|
||||||
<h:form id="frmLogin">
|
<h:form id="frmLogin">
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
package managedbean.common;
|
package managedbean.common;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Dictionary;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.faces.application.FacesMessage;
|
import javax.faces.application.FacesMessage;
|
||||||
|
import javax.faces.application.ViewExpiredException;
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
import javax.servlet.FilterConfig;
|
import javax.servlet.FilterConfig;
|
||||||
@@ -18,9 +16,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.primefaces.model.menu.DefaultSeparator;
|
|
||||||
import org.primefaces.model.menu.DefaultSubMenu;
|
|
||||||
|
|
||||||
import common.UserType;
|
import common.UserType;
|
||||||
|
|
||||||
@WebFilter(filterName = "AuthFilter", urlPatterns = { "*.xhtml" })
|
@WebFilter(filterName = "AuthFilter", urlPatterns = { "*.xhtml" })
|
||||||
@@ -39,20 +34,30 @@ public class AuthorizationFilter implements Filter {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
HttpServletRequest req = (HttpServletRequest) request;
|
HttpServletRequest req = (HttpServletRequest) request;
|
||||||
|
String reqURI = req.getRequestURI();
|
||||||
|
|
||||||
HttpServletResponse resp = (HttpServletResponse) response;
|
HttpServletResponse resp = (HttpServletResponse) response;
|
||||||
HttpSession ses = req.getSession(false);
|
HttpSession ses = req.getSession(false);
|
||||||
|
|
||||||
String reqURI = req.getRequestURI();
|
// Para recursos publicos permitimos el acceso exista sesión o no.
|
||||||
|
|
||||||
// Para recursos publicos permitimos el acceso
|
|
||||||
if (reqURI.indexOf("/login.xhtml") >= 0 || reqURI.indexOf("/profile/RegisterUser.xhtml") >= 0 || reqURI.indexOf("/home.xhtml") >= 0
|
if (reqURI.indexOf("/login.xhtml") >= 0 || reqURI.indexOf("/profile/RegisterUser.xhtml") >= 0 || reqURI.indexOf("/home.xhtml") >= 0
|
||||||
|| reqURI.indexOf("/error.xhtml") >= 0 || reqURI.indexOf("/public/") >= 0 || reqURI.contains("javax.faces.resource")) {
|
|| reqURI.indexOf("/error.xhtml") >= 0 || reqURI.indexOf("/public/") >= 0 || reqURI.contains("javax.faces.resource")) {
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si el usuario está logeado comprobamos si está autorizado a ver la página
|
// Sesión expirada
|
||||||
// solicitada.
|
if (req.isRequestedSessionIdValid() == false && req.getRequestedSessionId() != null) {
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
return;
|
||||||
|
//throw new ViewExpiredException("Session expired!", "error");
|
||||||
|
//resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
|
//SessionUtils.addMessage(ses, FacesMessage.SEVERITY_ERROR, "Su sesión ha caducado", "Su sesión ha caducado, por favor inicie sesión de nuevo.");
|
||||||
|
//resp.sendRedirect(req.getContextPath() + "/error.xhtml?type=expired");
|
||||||
|
//return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si el usuario está logeado comprobamos si está autorizado a ver la página solicitada.
|
||||||
if (SessionUtils.isLogedIn(ses) == true) {
|
if (SessionUtils.isLogedIn(ses) == true) {
|
||||||
UserType tipoUsuario = SessionUtils.getUserType(ses);
|
UserType tipoUsuario = SessionUtils.getUserType(ses);
|
||||||
boolean authorized = false;
|
boolean authorized = false;
|
||||||
@@ -130,7 +135,9 @@ public class AuthorizationFilter implements Filter {
|
|||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
SessionUtils.addMessage(ses, FacesMessage.SEVERITY_ERROR, "No está autorizado a acceder a la página solicitada. Por favor, utilice el menú principal de la aplicación.", String.format("Se ha producido una expción de autorización, su usuario no está autorizado a acceder a la página: (%s).", reqURI));
|
SessionUtils.addMessage(ses, FacesMessage.SEVERITY_ERROR,
|
||||||
|
"No está autorizado a acceder a la página solicitada. Por favor, utilice el menú principal de la aplicación.",
|
||||||
|
String.format("Se ha producido una expción de autorización, su usuario no está autorizado a acceder a la página: (%s).", reqURI));
|
||||||
resp.sendRedirect(req.getContextPath() + "/error.xhtml?type=auth");
|
resp.sendRedirect(req.getContextPath() + "/error.xhtml?type=auth");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user