import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.RequestProcessor;
-import com.google.gwt.user.client.Window;
-
+import fr.gouv.finances.dgfip.xemelios.auth.UnauthorizedException;
import fr.gouv.finances.dgfip.xemelios.auth.XemeliosUser;
+import fr.gouv.finances.dgfip.xemelios.web2.gwt.shared.DisconnectedException;
import fr.gouv.finances.dgfip.xemelios.web2.utils.AttributeHelper;
//rustine pour l'expiration de session
if(roles != null && roles.length > 0 && user == null){
- ServletOutputStream out = response.getOutputStream();
- String loginPage = request.getContextPath() + "/connexion.do?" + org.apache.struts.Globals.ERROR_KEY + "=" + URLEncoder.encode("Votre session a expiré.", "UTF-8");
-
- out.print("<html><head><script type=\"text/javascript\">top.document.location.href='"+loginPage+"';</script></head></html>");
-
- //Window.Location.replace(request.getContextPath() + "/connexion.do?" + org.apache.struts.Globals.ERROR_KEY + "=" + URLEncoder.encode("Votre session a expiré.", "UTF-8"));
- //response.sendRedirect(request.getContextPath() + "/connexion.do?" + org.apache.struts.Globals.ERROR_KEY + "=" + URLEncoder.encode("Votre session a expiré.", "UTF-8"));
+ redirectToLogin(request, response);
return false;
}
return true;
}
+ @Override
+ protected ActionForward processException(HttpServletRequest request, HttpServletResponse response, Exception e, ActionForm arg3, ActionMapping mapping) throws IOException, ServletException {
+ ActionForward toGo = null;
+
+ request.setAttribute("exception", e);
+
+ if(e instanceof DisconnectedException){
+ redirectToLogin(request, response);
+ }else if(e instanceof UnauthorizedException){
+ toGo = mapping.findForward("denied");
+ }else{
+ toGo = mapping.findForward("error");
+ }
+
+ return toGo;
+ }
+
+
+ private void redirectToLogin(HttpServletRequest request, HttpServletResponse response) throws IOException{
+ ServletOutputStream out = response.getOutputStream();
+ String loginPage = request.getContextPath() + "/connexion.do?" + org.apache.struts.Globals.ERROR_KEY + "=" + URLEncoder.encode("Votre session a expiré.", "UTF-8");
+
+ out.print("<html><head><script type=\"text/javascript\">top.document.location.href='"+loginPage+"';</script></head></html>");
+ }
}
--- /dev/null
+<%@page import="fr.gouv.finances.dgfip.xemelios.auth.UnauthorizedException"%>
+<%@page import="java.io.StringWriter"%>
+<%@page import="java.io.PrintWriter"%>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Non-autorisé</title>
+</head>
+<body>
+ <% UnauthorizedException e = (UnauthorizedException) request.getAttribute("exception"); %>
+ <h1><%= e.getMessage() %></h1>
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<%@page import="java.io.PrintWriter"%>
+<%@page import="java.io.StringWriter"%>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Erreur inattendue</title>
+</head>
+<body>
+ <% Exception e = (Exception)request.getAttribute("exception"); %>
+ <h1>Une erreur inattendue est survenue : <%= (e == null ? "" : e.getMessage()) %></h1>
+ <pre>
+ <%
+ if (e != null) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pwt = new PrintWriter(sw);
+ e.printStackTrace(pwt);
+
+ out.write(sw.toString());
+ }
+ %>
+ </pre>
+ </body>
+</html>
\ No newline at end of file
<global-forwards>
<forward name="login" path="/connexion"/>
+ <forward name="denied" path="/WEB-INF/jsp/denied.jsp"/>
+ <forward name="error" path="/WEB-INF/jsp/error.jsp"/>
</global-forwards>
- <action-mappings>
+ <action-mappings>
<action path="/connexion" parameter="dispatchMethod" input="/WEB-INF/jsp/connexion.jsp" validate="false" scope="request" type="fr.gouv.finances.dgfip.xemelios.web2.connexion.ConnexionAction" name="connexionForm">
<forward name="success" path="/welcomeGWT.html?gwt.codesvr=127.0.0.1:9997" redirect="true"/>
<forward name="not.allowed.browser" path="/browserNotAllowed.jsp" redirect="true"/>