Salome HOME
The bug related to the end of session is fixed. redirectOnEndOfSession interceptor...
authorrkv <rkv@opencascade.com>
Thu, 10 Jan 2013 12:42:45 +0000 (12:42 +0000)
committerrkv <rkv@opencascade.com>
Thu, 10 Jan 2013 12:42:45 +0000 (12:42 +0000)
Workspace/Siman/src/org/splat/simer/AbstractRedirectAfterLoginInterceptor.java [new file with mode: 0644]
Workspace/Siman/src/org/splat/simer/InvalidateAction.java [new file with mode: 0644]
Workspace/Siman/src/org/splat/simer/SimanRedirectOnEndOfSessionInterceptor.java [new file with mode: 0644]
Workspace/Siman/src/spring/applicationContext.xml
Workspace/Siman/src/struts.xml

diff --git a/Workspace/Siman/src/org/splat/simer/AbstractRedirectAfterLoginInterceptor.java b/Workspace/Siman/src/org/splat/simer/AbstractRedirectAfterLoginInterceptor.java
new file mode 100644 (file)
index 0000000..977b67c
--- /dev/null
@@ -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 <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
+
+}
diff --git a/Workspace/Siman/src/org/splat/simer/InvalidateAction.java b/Workspace/Siman/src/org/splat/simer/InvalidateAction.java
new file mode 100644 (file)
index 0000000..d8ffcdd
--- /dev/null
@@ -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 <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;
+       }
+}
diff --git a/Workspace/Siman/src/org/splat/simer/SimanRedirectOnEndOfSessionInterceptor.java b/Workspace/Siman/src/org/splat/simer/SimanRedirectOnEndOfSessionInterceptor.java
new file mode 100644 (file)
index 0000000..5beec98
--- /dev/null
@@ -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 <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));
+       }
+
+}
index a91952736c8766451225a6e6a74212543e20c846..ade8fa1a9f1dbbb9ccca041e2644afcf568ac5f9 100644 (file)
@@ -41,6 +41,11 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                <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>
@@ -96,7 +101,9 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                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" />
index 73adc9a324c2cd5a2f6fa4c3811eb7d31a050f63..4df744a72d71c3b5dc5c9f77d9d75ab5b27c6d78 100644 (file)
                                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>