camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ujeen <uj...@ujeen.com>
Subject The SFTP component: the keyboard-interactive auth method support
Date Thu, 29 Sep 2011 15:18:04 GMT
Hi Camel gurus.

I've got some small improvement for the SFTP component which probably might
be handy.

It appeared that our sftp share we get files from doesn't support the ssh
password auth method and we're not allowed to put the public key to there.
So the only ssh auth method we can use is the keyboard-interactive.
Unfortunately the SFTP camel component doesn't support this. 
However this can be easily fixed simply by providing the Jsch session with
both the  com.jcraft.jsch.UserInfo and com.jcraft.jsch.UIKeyboardInteractive
interfaces. The UIKeyboardInteractive has the only one
promptKeyboardInteractive method which returns String[] containing the
password entered by user interactively. In our case I simply return a
password. 
Here is how I implemented this:

SftpOperations operations = new SftpOperations() {
    protected Session createSession(final RemoteFileConfiguration
configuration) throws JSchException {
	final Session result = super.createSession(configuration);
	if(compression > 0 && compression < 10) {
		result.setConfig("compression.s2c", "zlib@openssh.com,zlib,none");
		result.setConfig("compression.c2s", "zlib@openssh.com,zlib,none");
		result.setConfig("compression_level", Integer.toString(compression));
	}
	final UserInfo userInfo = result.getUserInfo();
	result.setUserInfo(new ExtendedUserInfo() {
  	        public String getPassphrase() {return userInfo.getPassphrase();}
		public String getPassword() {return userInfo.getPassword();}
		public boolean promptPassword(String s) {return
userInfo.promptPassword(s);}
		public boolean promptPassphrase(String s) {return
userInfo.promptPassphrase(s);}
		public boolean promptYesNo(String s) {return userInfo.promptYesNo(s);	}
		public void showMessage(String s) {userInfo.showMessage(s);}
		public String[] promptKeyboardInteractive(
                                     String destination, String name,
				     String instruction, String[] prompt, boolean[] echo) {
			return new String[] { this.getPassword() };
		}
	});
	return result;
}};
 

Also as you could note I set the compression level there. Since we're moving
really huge files (2G and longer) via sftp I thought that setting the ssh
compression might be a good idea. It really helps. I pass them via
endpoint's uri. This requires the zlib kib to be in the classpath 
<dependency>
    <groupId>com.jcraft</groupId>
    <artifactId>jzlib</artifactId>
    <version>1.0.7</version>
</dependency>

That's it. I hope this is useful for you. Sorry if it's not.

Thanks for the Camel.
 

--
View this message in context: http://camel.465427.n5.nabble.com/The-SFTP-component-the-keyboard-interactive-auth-method-support-tp4853523p4853523.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message