Source Code Cross Referenced for Token.java in  » Web-Server » Brazil » sunlabs » brazil » handler » 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 » Web Server » Brazil » sunlabs.brazil.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Token.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 1998-1999 Sun Microsystems, Inc.
007:         *
008:         * Sun Public License Notice
009:         *
010:         * The contents of this file are subject to the Sun Public License Version 
011:         * 1.0 (the "License"). You may not use this file except in compliance with 
012:         * the License. A copy of the License is included as the file "license.terms",
013:         * and also available at http://www.sun.com/
014:         * 
015:         * The Original Code is from:
016:         *    Brazil project web application Framework release 1.1.
017:         * The Initial Developer of the Original Code is: suhler.
018:         * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
019:         * All Rights Reserved.
020:         * 
021:         * Contributor(s): suhler.
022:         *
023:         * Version:  1.4
024:         * Created by suhler on 98/09/24
025:         * Last modified by suhler on 99/03/30 09:29:24
026:         */
027:
028:        package sunlabs.brazil.handler;
029:
030:        import java.util.Hashtable;
031:        import java.util.StringTokenizer;
032:        import java.util.Vector;
033:
034:        /**
035:         * Manage supplier.net session tokens.
036:         * Each token represents a "credentials lease" for a sun.net session.
037:         * Used by {@link SunNetAuthHandler}
038:         */
039:
040:        public class Token {
041:            static Hashtable tokens; // where to store the tokens
042:            long ctime; // token creation time
043:            long atime; // time of last use
044:            long now; // The current time
045:            int uses; // number of times token is used
046:            String id; // ID for this token (e.g. the smart card serial #)
047:            Vector roles; // The roles affiliated with this token
048:            Object arg; // client data pointer
049:
050:            /**
051:             * Initialize the hash table to hold all of the tokens
052:             */
053:
054:            static {
055:                tokens = new Hashtable();
056:            }
057:
058:            /**
059:             * Create a new token, put it in the hash table .
060:             * @param cookie	The reference for this token (e.g. web cookie)
061:             * This is called by getToken.
062:             */
063:
064:            private Token(String cookie) {
065:                now = System.currentTimeMillis();
066:                ctime = now;
067:                id = null;
068:                roles = null;
069:                uses = 0;
070:                arg = null;
071:                tokens.put(cookie, this );
072:            }
073:
074:            /**
075:             * Find the token assosiated with this cookie.
076:             * Create a new one if it doesn't exist
077:             */
078:
079:            public static Token getToken(String cookie) {
080:                Token result = (Token) tokens.get(cookie);
081:                if (result == null) {
082:                    result = new Token(cookie);
083:                }
084:                result.atime = result.now;
085:                result.now = System.currentTimeMillis();
086:                result.uses++;
087:                return result;
088:            }
089:
090:            /**
091:             * Check to see if a token exists
092:             * @return true if there was a token
093:             */
094:
095:            public static boolean haveToken(String cookie) {
096:                return tokens.containsKey(cookie);
097:            }
098:
099:            /**
100:             * Remove the token associated with this cookie
101:             * @return true if there was a token to remove
102:             */
103:
104:            public static boolean removeToken(String cookie) {
105:                return (cookie != null && tokens.remove(cookie) != null);
106:            }
107:
108:            /**
109:             * Set the id and roles associated with this token
110:             * @param id	The unique identifier for this token
111:             * @param roles     The white space delimited set of roles
112:             */
113:
114:            public void setToken(String id, String roles) {
115:                this .id = id;
116:                StringTokenizer st = new StringTokenizer(roles);
117:                this .roles = new Vector(st.countTokens());
118:                for (int i = 0; i < this .roles.capacity(); i++) {
119:                    this .roles.addElement(st.nextToken());
120:                }
121:            }
122:
123:            /**
124:             * Get the unique id associated with this token.
125:             */
126:
127:            public String getId() {
128:                return this .id;
129:            }
130:
131:            /**
132:             * Get the roles associated with this token
133:             */
134:
135:            public Vector getRoles() {
136:                return this .roles;
137:            }
138:
139:            /**
140:             * Get the number of uses of this token
141:             */
142:
143:            public int getUses() {
144:                return this .uses;
145:            }
146:
147:            /**
148:             * Get the total age of this token in seconds
149:             */
150:
151:            public int getAge() {
152:                return (int) ((this .now - this .ctime) / 1000);
153:            }
154:
155:            /**
156:             * Get the idle time of this token in seconds
157:             */
158:
159:            public int getIdle() {
160:                return (int) ((this .now - this .atime) / 1000);
161:            }
162:
163:            /**
164:             * Set the client data
165:             */
166:
167:            public void setArg(Object arg) {
168:                this .arg = arg;
169:            }
170:
171:            /**
172:             * Get the client data
173:             */
174:
175:            public Object getArg() {
176:                return this .arg;
177:            }
178:
179:            /**
180:             * Print a prettier version of this instance
181:             */
182:
183:            public String toString() {
184:                String list = "";
185:                return "times: " + ctime / 1000 + " - " + atime / 1000 + " - "
186:                        + now / 1000 + " total tokens: " + tokens.size()
187:                        + " uses: " + uses + " id: " + id + " roles:" + roles;
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.