Source Code Cross Referenced for BaseSessionImpl.java in  » Authentication-Authorization » josso-1.7 » org » josso » gateway » session » service » 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 » Authentication Authorization » josso 1.7 » org.josso.gateway.session.service 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JOSSO: Java Open Single Sign-On
003:         *
004:         * Copyright 2004-2008, Atricore, Inc.
005:         *
006:         * This is free software; you can redistribute it and/or modify it
007:         * under the terms of the GNU Lesser General Public License as
008:         * published by the Free Software Foundation; either version 2.1 of
009:         * the License, or (at your option) any later version.
010:         *
011:         * This software is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this software; if not, write to the Free
018:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
020:         */
021:        package org.josso.gateway.session.service;
022:
023:        import org.apache.commons.logging.Log;
024:        import org.apache.commons.logging.LogFactory;
025:        import org.josso.Lookup;
026:        import org.josso.gateway.event.security.SSOSecurityEventManager;
027:
028:        /**
029:         * @author <a href="mailto:sgonzalez@josso.org">Sebastian Gonzalez Oyuela</a>
030:         * @version $Id: BaseSessionImpl.java 508 2008-02-18 13:32:29Z sgonzalez $
031:         */
032:
033:        public class BaseSessionImpl implements  BaseSession {
034:
035:            private static final Log logger = LogFactory
036:                    .getLog(BaseSessionImpl.class);
037:
038:            // This session identifier.
039:            protected String _id;
040:
041:            // Flag indicating if this session is valid.
042:            protected boolean _valid;
043:
044:            // Session creation time.
045:            protected long _creationTime;
046:
047:            // Session max inactive interval.
048:            protected int _maxInactiveInterval = -1;
049:
050:            // Session access time.
051:            protected long _lastAccessedTime;
052:
053:            // Session access count.
054:            protected long _accessCount;
055:
056:            // Indicates that this session is expiring.
057:            protected boolean _expiring;
058:
059:            // The username associated to this session
060:            protected String _username;
061:
062:            public BaseSessionImpl() {
063:            }
064:
065:            // ---------------------------------------------------------------
066:            // SSOSession interface.
067:            // ---------------------------------------------------------------
068:
069:            /**
070:             * The SSO Session id. This is a unique id.
071:             *
072:             * @return the session id.
073:             */
074:            public String getId() {
075:                return _id;
076:            }
077:
078:            /**
079:             * This method returns true if the session is valid.
080:             * It checks if this session should be expired.
081:             *
082:             * @return the session status.
083:             */
084:            public boolean isValid() {
085:
086:                if (!_valid) {
087:                    return _valid;
088:                }
089:
090:                if (_maxInactiveInterval >= 0) {
091:                    long timeNow = System.currentTimeMillis();
092:                    int timeIdle = (int) ((timeNow - _lastAccessedTime) / 1000L);
093:                    if (timeIdle >= _maxInactiveInterval) {
094:                        expire();
095:                    }
096:                }
097:
098:                return (_valid);
099:            }
100:
101:            /**
102:             * Set the maximum time interval, in seconds, between client requests
103:             * before the SSO Service will invalidate the session.  A negative
104:             * time indicates that the session should never time out.
105:             *
106:             * @param interval The new maximum interval
107:             */
108:            public void setMaxInactiveInterval(int interval) {
109:                _maxInactiveInterval = interval;
110:                isValid();
111:            }
112:
113:            public int getMaxInactiveInterval() {
114:                return _maxInactiveInterval;
115:            }
116:
117:            /**
118:             * Gets this session creation time in milliseconds.
119:             */
120:            public long getCreationTime() {
121:                return _creationTime;
122:            }
123:
124:            /**
125:             * Gets this session last access time in milliseconds.
126:             */
127:            public long getLastAccessTime() {
128:                return _lastAccessedTime;
129:            }
130:
131:            /**
132:             * Gets this session access count.
133:             */
134:            public long getAccessCount() {
135:                return _accessCount;
136:            }
137:
138:            // ----------------------------------------------------------
139:            // Base Session
140:            // ----------------------------------------------------------
141:
142:            /**
143:             * Update the accessed time information for this session.
144:             */
145:            public void access() {
146:
147:                _lastAccessedTime = System.currentTimeMillis();
148:
149:                // Check if the session is valid ...
150:                isValid();
151:
152:                _accessCount++;
153:
154:            }
155:
156:            /**
157:             * This method expires a session.  The isValid method will return false.
158:             */
159:            public void expire() {
160:
161:                setValid(false);
162:
163:                // Mark this session as "being expired" if needed
164:                if (_expiring)
165:                    return;
166:
167:                synchronized (this ) {
168:
169:                    _expiring = true;
170:                    _accessCount = 0;
171:                    setValid(false);
172:
173:                    // Notify interested session event listeners
174:                    fireSessionEvent(BaseSession.SESSION_DESTROYED_EVENT, null);
175:
176:                    // We have completed expire of this session
177:                    _expiring = false;
178:
179:                }
180:
181:            }
182:
183:            // -----------------------------------------------------------------------
184:            // Package utils
185:            // -----------------------------------------------------------------------
186:
187:            /**
188:             * Set the id of this session, used when initializing new sessions.
189:             *
190:             * @param id the session id.
191:             */
192:            public void setId(String id) {
193:                _id = id;
194:
195:                // Notify session event listeners
196:                fireSessionEvent(BaseSession.SESSION_CREATED_EVENT, null);
197:            }
198:
199:            /**
200:             * Set the creation time for this session.
201:             *
202:             * @param time The new creation time
203:             */
204:            public void setCreationTime(long time) {
205:                _creationTime = time;
206:                _lastAccessedTime = time;
207:            }
208:
209:            /**
210:             * Set the valid flag for this session.
211:             *
212:             * @param valid The new value for the valid property.
213:             */
214:            public void setValid(boolean valid) {
215:                _valid = valid;
216:            }
217:
218:            /**
219:             * Notify all session event listeners that a particular event has
220:             * occurred for this Session.  The default implementation performs
221:             * this notification synchronously using the calling thread.
222:             *
223:             * Note : Do not use this method outside the GWY ...
224:             *
225:             * @param type Event type
226:             * @param data Event data
227:             */
228:            public void fireSessionEvent(String type, Object data) {
229:
230:                try {
231:                    SSOSecurityEventManager em = (SSOSecurityEventManager) Lookup
232:                            .getInstance().lookupSecurityDomain()
233:                            .getEventManager();
234:                    em
235:                            .fireSessionEvent(this .getUsername(), getId(),
236:                                    type, data);
237:                } catch (Exception e) {
238:                    logger.error(
239:                            "Can't send session event : " + e.getMessage(), e);
240:                }
241:            }
242:
243:            /**
244:             * Getter for the username associated with this session, if any
245:             */
246:            public String getUsername() {
247:                return _username;
248:            }
249:
250:            /**
251:             * Setter for the username associated with this session
252:             */
253:            public void setUsername(String username) {
254:                _username = username;
255:            }
256:
257:            public String toString() {
258:                return _id + " [" + _username + "] "
259:                        + new java.util.Date(_creationTime);
260:            }
261:
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.