You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2022/04/20 14:55:05 UTC

[nifi] 02/04: NIFI-9939 Upgraded SSHJ from 0.32.0 to 0.33.0

This is an automated email from the ASF dual-hosted git repository.

joewitt pushed a commit to branch support/nifi-1.16
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit e4d8cd99d295f4a7f91c3dcd8182d94a70520523
Author: exceptionfactory <ex...@apache.org>
AuthorDate: Wed Apr 20 07:59:20 2022 -0500

    NIFI-9939 Upgraded SSHJ from 0.32.0 to 0.33.0
    
    - Removed PatchedSFTPEngine with resolution of SFTP renaming in SSHJ 0.33.0
    
    Signed-off-by: Pierre Villard <pi...@gmail.com>
    
    This closes #5982.
---
 .../processors/standard/ssh/PatchedSFTPEngine.java | 72 ----------------------
 .../processors/standard/util/SFTPTransfer.java     |  4 +-
 nifi-nar-bundles/nifi-standard-bundle/pom.xml      |  2 +-
 3 files changed, 3 insertions(+), 75 deletions(-)

diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ssh/PatchedSFTPEngine.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ssh/PatchedSFTPEngine.java
deleted file mode 100644
index 1de696d504..0000000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ssh/PatchedSFTPEngine.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.processors.standard.ssh;
-
-import net.schmizz.sshj.common.SSHException;
-import net.schmizz.sshj.connection.channel.direct.SessionFactory;
-import net.schmizz.sshj.sftp.PacketType;
-import net.schmizz.sshj.sftp.RenameFlags;
-import net.schmizz.sshj.sftp.Request;
-import net.schmizz.sshj.sftp.SFTPEngine;
-import net.schmizz.sshj.sftp.SFTPException;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Patched SFTP Engine to workaround SFTP rename issue 751 in SSHJ 0.32.0
- *
- * This class can be removed once the issue is resolved in a future version of SSHJ
- */
-public class PatchedSFTPEngine extends SFTPEngine {
-
-    public PatchedSFTPEngine(final SessionFactory sessionFactory) throws SSHException {
-        super(sessionFactory);
-    }
-
-    /**
-     * Override rename request packet generation to workaround handling of rename flags
-     *
-     * @param oldPath Old path of file to be renamed
-     * @param newPath New path of file to be renamed
-     * @param flags Rename flags used for SFTP Version 5 or higher
-     * @throws IOException Thrown on unsupported protocol version or request processing failures
-     */
-    @Override
-    public void rename(final String oldPath, final String newPath, final Set<RenameFlags> flags) throws IOException {
-        if (operativeVersion < 1) {
-            throw new SFTPException("RENAME is not supported in SFTPv" + operativeVersion);
-        }
-
-        final Charset remoteCharset = sub.getRemoteCharset();
-        final Request request = newRequest(PacketType.RENAME)
-                .putString(oldPath, remoteCharset)
-                .putString(newPath, remoteCharset);
-        // SFTP Version 5 introduced rename flags according to Section 6.5 of the specification
-        if (operativeVersion >= 5) {
-            long renameFlagMask = 0L;
-            for (RenameFlags flag : flags) {
-                renameFlagMask = renameFlagMask | flag.longValue();
-            }
-            request.putUInt32(renameFlagMask);
-        }
-
-        request(request).retrieve(getTimeoutMs(), TimeUnit.MILLISECONDS).ensureStatusPacketIsOK();
-    }
-}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java
index 628b9825c7..2e58ee122d 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java
@@ -26,6 +26,7 @@ import net.schmizz.sshj.sftp.RemoteResourceFilter;
 import net.schmizz.sshj.sftp.RemoteResourceInfo;
 import net.schmizz.sshj.sftp.Response;
 import net.schmizz.sshj.sftp.SFTPClient;
+import net.schmizz.sshj.sftp.SFTPEngine;
 import net.schmizz.sshj.sftp.SFTPException;
 import net.schmizz.sshj.xfer.FilePermission;
 import net.schmizz.sshj.xfer.LocalSourceFile;
@@ -42,7 +43,6 @@ import org.apache.nifi.logging.ComponentLog;
 import org.apache.nifi.processor.ProcessSession;
 import org.apache.nifi.processor.exception.ProcessException;
 import org.apache.nifi.processor.util.StandardValidators;
-import org.apache.nifi.processors.standard.ssh.PatchedSFTPEngine;
 import org.apache.nifi.processors.standard.ssh.SSHClientProvider;
 import org.apache.nifi.processors.standard.ssh.StandardSSHClientProvider;
 import org.apache.nifi.proxy.ProxyConfiguration;
@@ -596,7 +596,7 @@ public class SFTPTransfer implements FileTransfer {
 
         final Map<String, String> attributes = flowFile == null ? Collections.emptyMap() : flowFile.getAttributes();
         this.sshClient = SSH_CLIENT_PROVIDER.getClient(ctx, attributes);
-        this.sftpClient = new SFTPClient(new PatchedSFTPEngine(sshClient).init());
+        this.sftpClient = new SFTPClient(new SFTPEngine(sshClient).init());
         this.closed = false;
 
         // Configure timeout for sftp operations
diff --git a/nifi-nar-bundles/nifi-standard-bundle/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/pom.xml
index 07fc0c815c..d21d746f57 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/pom.xml
+++ b/nifi-nar-bundles/nifi-standard-bundle/pom.xml
@@ -181,7 +181,7 @@
             <dependency>
                 <groupId>com.hierynomus</groupId>
                 <artifactId>sshj</artifactId>
-                <version>0.32.0</version>
+                <version>0.33.0</version>
             </dependency>
             <dependency>
                 <groupId>jakarta.activation</groupId>