How to set preferred authentication methods in Camel SFTP component?

Solution Verified - Updated -

Environment

  • JBoss Fuse 6.1

Issue

We would like to specify the preferred authentications methods of the Camel SFTP component in order to avoid some gssapi-with-mic authentication issue she encountered. By default Camel relies on the default authentication methods of JSCH, which include gssapi-with-mic.

Resolution

Engineering added new optional preferredAuthentications option to the Camel SFTP component. The option is available starting from Camel 2.10.7, 2.11.2 and 2.12.0. This option is available since JBoss Fuse 6.1.

If you want to explicitly specify the list of authentication methods that should be used by the sftp component, use the preferredAuthentications option. If for example you would like Camel to attempt to authenticate with private/public SSH key and fallback to user/password authentication in the case when no public key is available, use the following route configuration:

from("sftp://localhost:9999/root?username=admin&password=admin&preferredAuthentications=publickey,password").
  to("bean:processFile");

The Camel issue related to the problem is CAMEL-6653. Usage of new preferredAuthentications option is described in the Camel SFTP component page - http://camel.apache.org/ftp2.

NOTE: There is a workaround for JBoss Fuse 6.0 users where they can place the follwoing snippet in the route builder class of the route which uses SFTP endpoint:

 // The preferred authentication methods to be used by JSCH which is utilised by 
    // the Camel-SFTP component
    private static final String JSCH_PREFFERRED_AUTHENTICATIONS_KEY = "PreferredAuthentications";

    /**
     * Sets the global JSch Preferred authentication methods (comma separated)
     * 
     * @param aPreferredAuthentications the preferredAuthentication to set
     */
    public void setPreferredAuthentications(String aPreferredAuthentications) {
        JSch.setConfig(JSCH_PREFFERRED_AUTHENTICATIONS_KEY, aPreferredAuthentications);
    }

Please note that while the above sets the preferred authentication method, it will not prevent that to be overridden on a session by session basis when that facility becomes available in JBoss Fuse 6.1.

Root Cause

Before Camel 2.10.7, 2.11.2 and 2.12.0 there was no way to pass preferredAuthentications option to the JSCH client used internally by Camel SFTP component.

Diagnostic Steps

Try to pass preferredAuthentications option to the endpoint (as demonstrated in the snippet below). If Camel won't complain about the unknown endpoint option, then you are using the right version of the former (2.10.7, 2.11.2 or 2.12.0).

from("sftp://localhost:9999/root?username=admin&password=admin&preferredAuthentications=publickey,password").
  to("bean:processFile");

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments