Advertisement
Guest User

Untitled

a guest
Jul 31st, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. import com.jcraft.jsch.UIKeyboardInteractive;
  2. import com.jcraft.jsch.UserInfo;
  3.  
  4. public class MyUserInfo implements UserInfo, UIKeyboardInteractive{
  5.    
  6.     /** LOG is the logger object of class */
  7.     private static final Logger LOG = Logger.getLogger(MyUserInfo.class);
  8.  
  9.     private String username;
  10.     private String password;
  11.    
  12.    
  13.     public MyUserInfo(String username, String password){
  14.         this.username = username;
  15.         this.password = password;
  16.     }
  17.    
  18.    
  19.     /**
  20.      * This method is overriding the getPassphrase method.
  21.      *
  22.      * @see com.jcraft.jsch.UserInfo#getPassphrase()
  23.      */
  24.     public String getPassphrase() {
  25.         return null;
  26.     }
  27.  
  28.     /**
  29.      * This method is overriding the getPassword method.
  30.      *
  31.      * @see com.jcraft.jsch.UserInfo#getPassword()
  32.      */
  33.     public String getPassword() {
  34.         return password;
  35.     }
  36.  
  37.     /**
  38.      * This method is overriding the promptPassphrase method.
  39.      *
  40.      * @see com.jcraft.jsch.UserInfo#promptPassphrase(java.lang.String)
  41.      */
  42.     public boolean promptPassphrase(String arg0) {
  43.         return true;
  44.     }
  45.  
  46.     /**
  47.      * This method is overriding the promptPassword method.
  48.      *
  49.      * @see com.jcraft.jsch.UserInfo#promptPassword(java.lang.String)
  50.      */
  51.     public boolean promptPassword(String arg0) {
  52.         return true;
  53.     }
  54.  
  55.     /**
  56.      * This method is overriding the promptYesNo method.
  57.      *
  58.      * @see com.jcraft.jsch.UserInfo#promptYesNo(java.lang.String)
  59.      */
  60.     public boolean promptYesNo(String arg0) {
  61.         return true;
  62.     }
  63.  
  64.     /**
  65.      * This method is overriding the showMessage method.
  66.      *
  67.      * @see com.jcraft.jsch.UserInfo#showMessage(java.lang.String)
  68.      */
  69.     public void showMessage(String arg0) {
  70.     }
  71.  
  72.     /**
  73.      * This method is overriding the promptKeyboardInteractive method.
  74.      * response size MUST be equal to prompt size
  75.      *
  76.      *
  77.      * @see com.jcraft.jsch.UIKeyboardInteractive#promptKeyboardInteractive(java.lang.String, java.lang.String, java.lang.String, java.lang.String[], boolean[])
  78.      */
  79.     public String[] promptKeyboardInteractive(String arg0, String arg1,
  80.             String arg2, String[] prompts, boolean[] echos) {
  81.        
  82.         String response[] = new String[prompts.length];
  83.         for(int i = 0 ; i < prompts.length; i++){
  84.             LOG.debug("Received keyboard prompt..");
  85.             if(echos[i])
  86.                 response[i] = username;
  87.             else response[i] = password;
  88.         }
  89.         return response;
  90.     }
  91.  
  92.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement