1. /*
  2. * Copyright 2003-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs.optional.ssh;
  18. import com.jcraft.jsch.UserInfo;
  19. /**
  20. */
  21. public class SSHUserInfo implements UserInfo {
  22. private String name;
  23. private String password = null;
  24. private String keyfile;
  25. private String passphrase = null;
  26. private boolean firstTime = true;
  27. private boolean trustAllCertificates;
  28. public SSHUserInfo() {
  29. super();
  30. this.trustAllCertificates = false;
  31. }
  32. public SSHUserInfo(String password, boolean trustAllCertificates) {
  33. super();
  34. this.password = password;
  35. this.trustAllCertificates = trustAllCertificates;
  36. }
  37. /**
  38. * @see com.jcraft.jsch.UserInfo#getName()
  39. */
  40. public String getName() {
  41. return name;
  42. }
  43. /**
  44. * @see com.jcraft.jsch.UserInfo#getPassphrase(String)
  45. */
  46. public String getPassphrase(String message) {
  47. return passphrase;
  48. }
  49. /**
  50. * @see com.jcraft.jsch.UserInfo#getPassword()
  51. */
  52. public String getPassword() {
  53. return password;
  54. }
  55. /**
  56. * @see com.jcraft.jsch.UserInfo#prompt(String)
  57. */
  58. public boolean prompt(String str) {
  59. return false;
  60. }
  61. /**
  62. * @see com.jcraft.jsch.UserInfo#retry()
  63. */
  64. public boolean retry() {
  65. return false;
  66. }
  67. /**
  68. * Sets the name.
  69. * @param name The name to set
  70. */
  71. public void setName(String name) {
  72. this.name = name;
  73. }
  74. /**
  75. * Sets the passphrase.
  76. * @param passphrase The passphrase to set
  77. */
  78. public void setPassphrase(String passphrase) {
  79. this.passphrase = passphrase;
  80. }
  81. /**
  82. * Sets the password.
  83. * @param password The password to set
  84. */
  85. public void setPassword(String password) {
  86. this.password = password;
  87. }
  88. /**
  89. * Sets the trust.
  90. * @param trust whether to trust or not.
  91. */
  92. public void setTrust(boolean trust) {
  93. this.trustAllCertificates = trust;
  94. }
  95. /**
  96. * @return whether to trust or not.
  97. */
  98. public boolean getTrust() {
  99. return this.trustAllCertificates;
  100. }
  101. /**
  102. * Returns the passphrase.
  103. * @return String
  104. */
  105. public String getPassphrase() {
  106. return passphrase;
  107. }
  108. /**
  109. * Returns the keyfile.
  110. * @return String
  111. */
  112. public String getKeyfile() {
  113. return keyfile;
  114. }
  115. /**
  116. * Sets the keyfile.
  117. * @param keyfile The keyfile to set
  118. */
  119. public void setKeyfile(String keyfile) {
  120. this.keyfile = keyfile;
  121. }
  122. /**
  123. * @see com.jcraft.jsch.UserInfo#promptPassphrase(String)
  124. */
  125. public boolean promptPassphrase(String message) {
  126. return true;
  127. }
  128. /**
  129. * @see com.jcraft.jsch.UserInfo#promptPassword(String)
  130. */
  131. public boolean promptPassword(String passwordPrompt) {
  132. //log(passwordPrompt, Project.MSG_DEBUG);
  133. if (firstTime) {
  134. firstTime = false;
  135. return true;
  136. }
  137. return firstTime;
  138. }
  139. /**
  140. * @see com.jcraft.jsch.UserInfo#promptYesNo(String)
  141. */
  142. public boolean promptYesNo(String message) {
  143. //log(prompt, Project.MSG_DEBUG);
  144. return trustAllCertificates;
  145. }
  146. /**
  147. * @see com.jcraft.jsch.UserInfo#showMessage(String)
  148. */
  149. public void showMessage(String message) {
  150. //log(message, Project.MSG_DEBUG);
  151. }
  152. }