Source Code Cross Referenced for SessionInvalidationInterceptor.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » interceptor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » webwork 2.2.6 » com.opensymphony.webwork.interceptor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.interceptor;
006:
007:        import org.apache.commons.logging.Log;
008:        import org.apache.commons.logging.LogFactory;
009:
010:        import com.opensymphony.webwork.dispatcher.SessionMap;
011:        import com.opensymphony.xwork.ActionContext;
012:        import com.opensymphony.xwork.ActionInvocation;
013:        import com.opensymphony.xwork.interceptor.AroundInterceptor;
014:
015:        /**
016:         * <!-- START SNIPPET: description -->
017:         * This interceptor invalidates http session based on the type of operation it is in. 
018:         * There's three type of operations:-
019:         * <ul>
020:         * 	<li>NextRequest - This causes the interceptor to invalidate the session in 
021:         * 							      the next comming request where this interceptor is present in the
022:         * 								  interceptor stack. This interceptor mark this in the http session 
023:         * 								  using a key determined by the key attribute of this interceptor</li>
024:         * 	<li>Now - This causes this interceptor to invalidate the session at the end of 
025:         * 					 this interceptor's interception</li>
026:         * 	<li>NoOperation - This causes this interceptor to basically do nothing. 
027:         * 								   It is here such that users could have this interceptor in their
028:         * 							      default stack and still allows it to do nothing</li>
029:         * </ul>
030:         * <!-- END SNIPPET: description -->
031:         * 
032:         * <!-- START SNIPPET: extending -->
033:         * No intended extension points.
034:         * <!-- END SNIPPET: extending -->
035:         * 
036:         * <!-- START SNIPPET: parameters -->
037:         * <ul>
038:         * 	<li>type - indicate the operation of this interceptor, valid values are 'NextRequest', 'Now' and 'NoOperation'
039:         *                      See description above for more information.</li>
040:         *  	<li>key - this is the http session key used by the interceptor to mark the situation
041:         *  				   whereby the next comming request with this interceptor present in the 
042:         *  				   interception stack, it will invalidate the http session.</li>
043:         * </ul>
044:         * <!-- END SNIPPET: parameters -->
045:         * 
046:         * <pre>
047:         * <!-- START SNIPPET: example -->
048:         * 
049:         * &lt;action name="logout" ... &gt;
050:         * 	&lt;intereptor-ref name="sessionInvalidate"&gt;
051:         * 	    &lt;param name="type"&gt;Now&lt;/param&gt;
052:         *     &lt;/interceptor-ref&gt;
053:         *     ....
054:         * &lt;/action&gt;
055:         *   
056:         *  or 
057:         *  
058:         *  &lt;action name="sayByeByeNextRequestWillHaveSessionLost" ... &gt;
059:         *      &lt;interceptor-ref name="sessionInvalidate"&gt;
060:         *      	&lt;param name="type"&lt;NextRequest&lt;/param&gt;
061:         *      &lt;/interceptor-ref&gt;
062:         *      ....
063:         *  &lt;/action&gt;
064:         *  
065:         *  &lt;!-- This is the next request, "sessionInvalidate"  will find the marker inserted
066:         *          by the action above and invalidate the session --&gt;
067:         *  &lt;!-- The type="NoOperation" is just there so that the type is a valid one, and 
068:         *         we don't get a warning log meessage --&gt;        
069:         *  &lt;action name="nextRequest" ... &gt;
070:         *  	&lt;interceptor-ref name="sessionInvalidate"&gt;
071:         *  		&lt;param name="type"&gt;NoOperation&lt;/param&gt;
072:         *     &lt;/interceptor-ref&gt;
073:         *      ...
074:         *  &lt;/action&gt;
075:         * 
076:         * <!-- END SNIPPET: example -->
077:         * </pre>
078:         * 
079:         * @author tmjee
080:         * @version $Date: 2006-12-11 13:45:46 +0100 (Mon, 11 Dec 2006) $ $Id: SessionInvalidationInterceptor.java 2757 2006-12-11 12:45:46Z tmjee $
081:         */
082:        public class SessionInvalidationInterceptor extends AroundInterceptor {
083:
084:            private static final Log LOG = LogFactory
085:                    .getLog(SessionInvalidationInterceptor.class);
086:
087:            private static final long serialVersionUID = 1L;
088:
089:            public static String NEXT_REQUEST = "NextRequest";
090:            public static String NOW = "Now";
091:            public static String NO_OPERATION = "NoOperation";
092:
093:            protected String key = "___invalidateSession";
094:            protected String type = NO_OPERATION;
095:
096:            /**
097:             * Set the session key, of which this interceptor will use to mark if the next request 
098:             * with this interceptor in the stack should have the session invalidated.
099:             * @param key
100:             */
101:            public void setKey(String key) {
102:                this .key = key;
103:            }
104:
105:            /** 
106:             * Get the session key, of which this interceptor will use to mark if the next request 
107:             * with this interceptor in the stack should have the session invalidated.
108:             * @return String
109:             */
110:            public String getKey() {
111:                return this .key;
112:            }
113:
114:            /**
115:             * Set the operation type, either 'NextRequest', 'Now', or 'NoOperation' (default).
116:             * @param key
117:             */
118:            public void setType(String type) {
119:                this .type = type;
120:            }
121:
122:            /** 
123:             * Returns the operation type. 
124:             * @return String
125:             */
126:            public String getType() {
127:                return this .type;
128:            }
129:
130:            /**
131:             * Decides if this interceptor should invalidate the session or mark the session
132:             * to be invalidated upon the next request that contains this interceptor in the stack.
133:             * 
134:             * @see com.opensymphony.xwork.interceptor.AroundInterceptor#after(com.opensymphony.xwork.ActionInvocation, java.lang.String)
135:             */
136:            protected void after(ActionInvocation invocation, String result)
137:                    throws Exception {
138:                SessionMap sessionMap = (SessionMap) invocation
139:                        .getInvocationContext().get(ActionContext.SESSION);
140:                if (NOW.equalsIgnoreCase(type)) {
141:                    if (LOG.isDebugEnabled())
142:                        LOG.debug("type=now, invalidating session now");
143:                    sessionMap.invalidate();
144:                    LOG.info("session invalidated");
145:                } else if (NEXT_REQUEST.equalsIgnoreCase(type)) {
146:                    if (LOG.isDebugEnabled())
147:                        LOG
148:                                .debug("type=NextRequest, mark key in session, such that next request that have this interceptor will invalidate the session");
149:                    sessionMap.put(key, "true");
150:                } else if (NO_OPERATION.equalsIgnoreCase(type)) {
151:                    if (LOG.isDebugEnabled())
152:                        LOG.debug("no operation");
153:                } else {
154:                    LOG.warn("unrecognized type, type should be either " + NOW
155:                            + ", " + NEXT_REQUEST + " or " + NO_OPERATION);
156:                }
157:            }
158:
159:            /**
160:             * Invalidate this session if it is marked to be invalidated from previous request.
161:             * 
162:             * @see com.opensymphony.xwork.interceptor.AroundInterceptor#before(com.opensymphony.xwork.ActionInvocation)
163:             */
164:            protected void before(ActionInvocation invocation) throws Exception {
165:                SessionMap sessionMap = (SessionMap) invocation
166:                        .getInvocationContext().get(ActionContext.SESSION);
167:                if (sessionMap.containsKey(key)
168:                        && sessionMap.get(key).equals("true")) {
169:                    if (LOG.isDebugEnabled())
170:                        LOG
171:                                .debug("found marker in session indicating this is the 'next request', session should be invalidated");
172:                    sessionMap.invalidate();
173:                    LOG.info("session invalidated");
174:                }
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.