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>");
+ }
}