1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package jatoo.exec.remote;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import com.jcraft.jsch.UserInfo;
24
25
26
27
28
29
30
31 public final class RemoteCommandExecutorJCraftUserInfo implements UserInfo {
32
33
34 private final Log logger = LogFactory.getLog(RemoteCommandExecutorJCraftUserInfo.class);
35
36 private final String password;
37
38 private boolean isAlreadyPrompted = false;
39
40 public RemoteCommandExecutorJCraftUserInfo(final String password) {
41 this.password = password;
42 }
43
44 @Override
45 public boolean promptPassword(final String message) {
46
47 if (isAlreadyPrompted) {
48 logger.error("Something went wrong, we are prompted again for passwordat. Maybe wrong password?");
49 throw new RuntimeException("Wrong password?");
50 }
51
52 isAlreadyPrompted = true;
53
54 logger.info(message);
55 logger.info("No need to prompt for password, the password was passed through constructor.");
56 return true;
57 }
58
59 @Override
60 public String getPassword() {
61 return password;
62 }
63
64 @Override
65 public boolean promptYesNo(final String message) {
66 logger.info(message);
67 logger.info("Auto accepting the fingerprint, because I was told to do so.");
68 return true;
69 }
70
71 @Override
72 public void showMessage(final String message) {
73 logger.info(message);
74 }
75
76 @Override
77 public boolean promptPassphrase(final String message) {
78 logger.info(message);
79 logger.info("No need to prompt for passphrase, the method #getPassphrase() will always return null.");
80 return true;
81 }
82
83 @Override
84 public String getPassphrase() {
85 return null;
86 }
87
88 }