Source Code Cross Referenced for HttpClientCredentialsProvider.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » component » http » client » 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 » ESB » cbesb 1.2 » com.bostechcorp.cbesb.runtime.component.http.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Name:        HttpClientCredentialsProvider.java
003:         * Version:     $Id: HttpClientCredentialsProvider.java 8974 2007-09-07 01:30:35Z mpreston $
004:         * Copyright:   Copyright (c) 2006, Bostech Corporation
005:         * Author:      mpreston
006:         * Created on:  May 1, 2006
007:         * Description: Class to provide the appropriate type of credentials depending on the authorization
008:         * scheme requested by the server.
009:         */
010:        package com.bostechcorp.cbesb.runtime.component.http.client;
011:
012:        import java.io.IOException;
013:
014:        import org.apache.commons.httpclient.Credentials;
015:        import org.apache.commons.httpclient.auth.AuthScheme;
016:        import org.apache.commons.httpclient.auth.CredentialsNotAvailableException;
017:        import org.apache.commons.httpclient.auth.CredentialsProvider;
018:        import org.apache.commons.httpclient.auth.NTLMScheme;
019:        import org.apache.commons.httpclient.auth.RFC2617Scheme;
020:        import org.apache.commons.httpclient.NTCredentials;
021:        import org.apache.commons.httpclient.UsernamePasswordCredentials;
022:
023:        public class HttpClientCredentialsProvider implements 
024:                CredentialsProvider {
025:
026:            /**
027:             * Constructor
028:             */
029:            public HttpClientCredentialsProvider() {
030:            }
031:
032:            /**
033:             * Sets the user and password to use for authentication.
034:             * @param username - the username to log in to the server.  If domain name should be specified,
035:             * then pass the username as <code><i>domain&#92;user</i></code>.
036:             * @param password - the password.
037:             */
038:            public void setUsernamePassword(String username, String password) {
039:                _username = username;
040:                _password = password;
041:            }
042:
043:            /**
044:             * Sets the user and password to use for authentication on a proxy server.
045:             * @param username - the username to log in to the server.  If domain name should be specified,
046:             * then pass the username as <code><i>domain&#92;user</i></code>.
047:             * @param password - the password.
048:             */
049:            public void setProxyUsernamePassword(String username,
050:                    String password) {
051:                _proxyUsername = username;
052:                _proxyPassword = password;
053:            }
054:
055:            /**
056:             * Called when a server requires authentication.  If the authentication scheme is NTLM, then NTCredentials
057:             * are supplied, otherwise UsernamePasswordCredentials are supplied.
058:             * @param authscheme - The authorization scheme requested by the server.
059:             * @param host - The server hostname
060:             * @param port - The server port
061:             * @param proxy - True if logging into a proxy server.  False otherwise.
062:             * @throws CredentialsNotAvailableException
063:             */
064:            public Credentials getCredentials(AuthScheme authscheme,
065:                    String host, int port, boolean proxy)
066:                    throws CredentialsNotAvailableException {
067:                String tmpuser;
068:                String tmppwd;
069:                if (proxy) {
070:                    tmpuser = _proxyUsername;
071:                    tmppwd = _proxyPassword;
072:                } else {
073:                    tmpuser = _username;
074:                    tmppwd = _password;
075:                }
076:
077:                if (authscheme == null) {
078:                    return null;
079:                }
080:                try {
081:                    if (authscheme instanceof  NTLMScheme) {
082:                        String user = "";
083:                        String domain = "";
084:                        if (tmpuser.indexOf("\\") > -1) {
085:                            int index = tmpuser.indexOf("\\");
086:                            user = tmpuser.substring(index + 1);
087:                            domain = tmpuser.substring(0, index);
088:                        } else {
089:                            throw new CredentialsNotAvailableException(
090:                                    "Could not determine domain from supplied username '"
091:                                            + tmpuser
092:                                            + "'.  Please specify in 'domain\\username' format.");
093:                        }
094:                        return new NTCredentials(user, tmppwd, host, domain);
095:
096:                    } else if (authscheme instanceof  RFC2617Scheme) {
097:                        return new UsernamePasswordCredentials(tmpuser, tmppwd);
098:                    } else {
099:                        throw new CredentialsNotAvailableException(
100:                                "Unsupported authentication scheme: "
101:                                        + authscheme.getSchemeName());
102:                    }
103:                } catch (IOException e) {
104:                    throw new CredentialsNotAvailableException(e.getMessage(),
105:                            e);
106:                }
107:            }
108:
109:            private String _username = "";
110:            private String _password = "";
111:            private String _proxyUsername = "";
112:            private String _proxyPassword = "";
113:
114:        }
w__w___w___.j___a___v_a2__s___._c_o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.