From 64eafb6f1f5504bd74861e902c0d15ae02dca510 Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 14:17:22 +0530 Subject: [PATCH 01/12] Add option for preferred auth method in auth configs --- ballerina/commons.bal | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ballerina/commons.bal b/ballerina/commons.bal index 4471e825..fd955847 100644 --- a/ballerina/commons.bal +++ b/ballerina/commons.bal @@ -48,11 +48,20 @@ public type Credentials record {| # # + credentials - Username and password to be used # + privateKey - Private key to be used +# + preferredMethods - Preferred authentication methods public type AuthConfiguration record {| Credentials credentials?; PrivateKey privateKey?; + PreferredMethod[] preferredMethods?; |}; +public enum PreferredMethod { + KEYBOARD_INTERACTIVE, + GSSAPI_WITH_MIC, + PASSWORD, + PUBLICKEY +} + # Configuration for the input given for `put` and `append` operations of # the FTP module. # From 1747c3078e6658e792e4124db1f80e602a4ca7a5 Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 14:17:59 +0530 Subject: [PATCH 02/12] Update mock sftp client initialization with `preferredMethods` field --- ballerina/tests/client_endpoint_test.bal | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ballerina/tests/client_endpoint_test.bal b/ballerina/tests/client_endpoint_test.bal index a37451d6..927cc5b9 100644 --- a/ballerina/tests/client_endpoint_test.bal +++ b/ballerina/tests/client_endpoint_test.bal @@ -51,7 +51,8 @@ ClientConfiguration sftpConfig = { privateKey: { path: "tests/resources/sftp.private.key", password: "changeit" - } + }, + preferredMethods: [GSSAPI_WITH_MIC, PUBLICKEY, KEYBOARD_INTERACTIVE, PASSWORD] } }; From 34277a6994a881b90807e20673e0611823e92f1f Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 14:18:58 +0530 Subject: [PATCH 03/12] Update native code to support preferred auth method in SFTP client initialization --- .../io/ballerina/stdlib/ftp/client/FtpClient.java | 14 ++++++++++++++ .../transport/server/util/FileTransportUtils.java | 10 ++++++++-- .../io/ballerina/stdlib/ftp/util/FtpConstants.java | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java b/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java index e53bba15..a05cdda4 100644 --- a/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java +++ b/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BString; @@ -41,9 +42,12 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; +import static io.ballerina.stdlib.ftp.util.FtpConstants.ENDPOINT_CONFIG_PREFERRED_METHODS; import static io.ballerina.stdlib.ftp.util.FtpConstants.ENTITY_BYTE_STREAM; import static io.ballerina.stdlib.ftp.util.FtpConstants.READ_INPUT_STREAM; import static io.ballerina.stdlib.ftp.util.FtpConstants.VFS_CLIENT_CONNECTOR; @@ -90,6 +94,16 @@ public static Object initClientEndpoint(BObject clientEndpoint, BMap options, FileSystemOptions private static void setSftpOptions(Map options, FileSystemOptions opts) throws RemoteFileSystemConnectorException { final SftpFileSystemConfigBuilder configBuilder = SftpFileSystemConfigBuilder.getInstance(); - configBuilder.setPreferredAuthentications(opts, - "gssapi-with-mic,publickey,keyboard-interactive,password"); + if (options.containsKey(ENDPOINT_CONFIG_PREFERRED_METHODS)) { + String value = options.get(ENDPOINT_CONFIG_PREFERRED_METHODS); + configBuilder.setPreferredAuthentications(opts, value); + } else { + configBuilder.setPreferredAuthentications(opts, + "gssapi-with-mic,publickey,keyboard-interactive,password"); + } if (options.get(FtpConstants.USER_DIR_IS_ROOT) != null) { configBuilder.setUserDirIsRoot(opts, false); } diff --git a/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java b/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java index 9d03f78d..64710f6f 100644 --- a/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java +++ b/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java @@ -77,6 +77,7 @@ private FtpConstants() { public static final String ENDPOINT_CONFIG_AUTH = "auth"; public static final String ENDPOINT_CONFIG_CREDENTIALS = "credentials"; public static final String ENDPOINT_CONFIG_PRIVATE_KEY = "privateKey"; + public static final String ENDPOINT_CONFIG_PREFERRED_METHODS = "preferredMethods"; public static final String INPUT_CONTENT_FILE_PATH_KEY = "filePath"; public static final String INPUT_CONTENT_IS_FILE_KEY = "isFile"; From b14673c0fcfd91942b5e1017f8f2e24725ff983d Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 14:19:39 +0530 Subject: [PATCH 04/12] Add doc comments to the `PreferredMethod` type --- ballerina/commons.bal | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ballerina/commons.bal b/ballerina/commons.bal index fd955847..36975c75 100644 --- a/ballerina/commons.bal +++ b/ballerina/commons.bal @@ -52,9 +52,15 @@ public type Credentials record {| public type AuthConfiguration record {| Credentials credentials?; PrivateKey privateKey?; - PreferredMethod[] preferredMethods?; + PreferredMethod[] preferredMethods = [PUBLICKEY, PASSWORD]; |}; +# Authentication methods for the FTP listener. +# +# + KEYBOARD_INTERACTIVE - Keyboard interactive authentication +# + GSSAPI_WITH_MIC - GSSAPI with MIC authentication +# + PASSWORD - Password authentication +# + PUBLICKEY - Public key authentication public enum PreferredMethod { KEYBOARD_INTERACTIVE, GSSAPI_WITH_MIC, From b512bafe80c5217c6600e5db79dd763732ceef0b Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 14:24:32 +0530 Subject: [PATCH 05/12] Remove hardcoded preferred auth methods --- .../stdlib/ftp/transport/server/util/FileTransportUtils.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/ftp/transport/server/util/FileTransportUtils.java b/native/src/main/java/io/ballerina/stdlib/ftp/transport/server/util/FileTransportUtils.java index 7e57204c..293c7f24 100644 --- a/native/src/main/java/io/ballerina/stdlib/ftp/transport/server/util/FileTransportUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/ftp/transport/server/util/FileTransportUtils.java @@ -86,9 +86,6 @@ private static void setSftpOptions(Map options, FileSystemOption if (options.containsKey(ENDPOINT_CONFIG_PREFERRED_METHODS)) { String value = options.get(ENDPOINT_CONFIG_PREFERRED_METHODS); configBuilder.setPreferredAuthentications(opts, value); - } else { - configBuilder.setPreferredAuthentications(opts, - "gssapi-with-mic,publickey,keyboard-interactive,password"); } if (options.get(FtpConstants.USER_DIR_IS_ROOT) != null) { configBuilder.setUserDirIsRoot(opts, false); From 30088b96d78f82c7d0d7ddc06a63d4172e1873d9 Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 14:47:07 +0530 Subject: [PATCH 06/12] Return error when the `preferredMethods` field is empty --- .../main/java/io/ballerina/stdlib/ftp/client/FtpClient.java | 4 ++++ .../ftp/transport/server/util/FileTransportUtils.java | 6 ++---- .../java/io/ballerina/stdlib/ftp/util/FtpConstants.java | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java b/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java index a05cdda4..f47dfa7a 100644 --- a/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java +++ b/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java @@ -49,6 +49,7 @@ import static io.ballerina.stdlib.ftp.util.FtpConstants.ENDPOINT_CONFIG_PREFERRED_METHODS; import static io.ballerina.stdlib.ftp.util.FtpConstants.ENTITY_BYTE_STREAM; +import static io.ballerina.stdlib.ftp.util.FtpConstants.NO_AUTH_METHOD_ERROR; import static io.ballerina.stdlib.ftp.util.FtpConstants.READ_INPUT_STREAM; import static io.ballerina.stdlib.ftp.util.FtpConstants.VFS_CLIENT_CONNECTOR; import static io.ballerina.stdlib.ftp.util.FtpUtil.ErrorType.Error; @@ -97,6 +98,9 @@ public static Object initClientEndpoint(BObject clientEndpoint, BMap options, FileSystemOptions private static void setSftpOptions(Map options, FileSystemOptions opts) throws RemoteFileSystemConnectorException { final SftpFileSystemConfigBuilder configBuilder = SftpFileSystemConfigBuilder.getInstance(); - if (options.containsKey(ENDPOINT_CONFIG_PREFERRED_METHODS)) { - String value = options.get(ENDPOINT_CONFIG_PREFERRED_METHODS); - configBuilder.setPreferredAuthentications(opts, value); - } + String value = options.get(ENDPOINT_CONFIG_PREFERRED_METHODS); + configBuilder.setPreferredAuthentications(opts, value); if (options.get(FtpConstants.USER_DIR_IS_ROOT) != null) { configBuilder.setUserDirIsRoot(opts, false); } diff --git a/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java b/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java index 64710f6f..f5fd7e44 100644 --- a/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java +++ b/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java @@ -88,6 +88,7 @@ private FtpConstants() { public static final String ON_FILE_CHANGE_REMOTE_FUNCTION = "onFileChange"; public static final String APACHE_VFS2_PACKAGE_NAME = "org.apache.commons.vfs2"; public static final String BALLERINA_FTP_PACKAGE_NAME = "io.ballerina.stdlib.ftp"; + public static final String NO_AUTH_METHOD_ERROR = "No preferred auth method is specified in the SFTP client"; public static final StrandMetadata ON_FILECHANGE_METADATA = new StrandMetadata(ModuleUtils.getModule().getOrg(), ModuleUtils.getModule().getName(), ModuleUtils.getModule().getMajorVersion(), From b5f9b60cb70d6354bbb578e2fd012ca74f7188a9 Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 14:53:01 +0530 Subject: [PATCH 07/12] Fix error message for no preferred auth method --- .../main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java b/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java index f5fd7e44..49501098 100644 --- a/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java +++ b/native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java @@ -88,7 +88,8 @@ private FtpConstants() { public static final String ON_FILE_CHANGE_REMOTE_FUNCTION = "onFileChange"; public static final String APACHE_VFS2_PACKAGE_NAME = "org.apache.commons.vfs2"; public static final String BALLERINA_FTP_PACKAGE_NAME = "io.ballerina.stdlib.ftp"; - public static final String NO_AUTH_METHOD_ERROR = "No preferred auth method is specified in the SFTP client"; + public static final String NO_AUTH_METHOD_ERROR = "No preferred auth method is specified in the " + + "SFTP client configurations"; public static final StrandMetadata ON_FILECHANGE_METADATA = new StrandMetadata(ModuleUtils.getModule().getOrg(), ModuleUtils.getModule().getName(), ModuleUtils.getModule().getMajorVersion(), From 756b0c114a3a652e91c5c862def2f6b21e3cc60c Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 15:16:28 +0530 Subject: [PATCH 08/12] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index eebaa7ba..889d27d0 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "ftp" -version = "2.9.1" +version = "2.9.2" authors = ["Ballerina"] keywords = ["FTP", "SFTP", "remote file", "file transfer", "client", "service"] repository = "https://github.com/ballerina-platform/module-ballerina-ftp" @@ -33,5 +33,5 @@ path = "./lib/commons-net-3.9.0.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "ftp-native" -version = "2.9.1" -path = "../native/build/libs/ftp-native-2.9.1.jar" +version = "2.9.2" +path = "../native/build/libs/ftp-native-2.9.2-SNAPSHOT.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index d636490b..4afe14eb 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "ftp-compiler-plugin" class = "io.ballerina.stdlib.ftp.plugin.FtpCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/ftp-compiler-plugin-2.9.1.jar" +path = "../compiler-plugin/build/libs/ftp-compiler-plugin-2.9.2-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1d9433c5..29b6df71 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -10,7 +10,7 @@ distribution-version = "2201.8.0" [[package]] org = "ballerina" name = "ftp" -version = "2.9.1" +version = "2.9.2" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -112,7 +112,7 @@ modules = [ [[package]] org = "ballerina" name = "observe" -version = "1.2.0" +version = "1.2.3" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] From edd5e77b91dfe68f2d7b668aeb52a2c1d444fbd1 Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 15:20:00 +0530 Subject: [PATCH 09/12] Move the string combination into separate methods --- .../stdlib/ftp/client/FtpClient.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java b/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java index f47dfa7a..00113c6d 100644 --- a/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java +++ b/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java @@ -101,12 +101,8 @@ public static Object initClientEndpoint(BObject clientEndpoint, BMap Date: Tue, 23 Jul 2024 15:20:24 +0530 Subject: [PATCH 10/12] Bump the FTP version to 2.10.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 7849ed61..aaa5fd0a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ org.gradle.caching=true group=io.ballerina.stdlib -version=2.9.2-SNAPSHOT +version=2.10.0-SNAPSHOT puppycrawlCheckstyleVersion=10.12.0 testngVersion=7.6.1 From 86b35fd541f492478e0e2fac9398d7501cabb510 Mon Sep 17 00:00:00 2001 From: Nuvindu Date: Tue, 23 Jul 2024 15:24:50 +0530 Subject: [PATCH 11/12] Apply suggestions from the review --- .../stdlib/ftp/client/FtpClient.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java b/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java index 00113c6d..c2356e39 100644 --- a/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java +++ b/native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java @@ -101,8 +101,10 @@ public static Object initClientEndpoint(BObject clientEndpoint, BMap Date: Tue, 23 Jul 2024 15:28:04 +0530 Subject: [PATCH 12/12] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 889d27d0..5433766e 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "ftp" -version = "2.9.2" +version = "2.10.0" authors = ["Ballerina"] keywords = ["FTP", "SFTP", "remote file", "file transfer", "client", "service"] repository = "https://github.com/ballerina-platform/module-ballerina-ftp" @@ -33,5 +33,5 @@ path = "./lib/commons-net-3.9.0.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "ftp-native" -version = "2.9.2" -path = "../native/build/libs/ftp-native-2.9.2-SNAPSHOT.jar" +version = "2.10.0" +path = "../native/build/libs/ftp-native-2.10.0-SNAPSHOT.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 4afe14eb..7e52044e 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "ftp-compiler-plugin" class = "io.ballerina.stdlib.ftp.plugin.FtpCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/ftp-compiler-plugin-2.9.2-SNAPSHOT.jar" +path = "../compiler-plugin/build/libs/ftp-compiler-plugin-2.10.0-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 29b6df71..17a725b9 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -10,7 +10,7 @@ distribution-version = "2201.8.0" [[package]] org = "ballerina" name = "ftp" -version = "2.9.2" +version = "2.10.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"},