Source Code Cross Referenced for AuthChallengeProcessor.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/AuthChallengeProcessor.java,v 1.2 2004/04/18 23:51:36 jsdever 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.Collection;
034:        import java.util.Iterator;
035:        import java.util.Map;
036:
037:        import org.apache.commons.httpclient.params.HttpParams;
038:        import org.apache.commons.logging.Log;
039:        import org.apache.commons.logging.LogFactory;
040:
041:        /**
042:         * This class provides utility methods for processing HTTP www and proxy authentication 
043:         * challenges.
044:         * 
045:         * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
046:         * 
047:         * @since 3.0
048:         */
049:        public final class AuthChallengeProcessor {
050:
051:            private static final Log LOG = LogFactory
052:                    .getLog(AuthChallengeProcessor.class);
053:
054:            private HttpParams params = null;
055:
056:            /**
057:             * Creates an authentication challenge processor with the given {@link HttpParams HTTP 
058:             * parameters}
059:             * 
060:             * @param params the {@link HttpParams HTTP parameters} used by this processor
061:             */
062:            public AuthChallengeProcessor(final HttpParams params) {
063:                super ();
064:                if (params == null) {
065:                    throw new IllegalArgumentException(
066:                            "Parameter collection may not be null");
067:                }
068:                this .params = params;
069:            }
070:
071:            /**
072:             * Determines the preferred {@link AuthScheme authentication scheme} that can be used 
073:             * to respond to the given collection of challenges.
074:             * 
075:             * @param challenges the collection of authentication challenges
076:             * 
077:             * @return the preferred {@link AuthScheme authentication scheme}
078:             * 
079:             * @throws AuthChallengeException if the preferred authentication scheme 
080:             * cannot be determined or is not supported
081:             */
082:            public AuthScheme selectAuthScheme(final Map challenges)
083:                    throws AuthChallengeException {
084:                if (challenges == null) {
085:                    throw new IllegalArgumentException(
086:                            "Challenge map may not be null");
087:                }
088:                Collection authPrefs = (Collection) this .params
089:                        .getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY);
090:                if (authPrefs == null || authPrefs.isEmpty()) {
091:                    authPrefs = AuthPolicy.getDefaultAuthPrefs();
092:                }
093:                if (LOG.isDebugEnabled()) {
094:                    LOG
095:                            .debug("Supported authentication schemes in the order of preference: "
096:                                    + authPrefs);
097:                }
098:                AuthScheme authscheme = null;
099:                String challenge = null;
100:                Iterator item = authPrefs.iterator();
101:                while (item.hasNext()) {
102:                    String id = (String) item.next();
103:                    challenge = (String) challenges.get(id.toLowerCase());
104:                    if (challenge != null) {
105:                        if (LOG.isInfoEnabled()) {
106:                            LOG.info(id + " authentication scheme selected");
107:                        }
108:                        try {
109:                            authscheme = AuthPolicy.getAuthScheme(id);
110:                        } catch (IllegalStateException e) {
111:                            throw new AuthChallengeException(e.getMessage());
112:                        }
113:                        break;
114:                    } else {
115:                        if (LOG.isDebugEnabled()) {
116:                            LOG.debug("Challenge for " + id
117:                                    + " authentication scheme not available");
118:                            // Try again
119:                        }
120:                    }
121:                }
122:                if (authscheme == null) {
123:                    // If none selected, something is wrong
124:                    throw new AuthChallengeException(
125:                            "Unable to respond to any of these challenges: "
126:                                    + challenges);
127:                }
128:                return authscheme;
129:            }
130:
131:            /**
132:             * Processes the given collection of challenges and updates the 
133:             * {@link AuthState state} of the authentication process.
134:             * 
135:             * @param challenges the collection of authentication challenges
136:             * 
137:             * @return the {@link AuthScheme authentication scheme} used to 
138:             * process the challenge
139:             * 
140:             * @throws AuthChallengeException if authentication challenges cannot be 
141:             * successfully processed or the preferred authentication scheme cannot
142:             * be determined
143:             */
144:            public AuthScheme processChallenge(final AuthState state,
145:                    final Map challenges) throws MalformedChallengeException,
146:                    AuthenticationException {
147:                if (state == null) {
148:                    throw new IllegalArgumentException(
149:                            "Authentication state may not be null");
150:                }
151:                if (challenges == null) {
152:                    throw new IllegalArgumentException(
153:                            "Challenge map may not be null");
154:                }
155:
156:                if (state.isPreemptive() || state.getAuthScheme() == null) {
157:                    // Authentication not attempted before
158:                    state.setAuthScheme(selectAuthScheme(challenges));
159:                }
160:                AuthScheme authscheme = state.getAuthScheme();
161:                String id = authscheme.getSchemeName();
162:                if (LOG.isDebugEnabled()) {
163:                    LOG.debug("Using authentication scheme: " + id);
164:                }
165:                String challenge = (String) challenges.get(id.toLowerCase());
166:                if (challenge == null) {
167:                    throw new AuthenticationException(
168:                            id
169:                                    + " authorization challenge expected, but not found");
170:                }
171:                authscheme.processChallenge(challenge);
172:                LOG.debug("Authorization challenge processed");
173:                return authscheme;
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.