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


001:        /*
002:         * Copyright 1999,2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.apache.catalina.realm;
018:
019:        import java.security.Principal;
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:         *
028:         * @author Craig R. McClanahan
029:         * @version $Revision: 1.4 $ $Date: 2004/02/27 14:58:45 $
030:         */
031:
032:        public class GenericPrincipal implements  Principal {
033:
034:            // ----------------------------------------------------------- Constructors
035:
036:            /**
037:             * Construct a new Principal, associated with the specified Realm, for the
038:             * specified username and password.
039:             *
040:             * @param realm The Realm that owns this Principal
041:             * @param name The username of the user represented by this Principal
042:             * @param password Credentials used to authenticate this user
043:             */
044:            public GenericPrincipal(Realm realm, String name, String password) {
045:
046:                this (realm, name, password, null);
047:
048:            }
049:
050:            /**
051:             * Construct a new Principal, associated with the specified Realm, for the
052:             * specified username and password, with the specified role names
053:             * (as Strings).
054:             *
055:             * @param realm The Realm that owns this principal
056:             * @param name The username of the user represented by this Principal
057:             * @param password Credentials used to authenticate this user
058:             * @param roles List of roles (must be Strings) possessed by this user
059:             */
060:            public GenericPrincipal(Realm realm, String name, String password,
061:                    List roles) {
062:
063:                super ();
064:                this .realm = realm;
065:                this .name = name;
066:                this .password = password;
067:                if (roles != null) {
068:                    this .roles = new String[roles.size()];
069:                    this .roles = (String[]) roles.toArray(this .roles);
070:                    if (this .roles.length > 0)
071:                        Arrays.sort(this .roles);
072:                }
073:            }
074:
075:            public GenericPrincipal(String name, String password, List roles) {
076:
077:                super ();
078:                this .name = name;
079:                this .password = password;
080:                if (roles != null) {
081:                    this .roles = new String[roles.size()];
082:                    this .roles = (String[]) roles.toArray(this .roles);
083:                    if (this .roles.length > 0)
084:                        Arrays.sort(this .roles);
085:                }
086:            }
087:
088:            // ------------------------------------------------------------- Properties
089:
090:            /**
091:             * The username of the user represented by this Principal.
092:             */
093:            protected String name = null;
094:
095:            public String getName() {
096:                return (this .name);
097:            }
098:
099:            /**
100:             * The authentication credentials for the user represented by
101:             * this Principal.
102:             */
103:            protected String password = null;
104:
105:            public String getPassword() {
106:                return (this .password);
107:            }
108:
109:            /**
110:             * The Realm with which this Principal is associated.
111:             */
112:            protected Realm realm = null;
113:
114:            public Realm getRealm() {
115:                return (this .realm);
116:            }
117:
118:            void setRealm(Realm realm) {
119:                this .realm = realm;
120:            }
121:
122:            /**
123:             * The set of roles associated with this user.
124:             */
125:            protected String roles[] = new String[0];
126:
127:            public String[] getRoles() {
128:                return (this .roles);
129:            }
130:
131:            // --------------------------------------------------------- Public Methods
132:
133:            /**
134:             * Does the user represented by this Principal possess the specified role?
135:             *
136:             * @param role Role to be tested
137:             */
138:            public boolean hasRole(String role) {
139:
140:                if ("*".equals(role)) // Special 2.4 role meaning everyone
141:                    return true;
142:                if (role == null)
143:                    return (false);
144:                return (Arrays.binarySearch(roles, role) >= 0);
145:
146:            }
147:
148:            /**
149:             * Return a String representation of this object, which exposes only
150:             * information that should be public.
151:             */
152:            public String toString() {
153:
154:                StringBuffer sb = new StringBuffer("GenericPrincipal[");
155:                sb.append(this .name);
156:                sb.append("(");
157:                for (int i = 0; i < roles.length; i++) {
158:                    sb.append(roles[i]).append(",");
159:                }
160:                sb.append(")]");
161:                return (sb.toString());
162:
163:            }
164:
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.