Source Code Cross Referenced for SSHBase.java in  » Build » ANT » org » apache » tools » ant » taskdefs » optional » ssh » 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 » Build » ANT » org.apache.tools.ant.taskdefs.optional.ssh 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.tools.ant.taskdefs.optional.ssh;
020:
021:        import com.jcraft.jsch.JSchException;
022:        import com.jcraft.jsch.Session;
023:        import com.jcraft.jsch.JSch;
024:
025:        import org.apache.tools.ant.Task;
026:        import org.apache.tools.ant.BuildException;
027:        import org.apache.tools.ant.Project;
028:
029:        /**
030:         * Base class for Ant tasks using jsch.
031:         *
032:         * @since Ant 1.6
033:         */
034:        public abstract class SSHBase extends Task implements  LogListener {
035:
036:            /** Default listen port for SSH daemon */
037:            private static final int SSH_PORT = 22;
038:
039:            private String host;
040:            private String knownHosts;
041:            private int port = SSH_PORT;
042:            private boolean failOnError = true;
043:            private boolean verbose;
044:            private SSHUserInfo userInfo;
045:
046:            /**
047:             * Constructor for SSHBase.
048:             */
049:            public SSHBase() {
050:                super ();
051:                userInfo = new SSHUserInfo();
052:            }
053:
054:            /**
055:             * Remote host, either DNS name or IP.
056:             *
057:             * @param host  The new host value
058:             */
059:            public void setHost(String host) {
060:                this .host = host;
061:            }
062:
063:            /**
064:             * Get the host.
065:             * @return the host
066:             */
067:            public String getHost() {
068:                return host;
069:            }
070:
071:            /**
072:             * Set the failonerror flag.
073:             * Default is true
074:             * @param failure if true throw a build exception when a failure occuries,
075:             *                otherwise just log the failure and continue
076:             */
077:            public void setFailonerror(boolean failure) {
078:                failOnError = failure;
079:            }
080:
081:            /**
082:             * Get the failonerror flag.
083:             * @return the failonerror flag
084:             */
085:            public boolean getFailonerror() {
086:                return failOnError;
087:            }
088:
089:            /**
090:             * Set the verbose flag.
091:             * @param verbose if true output more verbose logging
092:             * @since Ant 1.6.2
093:             */
094:            public void setVerbose(boolean verbose) {
095:                this .verbose = verbose;
096:            }
097:
098:            /**
099:             * Get the verbose flag.
100:             * @return the verbose flag
101:             * @since Ant 1.6.2
102:             */
103:            public boolean getVerbose() {
104:                return verbose;
105:            }
106:
107:            /**
108:             * Username known to remote host.
109:             *
110:             * @param username  The new username value
111:             */
112:            public void setUsername(String username) {
113:                userInfo.setName(username);
114:            }
115:
116:            /**
117:             * Sets the password for the user.
118:             *
119:             * @param password  The new password value
120:             */
121:            public void setPassword(String password) {
122:                userInfo.setPassword(password);
123:            }
124:
125:            /**
126:             * Sets the keyfile for the user.
127:             *
128:             * @param keyfile  The new keyfile value
129:             */
130:            public void setKeyfile(String keyfile) {
131:                userInfo.setKeyfile(keyfile);
132:            }
133:
134:            /**
135:             * Sets the passphrase for the users key.
136:             *
137:             * @param passphrase  The new passphrase value
138:             */
139:            public void setPassphrase(String passphrase) {
140:                userInfo.setPassphrase(passphrase);
141:            }
142:
143:            /**
144:             * Sets the path to the file that has the identities of
145:             * all known hosts.  This is used by SSH protocol to validate
146:             * the identity of the host.  The default is
147:             * <i>${user.home}/.ssh/known_hosts</i>.
148:             *
149:             * @param knownHosts a path to the known hosts file.
150:             */
151:            public void setKnownhosts(String knownHosts) {
152:                this .knownHosts = knownHosts;
153:            }
154:
155:            /**
156:             * Setting this to true trusts hosts whose identity is unknown.
157:             *
158:             * @param yesOrNo if true trust the identity of unknown hosts.
159:             */
160:            public void setTrust(boolean yesOrNo) {
161:                userInfo.setTrust(yesOrNo);
162:            }
163:
164:            /**
165:             * Changes the port used to connect to the remote host.
166:             *
167:             * @param port port number of remote host.
168:             */
169:            public void setPort(int port) {
170:                this .port = port;
171:            }
172:
173:            /**
174:             * Get the port attribute.
175:             * @return the port
176:             */
177:            public int getPort() {
178:                return port;
179:            }
180:
181:            /**
182:             * Initialize the task.
183:             * This initializizs the known hosts and sets the default port.
184:             * @throws BuildException on error
185:             */
186:            public void init() throws BuildException {
187:                super .init();
188:                this .knownHosts = System.getProperty("user.home")
189:                        + "/.ssh/known_hosts";
190:                this .port = SSH_PORT;
191:            }
192:
193:            /**
194:             * Open an ssh seession.
195:             * @return the opened session
196:             * @throws JSchException on error
197:             */
198:            protected Session openSession() throws JSchException {
199:                JSch jsch = new JSch();
200:                if (null != userInfo.getKeyfile()) {
201:                    jsch.addIdentity(userInfo.getKeyfile());
202:                }
203:
204:                if (!userInfo.getTrust() && knownHosts != null) {
205:                    log("Using known hosts: " + knownHosts, Project.MSG_DEBUG);
206:                    jsch.setKnownHosts(knownHosts);
207:                }
208:
209:                Session session = jsch.getSession(userInfo.getName(), host,
210:                        port);
211:                session.setUserInfo(userInfo);
212:                log("Connecting to " + host + ":" + port);
213:                session.connect();
214:                return session;
215:            }
216:
217:            /**
218:             * Get the user information.
219:             * @return the user information
220:             */
221:            protected SSHUserInfo getUserInfo() {
222:                return userInfo;
223:            }
224:        }
ww_w__.___j___av_a_2_s.___c__om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.