Source Code Cross Referenced for SerializablePrincipal.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » catalina » ha » session » 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 » Sevlet Container » apache tomcat 6.0.14 » org.apache.catalina.ha.session 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.catalina.ha.session;
019:
020:        import java.util.Arrays;
021:        import java.util.List;
022:        import org.apache.catalina.Realm;
023:
024:        /**
025:         * Generic implementation of <strong>java.security.Principal</strong> that
026:         * is available for use by <code>Realm</code> implementations.
027:         * The GenericPrincipal does NOT implement serializable and I didn't want to change that implementation
028:         * hence I implemented this one instead.
029:         * @author Filip Hanik
030:         * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
031:         */
032:        import org.apache.catalina.realm.GenericPrincipal;
033:        import java.io.ObjectInput;
034:        import java.io.ObjectOutput;
035:
036:        public class SerializablePrincipal implements  java.io.Serializable {
037:
038:            // ----------------------------------------------------------- Constructors
039:
040:            public SerializablePrincipal() {
041:                super ();
042:            }
043:
044:            /**
045:             * Construct a new Principal, associated with the specified Realm, for the
046:             * specified username and password.
047:             *
048:             * @param realm The Realm that owns this Principal
049:             * @param name The username of the user represented by this Principal
050:             * @param password Credentials used to authenticate this user
051:             */
052:            public SerializablePrincipal(Realm realm, String name,
053:                    String password) {
054:
055:                this (realm, name, password, null);
056:
057:            }
058:
059:            /**
060:             * Construct a new Principal, associated with the specified Realm, for the
061:             * specified username and password, with the specified role names
062:             * (as Strings).
063:             *
064:             * @param realm The Realm that owns this principal
065:             * @param name The username of the user represented by this Principal
066:             * @param password Credentials used to authenticate this user
067:             * @param roles List of roles (must be Strings) possessed by this user
068:             */
069:            public SerializablePrincipal(Realm realm, String name,
070:                    String password, List roles) {
071:
072:                super ();
073:                this .realm = realm;
074:                this .name = name;
075:                this .password = password;
076:                if (roles != null) {
077:                    this .roles = new String[roles.size()];
078:                    this .roles = (String[]) roles.toArray(this .roles);
079:                    if (this .roles.length > 0)
080:                        Arrays.sort(this .roles);
081:                }
082:
083:            }
084:
085:            // ------------------------------------------------------------- Properties
086:
087:            /**
088:             * The username of the user represented by this Principal.
089:             */
090:            protected String name = null;
091:
092:            public String getName() {
093:                return (this .name);
094:            }
095:
096:            /**
097:             * The authentication credentials for the user represented by
098:             * this Principal.
099:             */
100:            protected String password = null;
101:
102:            public String getPassword() {
103:                return (this .password);
104:            }
105:
106:            /**
107:             * The Realm with which this Principal is associated.
108:             */
109:            protected transient Realm realm = null;
110:
111:            public Realm getRealm() {
112:                return (this .realm);
113:            }
114:
115:            public void setRealm(Realm realm) {
116:                this .realm = realm;
117:            }
118:
119:            /**
120:             * The set of roles associated with this user.
121:             */
122:            protected String roles[] = new String[0];
123:
124:            public String[] getRoles() {
125:                return (this .roles);
126:            }
127:
128:            // --------------------------------------------------------- Public Methods
129:
130:            /**
131:             * Return a String representation of this object, which exposes only
132:             * information that should be public.
133:             */
134:            public String toString() {
135:
136:                StringBuffer sb = new StringBuffer("SerializablePrincipal[");
137:                sb.append(this .name);
138:                sb.append("]");
139:                return (sb.toString());
140:
141:            }
142:
143:            public static SerializablePrincipal createPrincipal(
144:                    GenericPrincipal principal) {
145:                if (principal == null)
146:                    return null;
147:                return new SerializablePrincipal(principal.getRealm(),
148:                        principal.getName(), principal.getPassword(), principal
149:                                .getRoles() != null ? Arrays.asList(principal
150:                                .getRoles()) : null);
151:            }
152:
153:            public GenericPrincipal getPrincipal(Realm realm) {
154:                return new GenericPrincipal(realm, name, password,
155:                        getRoles() != null ? Arrays.asList(getRoles()) : null);
156:            }
157:
158:            public static GenericPrincipal readPrincipal(ObjectInput in,
159:                    Realm realm) throws java.io.IOException {
160:                String name = in.readUTF();
161:                boolean hasPwd = in.readBoolean();
162:                String pwd = null;
163:                if (hasPwd)
164:                    pwd = in.readUTF();
165:                int size = in.readInt();
166:                String[] roles = new String[size];
167:                for (int i = 0; i < size; i++)
168:                    roles[i] = in.readUTF();
169:                return new GenericPrincipal(realm, name, pwd, Arrays
170:                        .asList(roles));
171:            }
172:
173:            public static void writePrincipal(GenericPrincipal p,
174:                    ObjectOutput out) throws java.io.IOException {
175:                out.writeUTF(p.getName());
176:                out.writeBoolean(p.getPassword() != null);
177:                if (p.getPassword() != null)
178:                    out.writeUTF(p.getPassword());
179:                String[] roles = p.getRoles();
180:                if (roles == null)
181:                    roles = new String[0];
182:                out.writeInt(roles.length);
183:                for (int i = 0; i < roles.length; i++)
184:                    out.writeUTF(roles[i]);
185:            }
186:
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.