diff --git a/pom.xml b/pom.xml
index 0d94cdc..b3da8d2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
org.jenkins-ci.plugins
plugin
- 4.37
+ 4.40
@@ -33,6 +33,7 @@
-SNAPSHOT
2.289.1
8
+ 1.7.32
@@ -44,6 +45,16 @@
pom
import
+
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
+
+
+ org.slf4j
+ jcl-over-slf4j
+ ${slf4j.version}
+
@@ -51,7 +62,7 @@
org.apache.sshd
sshd-core
- 2.7.0
+ 2.8.0
net.i2p.crypto
diff --git a/src/main/java/org/jenkinsci/main/modules/sshd/AsynchronousCommand.java b/src/main/java/org/jenkinsci/main/modules/sshd/AsynchronousCommand.java
index a6debb3..efe3b01 100644
--- a/src/main/java/org/jenkinsci/main/modules/sshd/AsynchronousCommand.java
+++ b/src/main/java/org/jenkinsci/main/modules/sshd/AsynchronousCommand.java
@@ -81,9 +81,9 @@ public void setSession(ServerSession session) {
@CheckForNull
protected User getCurrentUser() {
- final Jenkins jenkins = Jenkins.getInstance();
- if (jenkins != null && jenkins.isUseSecurity()) {
- return User.get(getSession().getUsername()); // then UserAuthNamedFactory must have done public key auth
+ final Jenkins jenkins = Jenkins.get();
+ if (jenkins.isUseSecurity()) {
+ return User.getById(getSession().getUsername(), true); // then UserAuthNamedFactory must have done public key auth
} else {
return null; // not authenticated. anonymous.
}
diff --git a/src/main/java/org/jenkinsci/main/modules/sshd/CLICommandAdapter.java b/src/main/java/org/jenkinsci/main/modules/sshd/CLICommandAdapter.java
index cd88324..b02594e 100644
--- a/src/main/java/org/jenkinsci/main/modules/sshd/CLICommandAdapter.java
+++ b/src/main/java/org/jenkinsci/main/modules/sshd/CLICommandAdapter.java
@@ -26,7 +26,9 @@ public Command create(CommandLine commandLine) {
@Override
public int runCommand() throws IOException {
User u = getCurrentUser();
- if (u!=null) c.setTransportAuth(u.impersonate());
+ if (u != null) {
+ c.setTransportAuth2(u.impersonate2());
+ }
CommandLine cmds = getCmdLine();
diff --git a/src/main/java/org/jenkinsci/main/modules/sshd/PortAdvertiser.java b/src/main/java/org/jenkinsci/main/modules/sshd/PortAdvertiser.java
index 7df8afd..851d905 100644
--- a/src/main/java/org/jenkinsci/main/modules/sshd/PortAdvertiser.java
+++ b/src/main/java/org/jenkinsci/main/modules/sshd/PortAdvertiser.java
@@ -25,10 +25,7 @@ public String getEndpoint() {
try {
int p = sshd.getActualPort();
if (p>0) {
- final Jenkins jenkins = Jenkins.getInstance();
- if (jenkins == null) {
- throw new IllegalStateException("Jenkins has not been started, or was already shut down");
- }
+ final Jenkins jenkins = Jenkins.get();
return (host != null ? host : new URL(jenkins.getRootUrl()).getHost()) + ":" + p;
}
} catch (Exception e) {
diff --git a/src/main/java/org/jenkinsci/main/modules/sshd/UserAuthNamedFactory.java b/src/main/java/org/jenkinsci/main/modules/sshd/UserAuthNamedFactory.java
index 29ee8da..990f5bd 100644
--- a/src/main/java/org/jenkinsci/main/modules/sshd/UserAuthNamedFactory.java
+++ b/src/main/java/org/jenkinsci/main/modules/sshd/UserAuthNamedFactory.java
@@ -18,8 +18,8 @@ class UserAuthNamedFactory implements UserAuthFactory {
UserAuthFactory none = UserAuthNoneFactory.INSTANCE;
private UserAuthFactory select() {
- final Jenkins jenkins = Jenkins.getInstance();
- return (jenkins != null && jenkins.isUseSecurity()) ? publicKey : none;
+ final Jenkins jenkins = Jenkins.get();
+ return jenkins.isUseSecurity() ? publicKey : none;
}
public String getName() {
diff --git a/src/test/java/org/jenkinsci/main/modules/cli/auth/ssh/CLITest.java b/src/test/java/org/jenkinsci/main/modules/cli/auth/ssh/CLITest.java
index f16b43d..2660936 100644
--- a/src/test/java/org/jenkinsci/main/modules/cli/auth/ssh/CLITest.java
+++ b/src/test/java/org/jenkinsci/main/modules/cli/auth/ssh/CLITest.java
@@ -64,17 +64,18 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
-import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
import static org.junit.Assume.assumeNoException;
import static org.junit.Assume.assumeThat;
import static org.junit.Assume.assumeTrue;
@@ -130,7 +131,7 @@ public void strictHostKey() throws Exception {
SSHD.get().setPort(0);
File privkey = tmp.newFile("id_rsa");
FileUtils.copyURLToFile(CLITest.class.getResource("id_rsa"), privkey);
- User.get("admin").addProperty(new UserPropertyImpl(IOUtils.toString(CLITest.class.getResource("id_rsa.pub"))));
+ User.getById("admin", true).addProperty(new UserPropertyImpl(IOUtils.toString(CLITest.class.getResource("id_rsa.pub"), StandardCharsets.UTF_8)));
assertNotEquals(0, new Launcher.LocalLauncher(StreamTaskListener.fromStderr()).launch().cmds(
"java", "-Duser.home=" + home, "-jar", jar.getAbsolutePath(), "-s", r.getURL().toString(), "-ssh", "-user", "admin", "-i", privkey.getAbsolutePath(), "-strictHostKey", "who-am-i"
).stdout(System.out).stderr(System.err).join());
@@ -162,7 +163,7 @@ public void interrupt() throws Exception {
SSHD.get().setPort(0);
File privkey = tmp.newFile("id_rsa");
FileUtils.copyURLToFile(CLITest.class.getResource("id_rsa"), privkey);
- User.get("admin").addProperty(new UserPropertyImpl(IOUtils.toString(CLITest.class.getResource("id_rsa.pub"))));
+ User.getById("admin", true).addProperty(new UserPropertyImpl(IOUtils.toString(CLITest.class.getResource("id_rsa.pub"), StandardCharsets.UTF_8)));
FreeStyleProject p = r.createFreeStyleProject("p");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
p.getBuildersList().add(new SleepBuilder(TimeUnit.MINUTES.toMillis(2)));
@@ -241,9 +242,9 @@ public void redirectToEndpointShouldBeFollowed() throws Exception {
WebResponse rsp = wc.goTo("cli-proxy/").getWebResponse();
assertEquals(rsp.getContentAsString(), HttpURLConnection.HTTP_MOVED_TEMP, rsp.getStatusCode());
- assertEquals(rsp.getContentAsString(), null, rsp.getResponseHeaderValue("X-Jenkins"));
- assertEquals(rsp.getContentAsString(), null, rsp.getResponseHeaderValue("X-Jenkins-CLI-Port"));
- assertEquals(rsp.getContentAsString(), null, rsp.getResponseHeaderValue("X-SSH-Endpoint"));
+ assertNull(rsp.getContentAsString(), rsp.getResponseHeaderValue("X-Jenkins"));
+ assertNull(rsp.getContentAsString(), rsp.getResponseHeaderValue("X-Jenkins-CLI-Port"));
+ assertNull(rsp.getContentAsString(), rsp.getResponseHeaderValue("X-SSH-Endpoint"));
String url = r.getURL().toString() + "cli-proxy/";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/src/test/java/org/jenkinsci/main/modules/cli/auth/ssh/UserPropertyImplTest.java b/src/test/java/org/jenkinsci/main/modules/cli/auth/ssh/UserPropertyImplTest.java
index 8ece9f5..cf41908 100644
--- a/src/test/java/org/jenkinsci/main/modules/cli/auth/ssh/UserPropertyImplTest.java
+++ b/src/test/java/org/jenkinsci/main/modules/cli/auth/ssh/UserPropertyImplTest.java
@@ -25,7 +25,7 @@ public void dsa() throws Exception {
private void testRoundtrip(String publicKey) throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
- User foo = User.get("foo");
+ User foo = User.getById("foo", true);
foo.addProperty(new UserPropertyImpl(publicKey));
r.configRoundtrip(foo);
assertEquals(publicKey, foo.getProperty(UserPropertyImpl.class).authorizedKeys);