Source Code Cross Referenced for JavaHLAuthenticationProvider.java in  » Source-Control » tmatesoft-SVN » org » tmatesoft » svn » core » javahl » 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 » Source Control » tmatesoft SVN » org.tmatesoft.svn.core.javahl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ====================================================================
003:         * Copyright (c) 2004-2008 TMate Software Ltd.  All rights reserved.
004:         *
005:         * This software is licensed as described in the file COPYING, which
006:         * you should have received as part of this distribution.  The terms
007:         * are also available at http://svnkit.com/license.html
008:         * If newer versions of this license are posted there, you may use a
009:         * newer version instead, at your option.
010:         * ====================================================================
011:         */
012:        package org.tmatesoft.svn.core.javahl;
013:
014:        import java.io.File;
015:        import java.security.cert.X509Certificate;
016:
017:        import org.tigris.subversion.javahl.PromptUserPassword;
018:        import org.tigris.subversion.javahl.PromptUserPassword2;
019:        import org.tigris.subversion.javahl.PromptUserPassword3;
020:        import org.tmatesoft.svn.core.SVNErrorMessage;
021:        import org.tmatesoft.svn.core.SVNURL;
022:        import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
023:        import org.tmatesoft.svn.core.auth.ISVNAuthenticationProvider;
024:        import org.tmatesoft.svn.core.auth.SVNAuthentication;
025:        import org.tmatesoft.svn.core.auth.SVNPasswordAuthentication;
026:        import org.tmatesoft.svn.core.auth.SVNSSHAuthentication;
027:        import org.tmatesoft.svn.core.auth.SVNSSLAuthentication;
028:        import org.tmatesoft.svn.core.auth.SVNUserNameAuthentication;
029:        import org.tmatesoft.svn.core.internal.util.SVNSSLUtil;
030:
031:        /**
032:         * @version 1.1.1
033:         * @author  TMate Software Ltd.
034:         */
035:        class JavaHLAuthenticationProvider implements 
036:                ISVNAuthenticationProvider {
037:
038:            private static final String ADAPTER_DEFAULT_PROMPT_CLASS = "org.tigris.subversion.svnclientadapter.javahl.AbstractJhlClientAdapter$DefaultPromptUserPassword";
039:            private PromptUserPassword myPrompt;
040:
041:            public JavaHLAuthenticationProvider(PromptUserPassword prompt) {
042:                myPrompt = prompt;
043:            }
044:
045:            public SVNAuthentication requestClientAuthentication(String kind,
046:                    SVNURL url, String realm, SVNErrorMessage errorMessage,
047:                    SVNAuthentication previousAuth, boolean authMayBeStored) {
048:                if (ISVNAuthenticationManager.SSH.equals(kind)
049:                        && myPrompt instanceof  PromptUserPasswordSSH) {
050:                    PromptUserPasswordSSH prompt4 = (PromptUserPasswordSSH) myPrompt;
051:                    String userName = previousAuth != null
052:                            && previousAuth.getUserName() != null ? previousAuth
053:                            .getUserName()
054:                            : getUserName(null, url);
055:                    int port = url != null ? url.getPort() : -1;
056:                    if (prompt4.promptSSH(realm, userName, port,
057:                            authMayBeStored)) {
058:                        String password = prompt4.getPassword();
059:                        String keyPath = prompt4.getSSHPrivateKeyPath();
060:                        String passphrase = prompt4
061:                                .getSSHPrivateKeyPassphrase();
062:                        userName = getUserName(prompt4.getUsername(), url);
063:                        if ("".equals(passphrase)) {
064:                            passphrase = null;
065:                        }
066:                        port = prompt4.getSSHPort();
067:                        if (port < 0 && url != null) {
068:                            port = url.getPort();
069:                        }
070:                        if (port < 0) {
071:                            port = 22;
072:                        }
073:                        boolean save = prompt4.userAllowedSave();
074:                        if (keyPath != null && !"".equals(keyPath)) {
075:                            return new SVNSSHAuthentication(userName, new File(
076:                                    keyPath), passphrase, port, save);
077:                        } else if (password != null) {
078:                            return new SVNSSHAuthentication(userName, password,
079:                                    port, save);
080:                        }
081:                    }
082:                    return null;
083:                } else if (ISVNAuthenticationManager.SSL.equals(kind)
084:                        && myPrompt instanceof  PromptUserPasswordSSL) {
085:                    PromptUserPasswordSSL prompt4 = (PromptUserPasswordSSL) myPrompt;
086:                    if (prompt4.promptSSL(realm, authMayBeStored)) {
087:                        String cert = prompt4.getSSLClientCertPath();
088:                        String password = prompt4.getSSLClientCertPassword();
089:                        if (cert != null) {
090:                            if ("".equals(password)) {
091:                                password = null;
092:                            }
093:                            boolean save = prompt4.userAllowedSave();
094:                            return new SVNSSLAuthentication(new File(cert),
095:                                    password, save);
096:                        }
097:                    }
098:                    return null;
099:                }
100:                if (ISVNAuthenticationManager.SSH.equals(kind)
101:                        && previousAuth == null) {
102:                    // use configuration file here? but it was already used once...
103:                    String keyPath = System.getProperty("svnkit.ssh2.key",
104:                            System.getProperty("javasvn.ssh2.key"));
105:                    String userName = getUserName(System.getProperty(
106:                            "svnkit.ssh2.username", System
107:                                    .getProperty("javasvn.ssh2.username")), url);
108:                    String passPhrase = System.getProperty(
109:                            "svnkit.ssh2.passphrase", System
110:                                    .getProperty("javasvn.ssh2.passphrase"));
111:                    if (userName == null) {
112:                        return null;
113:                    }
114:                    if (keyPath != null && previousAuth == null) {
115:                        // use port number from configuration file?
116:                        return new SVNSSHAuthentication(userName, new File(
117:                                keyPath), passPhrase, -1, true);
118:                    }
119:                    // try to get password for ssh from the user.
120:                } else if (ISVNAuthenticationManager.USERNAME.equals(kind)) {
121:                    String userName = previousAuth != null
122:                            && previousAuth.getUserName() != null ? previousAuth
123:                            .getUserName()
124:                            : getUserName(null, url);
125:                    if (myPrompt instanceof  PromptUserPasswordUser) {
126:                        PromptUserPasswordUser prompt3 = (PromptUserPasswordUser) myPrompt;
127:                        if (prompt3
128:                                .promptUser(realm, userName, authMayBeStored)) {
129:                            return new SVNUserNameAuthentication(prompt3
130:                                    .getUsername(), prompt3.userAllowedSave());
131:                        }
132:                        return getDefaultUserNameCredentials(userName);
133:                    } else if (myPrompt instanceof  PromptUserPassword3) {
134:                        PromptUserPassword3 prompt3 = (PromptUserPassword3) myPrompt;
135:                        if (prompt3.prompt(realm, userName, authMayBeStored)) {
136:                            return new SVNUserNameAuthentication(prompt3
137:                                    .getUsername(), prompt3.userAllowedSave());
138:                        }
139:                        return getDefaultUserNameCredentials(userName);
140:                    }
141:                    if (myPrompt.prompt(realm, userName)) {
142:                        return new SVNUserNameAuthentication(myPrompt
143:                                .getUsername(), false);
144:                    }
145:                    return getDefaultUserNameCredentials(userName);
146:                } else if (!ISVNAuthenticationManager.PASSWORD.equals(kind)) {
147:                    return null;
148:                }
149:                String userName = previousAuth != null
150:                        && previousAuth.getUserName() != null ? previousAuth
151:                        .getUserName() : getUserName(null, url);
152:                if (myPrompt instanceof  PromptUserPassword3) {
153:                    PromptUserPassword3 prompt3 = (PromptUserPassword3) myPrompt;
154:                    if (prompt3.prompt(realm, userName, authMayBeStored)) {
155:                        if (ISVNAuthenticationManager.SSH.equals(kind)) {
156:                            // use default port number from configuration file (should be in previous auth).
157:                            int portNumber = (previousAuth instanceof  SVNSSHAuthentication) ? ((SVNSSHAuthentication) previousAuth)
158:                                    .getPortNumber()
159:                                    : -1;
160:                            return new SVNSSHAuthentication(prompt3
161:                                    .getUsername(), prompt3.getPassword(),
162:                                    portNumber, prompt3.userAllowedSave());
163:                        }
164:                        return new SVNPasswordAuthentication(prompt3
165:                                .getUsername(), prompt3.getPassword(), prompt3
166:                                .userAllowedSave());
167:                    }
168:                } else {
169:                    if (myPrompt.prompt(realm, userName)) {
170:                        if (ISVNAuthenticationManager.SSH.equals(kind)) {
171:                            return new SVNSSHAuthentication(userName, myPrompt
172:                                    .getPassword(), -1, true);
173:                        }
174:                        return new SVNPasswordAuthentication(myPrompt
175:                                .getUsername(), myPrompt.getPassword(), true);
176:                    }
177:                }
178:                return null;
179:            }
180:
181:            private SVNAuthentication getDefaultUserNameCredentials(
182:                    String userName) {
183:                if (ADAPTER_DEFAULT_PROMPT_CLASS.equals(myPrompt.getClass()
184:                        .getName())) {
185:                    // return default username, despite prompt was 'cancelled'.
186:                    return new SVNUserNameAuthentication(userName, false);
187:                }
188:                return null;
189:            }
190:
191:            public int acceptServerAuthentication(SVNURL url, String realm,
192:                    Object serverAuth, boolean resultMayBeStored) {
193:                if (serverAuth != null
194:                        && myPrompt instanceof  PromptUserPassword2) {
195:                    PromptUserPassword2 sslPrompt = (PromptUserPassword2) myPrompt;
196:                    serverAuth = serverAuth instanceof  X509Certificate ? SVNSSLUtil
197:                            .getServerCertificatePrompt(
198:                                    (X509Certificate) serverAuth, realm, url
199:                                            .getHost())
200:                            : serverAuth;
201:                    if (serverAuth == null) {
202:                        serverAuth = "Unsupported certificate type '"
203:                                + (serverAuth != null ? serverAuth.getClass()
204:                                        .getName() : "null") + "'";
205:                    }
206:                    return sslPrompt.askTrustSSLServer(serverAuth.toString(),
207:                            resultMayBeStored);
208:                }
209:                return ACCEPTED;
210:            }
211:
212:            private static String getUserName(String userName, SVNURL url) {
213:                if (userName == null || "".equals(userName.trim())) {
214:                    userName = url != null ? url.getUserInfo() : null;
215:                }
216:                if (userName == null || "".equals(userName.trim())) {
217:                    userName = System.getProperty("user.name");
218:                }
219:                return userName;
220:            }
221:
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.