diff --git a/CHANGELOG.md b/CHANGELOG.md
index bc3af7ecf..35e917c24 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
### 新特性
### Bug修复
+* 【extra】 修复遗留的getSession端口判断错误(issue#594@Github)
-------------------------------------------------------------------------------------------------------------
diff --git a/README.md b/README.md
index 95fc4846c..35153e236 100644
--- a/README.md
+++ b/README.md
@@ -51,7 +51,7 @@ Hutool是一个小而全的Java工具类库,通过静态方法封装,降低
Hutool中的工具方法来自于每个用户的精雕细琢,它涵盖了Java开发底层代码中的方方面面,它既是大型项目开发中解决小问题的利器,也是小型项目中的效率担当;
-Hutool是项目中“util”包友好的替代,它节省了我们对项目中公用类和公用工具方法的封装时间,使开发专注于业务,同时可以最大限度的避免封装不完善带来的bug。
+Hutool是项目中“util”包友好的替代,它节省了开发人员对项目中公用类和公用工具方法的封装时间,使开发专注于业务,同时可以最大限度的避免封装不完善带来的bug。
### Hutool名称的由来
diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ssh/JschUtil.java b/hutool-extra/src/main/java/cn/hutool/extra/ssh/JschUtil.java
index 63c4bb6a2..7bff2b934 100644
--- a/hutool-extra/src/main/java/cn/hutool/extra/ssh/JschUtil.java
+++ b/hutool-extra/src/main/java/cn/hutool/extra/ssh/JschUtil.java
@@ -119,28 +119,13 @@ public class JschUtil {
* @since 4.5.2
*/
public static Session createSession(String sshHost, int sshPort, String sshUser, String sshPass) {
- Assert.notEmpty(sshHost, "SSH Host must be not empty!");
- Assert.isTrue(sshPort < 0, "SSH Host must be not empty!");
-
- // 默认root用户
- if (StrUtil.isEmpty(sshUser)) {
- sshUser = "root";
- }
-
final JSch jsch = new JSch();
- Session session;
- try {
- session = jsch.getSession(sshUser, sshHost, sshPort);
- } catch (JSchException e) {
- throw new JschRuntimeException(e);
- }
+ final Session session = createSession(jsch, sshHost, sshPort, sshUser);
if (StrUtil.isNotEmpty(sshPass)) {
session.setPassword(sshPass);
}
- // 设置第一次登陆的时候提示,可选值:(ask | yes | no)
- session.setConfig("StrictHostKeyChecking", "no");
return session;
}
@@ -156,19 +141,43 @@ public class JschUtil {
* @since 5.0.0
*/
public static Session createSession(String sshHost, int sshPort, String sshUser, String privateKeyPath, byte[] passphrase) {
+ Assert.notEmpty(privateKeyPath, "PrivateKey Path must be not empty!");
+
+ final JSch jsch = new JSch();
+ try {
+ jsch.addIdentity(privateKeyPath, passphrase);
+ } catch (JSchException e) {
+ throw new JschRuntimeException(e);
+ }
+
+ return createSession(jsch, sshHost, sshPort, sshUser);
+ }
+
+ /**
+ * 创建一个SSH会话,重用已经使用的会话
+ *
+ * @param jsch {@link JSch}
+ * @param sshHost 主机
+ * @param sshPort 端口
+ * @param sshUser 用户名,如果为null,默认root
+ * @return {@link Session}
+ * @since 5.0.3
+ */
+ public static Session createSession(JSch jsch, String sshHost, int sshPort, String sshUser) {
Assert.notEmpty(sshHost, "SSH Host must be not empty!");
Assert.isTrue(sshPort > 0, "SSH port must be > 0");
- Assert.notEmpty(privateKeyPath, "PrivateKey Path must be not empty!");
// 默认root用户
if (StrUtil.isEmpty(sshUser)) {
sshUser = "root";
}
- final JSch jsch = new JSch();
+ if(null == jsch){
+ jsch = new JSch();
+ }
+
Session session;
try {
- jsch.addIdentity(privateKeyPath, passphrase);
session = jsch.getSession(sshUser, sshHost, sshPort);
} catch (JSchException e) {
throw new JschRuntimeException(e);
@@ -176,6 +185,7 @@ public class JschUtil {
// 设置第一次登录的时候提示,可选值:(ask | yes | no)
session.setConfig("StrictHostKeyChecking", "no");
+
return session;
}
diff --git a/hutool-poi/pom.xml b/hutool-poi/pom.xml
index a213548c2..33d1aeb46 100644
--- a/hutool-poi/pom.xml
+++ b/hutool-poi/pom.xml
@@ -17,7 +17,7 @@
- 4.1.0
+ 4.1.1
2.12.0
diff --git a/hutool-system/pom.xml b/hutool-system/pom.xml
index 700f6c32f..b542f6dfd 100644
--- a/hutool-system/pom.xml
+++ b/hutool-system/pom.xml
@@ -26,7 +26,7 @@
com.github.oshi
oshi-core
- 4.0.0
+ 4.1.0
provided