Source Code Cross Referenced for AuthPolicy.java in  » Net » Apache-common-HttpClient » org » apache » commons » httpclient » 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 » Net » Apache common HttpClient » org.apache.commons.httpclient.auth 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/auth/AuthPolicy.java,v 1.6 2004/05/13 04:02:00 mbecke Exp $
003:         * $Revision: 480424 $
004:         * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005:         *
006:         * ====================================================================
007:         *
008:         *  Licensed to the Apache Software Foundation (ASF) under one or more
009:         *  contributor license agreements.  See the NOTICE file distributed with
010:         *  this work for additional information regarding copyright ownership.
011:         *  The ASF licenses this file to You under the Apache License, Version 2.0
012:         *  (the "License"); you may not use this file except in compliance with
013:         *  the License.  You may obtain a copy of the License at
014:         *
015:         *      http://www.apache.org/licenses/LICENSE-2.0
016:         *
017:         *  Unless required by applicable law or agreed to in writing, software
018:         *  distributed under the License is distributed on an "AS IS" BASIS,
019:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020:         *  See the License for the specific language governing permissions and
021:         *  limitations under the License.
022:         * ====================================================================
023:         *
024:         * This software consists of voluntary contributions made by many
025:         * individuals on behalf of the Apache Software Foundation.  For more
026:         * information on the Apache Software Foundation, please see
027:         * <http://www.apache.org/>.
028:         *
029:         */
030:
031:        package org.apache.commons.httpclient.auth;
032:
033:        import java.util.ArrayList;
034:        import java.util.HashMap;
035:        import java.util.List;
036:
037:        import org.apache.commons.logging.Log;
038:        import org.apache.commons.logging.LogFactory;
039:
040:        /**
041:         * Authentication policy class. The Authentication policy provides corresponding
042:         * authentication scheme interfrace for a given type of authorization challenge. 
043:         * <p>The following specifications are provided:
044:         *  <ul>
045:         *   <li><tt>Basic</tt>: Basic authentication scheme as defined in RFC2617
046:         *           (considered inherently insecure, but most widely supported)
047:         *   <li><tt>Digest</tt>: Digest authentication scheme as defined in RFC2617
048:         *   <li><tt>NTLM</tt>: The NTLM scheme is a proprietary Microsoft Windows 
049:         *           Authentication protocol (considered to be the most secure among
050:         *           currently supported authentication schemes)
051:         *  </ul>
052:         * 
053:         * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
054:         *
055:         * @version $Revision: 480424 $
056:         * @since 3.0
057:         */
058:        public abstract class AuthPolicy {
059:
060:            private static final HashMap SCHEMES = new HashMap();
061:            private static final ArrayList SCHEME_LIST = new ArrayList();
062:
063:            /**
064:             * The key used to look up the list of IDs of supported {@link AuthScheme 
065:             * authentication schemes} in their order of preference. The scheme IDs are 
066:             * stored in a {@link java.util.Collection} as {@link java.lang.String}s. 
067:             * 
068:             * <p>
069:             * If several schemes are returned in the <tt>WWW-Authenticate</tt> 
070:             * or <tt>Proxy-Authenticate</tt> header, this parameter defines which
071:             * {@link AuthScheme authentication schemes} takes precedence over others.
072:             * The first item in the collection represents the most preferred 
073:             * {@link AuthScheme authentication scheme}, the last item represents the ID 
074:             * of the least preferred one.
075:             * </p>
076:             * 
077:             * @see org.apache.commons.httpclient.params.DefaultHttpParams
078:             */
079:            public static final String AUTH_SCHEME_PRIORITY = "http.auth.scheme-priority";
080:
081:            /**
082:             * The NTLM scheme is a proprietary Microsoft Windows Authentication 
083:             * protocol (considered to be the most secure among currently supported 
084:             * authentication schemes).
085:             */
086:            public static final String NTLM = "NTLM";
087:
088:            /** 
089:             * Digest authentication scheme as defined in RFC2617.
090:             */
091:            public static final String DIGEST = "Digest";
092:
093:            /** 
094:             * Basic authentication scheme as defined in RFC2617 (considered inherently
095:             * insecure, but most widely supported)
096:             */
097:            public static final String BASIC = "Basic";
098:
099:            static {
100:                AuthPolicy.registerAuthScheme(NTLM, NTLMScheme.class);
101:                AuthPolicy.registerAuthScheme(DIGEST, DigestScheme.class);
102:                AuthPolicy.registerAuthScheme(BASIC, BasicScheme.class);
103:            }
104:
105:            /** Log object. */
106:            protected static final Log LOG = LogFactory
107:                    .getLog(AuthPolicy.class);
108:
109:            /**
110:             * Registers a class implementing an {@link AuthScheme authentication scheme} with 
111:             * the given identifier. If a class with the given ID already exists it will be overridden.  
112:             * This ID is the same one used to retrieve the {@link AuthScheme authentication scheme} 
113:             * from {@link #getAuthScheme(String)}.
114:             * 
115:             * <p>
116:             * Please note that custom authentication preferences, if used, need to be updated accordingly 
117:             * for the new {@link AuthScheme authentication scheme} to take effect.
118:             * </p>    
119:             * 
120:             * @param id the identifier for this scheme
121:             * @param clazz the class to register
122:             * 
123:             * @see #getAuthScheme(String)
124:             * @see #AUTH_SCHEME_PRIORITY
125:             */
126:            public static synchronized void registerAuthScheme(final String id,
127:                    Class clazz) {
128:                if (id == null) {
129:                    throw new IllegalArgumentException("Id may not be null");
130:                }
131:                if (clazz == null) {
132:                    throw new IllegalArgumentException(
133:                            "Authentication scheme class may not be null");
134:                }
135:                SCHEMES.put(id.toLowerCase(), clazz);
136:                SCHEME_LIST.add(id.toLowerCase());
137:            }
138:
139:            /**
140:             * Unregisters the class implementing an {@link AuthScheme authentication scheme} with 
141:             * the given ID.
142:             * 
143:             * @param id the ID of the class to unregister
144:             */
145:            public static synchronized void unregisterAuthScheme(final String id) {
146:                if (id == null) {
147:                    throw new IllegalArgumentException("Id may not be null");
148:                }
149:                SCHEMES.remove(id.toLowerCase());
150:                SCHEME_LIST.remove(id.toLowerCase());
151:            }
152:
153:            /**
154:             * Gets the {@link AuthScheme authentication scheme} with the given ID.
155:             * 
156:             * @param id the {@link AuthScheme authentication scheme} ID
157:             * 
158:             * @return {@link AuthScheme authentication scheme}
159:             * 
160:             * @throws IllegalStateException if a scheme with the ID cannot be found
161:             */
162:            public static synchronized AuthScheme getAuthScheme(final String id)
163:                    throws IllegalStateException {
164:
165:                if (id == null) {
166:                    throw new IllegalArgumentException("Id may not be null");
167:                }
168:                Class clazz = (Class) SCHEMES.get(id.toLowerCase());
169:                if (clazz != null) {
170:                    try {
171:                        return (AuthScheme) clazz.newInstance();
172:                    } catch (Exception e) {
173:                        LOG.error("Error initializing authentication scheme: "
174:                                + id, e);
175:                        throw new IllegalStateException(id
176:                                + " authentication scheme implemented by "
177:                                + clazz.getName() + " could not be initialized");
178:                    }
179:                } else {
180:                    throw new IllegalStateException(
181:                            "Unsupported authentication scheme " + id);
182:                }
183:            }
184:
185:            /**
186:             * Returns a list containing all registered {@link AuthScheme authentication 
187:             * schemes} in their default order.
188:             * 
189:             * @return {@link AuthScheme authentication scheme}
190:             */
191:            public static synchronized List getDefaultAuthPrefs() {
192:                return (List) SCHEME_LIST.clone();
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.