Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.37</version>
<version>4.40</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -33,6 +33,7 @@
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.289.1</jenkins.version>
<java.level>8</java.level>
<slf4j.version>1.7.32</slf4j.version>
</properties>

<dependencyManagement>
Expand All @@ -44,14 +45,24 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>2.7.0</version>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>net.i2p.crypto</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down