Loading

How to get rid of the " IdentityFile not found " exception when using SFTP connector with key authentication in place

Julkaisupäivä: Mar 2, 2024
Ratkaisu
SYMPTOM

You have an application which implements an SFTP message receiver ( at flow receiver side), or an SFTP dispatcher ( at flow process side), which has key authentication configured through the Connector Configuration->General->Authentication->Identity File and Connector->Advanced->Passphrase properties set up as expected.
 
Even when you have your PKI private key file located under application's src/main/resources folder , and you had set up the file name under the Connector Configuration->General->Authentication->IdentityFile as expected,  mule fails at run-time,  throwing the following exception:  ( suppose we have workday.cer configured as the PKI private key file )
 
Unexpected exception attempting to write file, message was: IdentityFile 'workday.cer' not found
java.io.IOException: IdentityFile 'workday.cer' not found
 
And on the mule logs, you would be able to see the following accompanying stack trace:
 
java.io.IOException: IdentityFile 'workday.cer' not found
    at org.mule.transport.sftp.SftpClient.login(SftpClient.java:170)
    at org.mule.transport.sftp.SftpConnectionFactory.createClient(SftpConnectionFactory.java:112)
    at org.mule.transport.sftp.SftpConnector.createSftpClient(SftpConnector.java:195)
    at org.mule.transport.sftp.SftpMessageDispatcher.doDispatch(SftpMessageDispatcher.java:77)
    at org.mule.transport.AbstractMessageDispatcher.process(AbstractMessageDispatcher.java:109)
    at org.mule.transport.AbstractConnector$DispatcherMessageProcessor.process(AbstractConnector.java:2724)
 
CAUSE

This is caused by the mule SFTP transport, which does not honors the mule common class-loader mechanism to look-up any resource, and tries to pick up the file from file system in a direct way, as shown below: ( snippet from org.mule.transport.sftp.SftpClient.login )
 
public void login(String user, String identityFile, String passphrase) throws IOException
    {
        // Lets first check that the identityFile exist
        if (!new File(identityFile).exists())
        {
            throw new IOException("IdentityFile '" + identityFile + "' not found");
        }
 
Making the file location absolute, breaks with the application self-containing approach, because you cannot specify a relative path inside the standard src/main/resources folder.

SOLUTION
 
To overcome this condition, you have to specify an absolute location on the IdentityFile field  , but using an environment variable to provide the exact location of your application home, as shown below:

${app.home}/classes/workday.cer

In run-time, mule will replace ${app.home| with the actual application home on the filesystem, inside your mule home directory.  The "classes" subfolder represents the place where all the resources defined on build-time under your application's src/main/resources folder are copied on run-time, so mule will be able to locate the PKI private key as expected.
Knowledge-artikkelin numero

001118492

 
Ladataan
Salesforce Help | Article