--- /dev/null
+/*****************************************************************************
+ * 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 <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ *
+ */
+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
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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 <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public class InvalidateAction extends ActionSupport implements SessionAware {
+
+ /**
+ * Serial version UID.
+ */
+ private static final long serialVersionUID = -4418374434097351120L;
+
+ /**
+ * Http session container.
+ */
+ private Map<String, Object> _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<String, Object> session) {
+ _session = session;
+ }
+}
--- /dev/null
+/*****************************************************************************
+ * 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 <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ *
+ */
+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));
+ }
+
+}
<property name="documentTypeService" ref="documentTypeService" />
</bean>
+ <bean id="redirectOnEndOfSessionInterceptor"
+ class="org.splat.simer.SimanRedirectOnEndOfSessionInterceptor">
+ <property name="globalResult" value="home" />
+ </bean>
+
<bean id="menuBarSettings" class="org.splat.simer.MenuBarSettings"
scope="session">
</bean>
parent="openObject" scope="session">
</bean>
- <bean id="baseAction" class="org.splat.simer.Action"
+ <bean id="invalidateAction" class="org.splat.simer.InvalidateAction"/>
+
+ <bean id="baseAction" class="org.splat.simer.Action"
scope="prototype" abstract="true">
<property name="applicationSettings" ref="applicationSettings" />
<property name="openStudy" ref="openStudy" />
class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
+ <interceptors>
+ <interceptor name="redirectOnEndOfSession"
+ class="redirectOnEndOfSessionInterceptor" />
+
+ <interceptor-stack name="simanBasicStack">
+ <interceptor-ref name="exception" />
+ <interceptor-ref name="servletConfig" />
+ <interceptor-ref name="redirectOnEndOfSession" />
+ <interceptor-ref name="prepare" />
+ <interceptor-ref name="checkbox" />
+ <interceptor-ref name="params" />
+ </interceptor-stack>
+ </interceptors>
+
+ <default-interceptor-ref name="simanBasicStack" />
+
<global-results>
<result name="exception" type="chain">
exceptionAction
</result>
+ <result name="home" type="redirectAction">
+ <param name="actionName">index</param>
+ <param name="namespace">/</param>
+ </result>
</global-results>
<global-exception-mappings>
<result name="success" type="tiles">page.test.json.exception</result>
</action>
-->
+ <action name="invalidate-session" class="invalidateAction"
+ method="invalidate">
+ <result name="success" type="tiles">page.home</result>
+ </action>
+
<action name="index" class="startAction" method="initialize">
<result name="success" type="tiles">page.welcome</result>
<result name="error" type="tiles">page.exception</result>