Source Code Cross Referenced for WikiPrincipal.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » auth » 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 » Wiki Engine » JSPWiki » com.ecyrd.jspwiki.auth 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         JSPWiki - a JSP-based WikiWiki clone.
003:
004:         Copyright (C) 2001-2004 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006:         This program is free software; you can redistribute it and/or modify
007:         it under the terms of the GNU Lesser General Public License as published by
008:         the Free Software Foundation; either version 2.1 of the License, or
009:         (at your option) any later version.
010:
011:         This program 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
014:         GNU Lesser General Public License for more details.
015:
016:         You should have received a copy of the GNU Lesser General Public License
017:         along with this program; if not, write to the Free Software
018:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:        package com.ecyrd.jspwiki.auth;
021:
022:        import java.security.Principal;
023:        import java.util.Arrays;
024:        import java.util.Comparator;
025:
026:        /**
027:         *  A lightweight, immutable Principal class. WikiPrincipals can be created with
028:         *  and optional "type" to denote what type of user profile Principal it represents
029:         *  (FULL_NAME, WIKI_NAME, LOGIN_NAME). Types are used to determine suitable
030:         *  user and login Principals in classes like WikiSession. However, the type
031:         *  property of a WikiPrincipal does not affect a WikiPrincipal's logical equality
032:         *  or hash code; two WikiPrincipals with the same name but different types are still
033:         *  considered equal.
034:         *
035:         *  @author Janne Jalkanen
036:         *  @author Andrew Jaquith
037:         *  @since  2.2
038:         */
039:        public final class WikiPrincipal implements  Principal {
040:
041:            /**
042:             * Represents an anonymous user. WikiPrincipals may be
043:             * created with an optional type designator: 
044:             * LOGIN_NAME, WIKI_NAME, FULL_NAME or UNSPECIFIED.
045:             */
046:            public static final Principal GUEST = new WikiPrincipal("Guest");
047:
048:            /** WikiPrincipal type denoting a user's full name. */
049:            public static final String FULL_NAME = "fullName";
050:
051:            /** WikiPrincipal type denoting a user's login name. */
052:            public static final String LOGIN_NAME = "loginName";
053:
054:            /** WikiPrincipal type denoting a user's wiki name. */
055:            public static final String WIKI_NAME = "wikiName";
056:
057:            /** Generic WikiPrincipal of unspecified type. */
058:            public static final String UNSPECIFIED = "unspecified";
059:
060:            /** Static instance of Comparator that allows Principals to be sorted. */
061:            public static final Comparator COMPARATOR = new PrincipalComparator();
062:
063:            private static final String[] VALID_TYPES;
064:
065:            static {
066:                VALID_TYPES = new String[] { FULL_NAME, LOGIN_NAME, WIKI_NAME,
067:                        UNSPECIFIED };
068:                Arrays.sort(VALID_TYPES);
069:            }
070:
071:            private final String m_name;
072:            private final String m_type;
073:
074:            /**
075:             * Constructs a new WikiPrincipal with a given name and a type of
076:             * {@link #UNSPECIFIED}.
077:             * @param name the name of the Principal
078:             */
079:            public WikiPrincipal(String name) {
080:                m_name = name;
081:                m_type = UNSPECIFIED;
082:            }
083:
084:            /**
085:             * Constructs a new WikiPrincipal with a given name and optional type
086:             * designator. If the supplied <code>type</code> parameter is not
087:             * {@link #LOGIN_NAME}, {@link #FULL_NAME}, {@link #WIKI_NAME}
088:             * or {@link #WIKI_NAME}, this method throws
089:             * an {@link IllegalArgumentException}.
090:             * @param name the name of the Principal
091:             * @param type the type for this principal, which may be {@link #LOGIN_NAME},
092:             *            {@link #FULL_NAME}, {@link #WIKI_NAME} or {@link #WIKI_NAME}.
093:             */
094:            public WikiPrincipal(String name, String type) {
095:                m_name = name;
096:                if (Arrays.binarySearch(VALID_TYPES, type) < 0) {
097:                    throw new IllegalArgumentException("Principal type '"
098:                            + type + "' is invalid.");
099:                }
100:                m_type = type;
101:            }
102:
103:            /**
104:             *  Returns the wiki name of the Principal.
105:             *  @return the name
106:             */
107:            public final String getName() {
108:                return m_name;
109:            }
110:
111:            /**
112:             * Two <code>WikiPrincipal</code>s are considered equal if their
113:             * names are equal (case-sensitive).
114:             * @param obj the object to compare
115:             * @return the result of the equality test
116:             */
117:            public final boolean equals(Object obj) {
118:                if (obj == null || !(obj instanceof  WikiPrincipal)) {
119:                    return false;
120:                }
121:                return m_name.equals(((WikiPrincipal) obj).getName());
122:            }
123:
124:            /**
125:             *  The hashCode() returned for the WikiPrincipal is the same as
126:             *  for its name.
127:             *  @return the hash code
128:             */
129:            public final int hashCode() {
130:                return m_name.hashCode();
131:            }
132:
133:            /**
134:             * Returns the Principal "type": {@link #LOGIN_NAME}, {@link #FULL_NAME},
135:             * {@link #WIKI_NAME} or {@link #WIKI_NAME}
136:             * @return the type
137:             */
138:            public final String getType() {
139:                return m_type;
140:            }
141:
142:            /**
143:             * Returns a human-readable representation of the object.
144:             * @return the string representation
145:             */
146:            public final String toString() {
147:                return "[WikiPrincipal (" + m_type + "): " + getName() + "]";
148:            }
149:
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.