From: rkv Date: Thu, 10 Jan 2013 12:42:45 +0000 (+0000) Subject: The bug related to the end of session is fixed. redirectOnEndOfSession interceptor... X-Git-Tag: Root_Delivery2_2013_04_22~190 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1ad9a9cae5ddc91cdb9e2815fc09e5fae18fbce3;p=tools%2Fsiman.git The bug related to the end of session is fixed. redirectOnEndOfSession interceptor is created. --- diff --git a/Workspace/Siman/src/org/splat/simer/AbstractRedirectAfterLoginInterceptor.java b/Workspace/Siman/src/org/splat/simer/AbstractRedirectAfterLoginInterceptor.java new file mode 100644 index 0000000..977b67c --- /dev/null +++ b/Workspace/Siman/src/org/splat/simer/AbstractRedirectAfterLoginInterceptor.java @@ -0,0 +1,106 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 10.01.2013 + * @author $Author$ + * @version $Revision$ + * @copyright OPEN CASCADE 2012 + *****************************************************************************/ + +package org.splat.simer; + +import org.splat.log.AppLogger; + +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.interceptor.Interceptor; + +/** + * The interceptor that redirect to a page after login. + * + * @author Roman Kozlov (RKV) + * + */ +public abstract class AbstractRedirectAfterLoginInterceptor implements + Interceptor { + + /** + * the logger. + */ + protected final static AppLogger LOG = AppLogger + .getLogger(AbstractRedirectAfterLoginInterceptor.class); + + /** + * The global result. + */ + private String _globalResult; + + /** + * Get the globalResult. + * + * @return the globalResult + */ + public String getGlobalResult() { + return _globalResult; + } + + /** + * Set the globalResult. + * + * @param globalResult + * the globalResult to set + */ + public void setGlobalResult(final String globalResult) { + _globalResult = globalResult; + } + + /** + * {@inheritDoc} + * + * @see com.opensymphony.xwork2.interceptor.Interceptor#destroy() + */ + public void destroy() { + LOG.debug("RedirectAfterLoginInterceptor destroyed."); + } + + /** + * {@inheritDoc} + * + * @see com.opensymphony.xwork2.interceptor.Interceptor#init() + */ + public void init() { + LOG.debug("RedirectAfterLoginInterceptor initialized."); + } + + /** + * {@inheritDoc} + * + * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation) + */ + public String intercept(final ActionInvocation invocation) throws Exception { //NOPMD: RKV: because of struts invoke() method + LOG.debug("RedirectAfterLoginInterceptor before rendering."); + + String result = getGlobalResult(); + + if (redirectCondition(invocation)) { + LOG.debug("RedirectAfterLoginInterceptor Redirection Needed"); + } else { + result = invocation.invoke(); + } + LOG.debug("RedirectAfterLoginInterceptor after rendering."); + return result; + } + + /** + * Return true if it must to redirect on the global result. + * + * @param invocation + * the Invocation + * @return boolean true if we need to redirect to the global result + * @throws Exception + * exception + */ + protected abstract boolean redirectCondition( + final ActionInvocation invocation) throws Exception; //NOPMD: RKV: because of struts invoke() method + +} diff --git a/Workspace/Siman/src/org/splat/simer/InvalidateAction.java b/Workspace/Siman/src/org/splat/simer/InvalidateAction.java new file mode 100644 index 0000000..d8ffcdd --- /dev/null +++ b/Workspace/Siman/src/org/splat/simer/InvalidateAction.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 10.01.2013 + * @author $Author$ + * @version $Revision$ + * @copyright OPEN CASCADE 2012 + *****************************************************************************/ + +package org.splat.simer; + +import java.util.Map; + +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.interceptor.SessionAware; + +import com.opensymphony.xwork2.ActionSupport; + +/** + * The action to invalidate http session. + * + * @author Roman Kozlov (RKV) + */ +public class InvalidateAction extends ActionSupport implements SessionAware { + + /** + * Serial version UID. + */ + private static final long serialVersionUID = -4418374434097351120L; + + /** + * Http session container. + */ + private Map _session; + + /** + * Invalidate the current session. + * @return "home" + */ + public String doInvalidate() { + if (_session != null) { + _session.clear(); + } + ServletActionContext.getRequest().getSession().invalidate(); + return SUCCESS; + } + + /** + * {@inheritDoc} + * @see org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map) + */ + @Override + public void setSession(final Map session) { + _session = session; + } +} diff --git a/Workspace/Siman/src/org/splat/simer/SimanRedirectOnEndOfSessionInterceptor.java b/Workspace/Siman/src/org/splat/simer/SimanRedirectOnEndOfSessionInterceptor.java new file mode 100644 index 0000000..5beec98 --- /dev/null +++ b/Workspace/Siman/src/org/splat/simer/SimanRedirectOnEndOfSessionInterceptor.java @@ -0,0 +1,81 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 10.01.2013 + * @author $Author$ + * @version $Revision$ + * @copyright OPEN CASCADE 2012 + *****************************************************************************/ + +package org.splat.simer; + +import org.apache.struts2.ServletActionContext; + +import com.opensymphony.xwork2.ActionInvocation; + +/** + * Redirect to a globalResult if the session has been invalidated. + * + * @author Roman Kozlov (RKV) + * + */ +public class SimanRedirectOnEndOfSessionInterceptor extends + AbstractRedirectAfterLoginInterceptor { + + /** + * Serial version UID. + */ + private static final long serialVersionUID = -2669940721820416684L; + + /** + * serialVersionUID. + */ + + /** + * globalResultActionName. + */ + private String _globalResultActionName; + + /** + * Get the globalResultActionName. + * + * @return the globalResultActionName + */ + public String getGlobalResultActionName() { + return _globalResultActionName; + } + + /** + * Set the globalResultActionName. + * + * @param globalResultActionName + * the globalResultActionName to set + */ + public void setGlobalResultActionName(final String globalResultActionName) { + _globalResultActionName = globalResultActionName; + } + + /** + * {@inheritDoc} + * + * @see org.splat.simer.AbstractRedirectAfterLoginInterceptor#redirectCondition(com.opensymphony.xwork2.ActionInvocation) + */ + @Override + protected boolean redirectCondition(final ActionInvocation invocation) + throws Exception { // NOPMD: RKV: because of struts invoke() method + String action = invocation.getInvocationContext().getName(); + boolean doRedirect = (!"index".equals(action)); + if (LOG.isDebugEnabled()) { + LOG.debug("Entering redirectCondition Test: " + action); + LOG + .debug("Do redirection: " + + (doRedirect && (ServletActionContext.getRequest() + .getSession().getAttribute( + Action.USER_RIGHTS) == null))); + } + return (doRedirect && (ServletActionContext.getRequest().getSession() + .getAttribute(Action.USER_RIGHTS) == null)); + } + +} diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index a919527..ade8fa1 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -41,6 +41,11 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + + + + @@ -96,7 +101,9 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> parent="openObject" scope="session"> - + + diff --git a/Workspace/Siman/src/struts.xml b/Workspace/Siman/src/struts.xml index 73adc9a..4df744a 100644 --- a/Workspace/Siman/src/struts.xml +++ b/Workspace/Siman/src/struts.xml @@ -22,10 +22,30 @@ class="org.apache.struts2.views.tiles.TilesResult" /> + + + + + + + + + + + + + + + exceptionAction + + index + / + @@ -56,6 +76,11 @@ page.test.json.exception --> + + page.home + + page.welcome page.exception