Skip to content

Commit a567c54

Browse files
authored
Merge pull request #134 from mtughan/modernize-2.479
Modernize to Jenkins 2.479 and Jakarta EE 9
2 parents 6f78adb + 238480b commit a567c54

13 files changed

+326
-288
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ mvn.out*
77
.settings/
88
.repository/
99
.settings.xml
10+
.idea/

pom.xml

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34

45
<parent>
56
<groupId>org.jenkins-ci.plugins</groupId>
67
<artifactId>plugin</artifactId>
7-
<version>4.86</version>
8-
<relativePath/>
8+
<version>5.6</version>
9+
<relativePath />
910
</parent>
1011

1112
<artifactId>git-server</artifactId>
@@ -15,21 +16,6 @@
1516
<name>Jenkins Git server Plugin</name>
1617
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
1718

18-
<properties>
19-
<changelist>999999-SNAPSHOT</changelist>
20-
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
21-
<jenkins.baseline>2.440</jenkins.baseline>
22-
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
23-
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
24-
</properties>
25-
26-
<scm>
27-
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
28-
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
29-
<url>https://github.com/${gitHubRepo}</url>
30-
<tag>${scmTag}</tag>
31-
</scm>
32-
3319
<licenses>
3420
<license>
3521
<name>The MIT license</name>
@@ -38,14 +24,29 @@
3824
</license>
3925
</licenses>
4026

27+
<scm>
28+
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
29+
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
30+
<tag>${scmTag}</tag>
31+
<url>https://github.com/${gitHubRepo}</url>
32+
</scm>
33+
34+
<properties>
35+
<changelist>999999-SNAPSHOT</changelist>
36+
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
37+
<jenkins.baseline>2.479</jenkins.baseline>
38+
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
39+
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
40+
</properties>
41+
4142
<dependencyManagement>
4243
<dependencies>
4344
<dependency>
4445
<groupId>io.jenkins.tools.bom</groupId>
4546
<artifactId>bom-${jenkins.baseline}.x</artifactId>
46-
<version>3234.v5ca_5154341ef</version>
47-
<scope>import</scope>
47+
<version>4023.va_eeb_b_4e45f07</version>
4848
<type>pom</type>
49+
<scope>import</scope>
4950
</dependency>
5051
</dependencies>
5152
</dependencyManagement>
@@ -67,7 +68,7 @@
6768
<dependency>
6869
<groupId>org.eclipse.jgit</groupId>
6970
<artifactId>org.eclipse.jgit.ssh.apache</artifactId>
70-
<version>6.9.0.202403050737-r</version>
71+
<version>7.0.0.202409031743-r</version>
7172
<scope>test</scope>
7273
</dependency>
7374
<dependency>

src/main/java/org/jenkinsci/plugins/gitserver/CSRFExclusionImpl.java

+30-32
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22

33
import hudson.Extension;
44
import hudson.security.csrf.CrumbExclusion;
5-
6-
import javax.servlet.FilterChain;
7-
import javax.servlet.ReadListener;
8-
import javax.servlet.ServletException;
9-
import javax.servlet.ServletInputStream;
10-
import javax.servlet.http.HttpServletRequest;
11-
import javax.servlet.http.HttpServletRequestWrapper;
12-
import javax.servlet.http.HttpServletResponse;
5+
import jakarta.servlet.FilterChain;
6+
import jakarta.servlet.ReadListener;
7+
import jakarta.servlet.ServletException;
8+
import jakarta.servlet.ServletInputStream;
9+
import jakarta.servlet.http.HttpServletRequest;
10+
import jakarta.servlet.http.HttpServletRequestWrapper;
11+
import jakarta.servlet.http.HttpServletResponse;
1312
import java.io.IOException;
1413
import java.util.Collections;
1514
import java.util.Enumeration;
15+
import java.util.Locale;
1616
import java.util.Map;
17-
import java.util.Vector;
1817

1918
/**
2019
* CSRF exclusion for git-upload-pack.
21-
*
20+
*
2221
* <p>
2322
* We do some basic checks to significantly limit the scope of exclusion, but
2423
* because of the dynamic nature of the URL structure, this doesn't guarantee
2524
* that we have no leak.
2625
*
26+
* <p>
2727
* So to further protect Jenkins, we pass through a fake {@link HttpServletRequest}
2828
* that masks the values of the submission.
29-
*
29+
*
3030
* <p>
3131
* If the fake request is routed to {@link HttpGitRepository}, which is
3232
* the only legitimate destination of the request, we'll unwrap this fake request
@@ -35,53 +35,51 @@
3535
* <p>
3636
* In this way, even if an attacker manages to route the request to elsewhere in Jenkins,
3737
* that request will not be interpreted as a POST request.
38-
*
38+
*
3939
* @author Kohsuke Kawaguchi
4040
*/
4141
@Extension
4242
public class CSRFExclusionImpl extends CrumbExclusion {
43+
private static final String BOGUS = "bogus";
4344

44-
public boolean process(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
45-
if (!"application/x-git-receive-pack-request".equals(request.getHeader("Content-Type")))
46-
return false;
47-
48-
// String path = request.getPathInfo();
49-
// if(!path.contains("/repo.git/") || !path.endsWith("/git-receive-pack"))
50-
// return false;
45+
@Override
46+
public boolean process(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
47+
throws IOException, ServletException {
48+
if (!"application/x-git-receive-pack-request".equals(request.getHeader("Content-Type"))) return false;
5149

5250
HttpServletRequestWrapper w = new HttpServletRequestWrapper(request) {
5351
@Override
5452
public String getQueryString() {
55-
return "bogus";
53+
return BOGUS;
5654
}
5755

5856
@Override
5957
public String getParameter(String name) {
60-
return "bogus";
58+
return BOGUS;
6159
}
6260

6361
@Override
64-
public Map getParameterMap() {
62+
public Map<String, String[]> getParameterMap() {
6563
return Collections.emptyMap();
6664
}
6765

6866
@Override
69-
public Enumeration getParameterNames() {
70-
return new Vector().elements();
67+
public Enumeration<String> getParameterNames() {
68+
return Collections.emptyEnumeration();
7169
}
7270

7371
@Override
7472
public String[] getParameterValues(String name) {
75-
return new String[]{"bogus"};
73+
return new String[] {BOGUS};
7674
}
7775

7876
@Override
7977
public String getMethod() {
80-
return "BOGUS";
78+
return BOGUS.toUpperCase(Locale.ROOT);
8179
}
8280

8381
@Override
84-
public ServletInputStream getInputStream() throws IOException {
82+
public ServletInputStream getInputStream() {
8583
return new ServletInputStream() {
8684
@Override
8785
public boolean isFinished() {
@@ -94,7 +92,7 @@ public boolean isReady() {
9492
}
9593

9694
@Override
97-
public int read() throws IOException {
95+
public int read() {
9896
return -1;
9997
}
10098

@@ -105,13 +103,13 @@ public void setReadListener(ReadListener readListener) {
105103
};
106104
}
107105
};
108-
w.setAttribute(ORIGINAL_REQUEST,request);
109-
110-
chain.doFilter(w,response);
106+
w.setAttribute(ORIGINAL_REQUEST, request);
107+
108+
chain.doFilter(w, response);
111109
return true;
112110
}
113111

114-
static final String ORIGINAL_REQUEST = CSRFExclusionImpl.class.getName()+".originalRequest";
112+
static final String ORIGINAL_REQUEST = CSRFExclusionImpl.class.getName() + ".originalRequest";
115113

116114
public static HttpServletRequest unwrapRequest(HttpServletRequest req) {
117115
return (HttpServletRequest) req.getAttribute(CSRFExclusionImpl.ORIGINAL_REQUEST);

src/main/java/org/jenkinsci/plugins/gitserver/ChannelTransport.java

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.jenkinsci.plugins.gitserver;
22

33
import hudson.FilePath;
4-
import hudson.FilePath.FileCallable;
54
import hudson.remoting.Pipe;
65
import hudson.remoting.VirtualChannel;
6+
import java.io.BufferedInputStream;
7+
import java.io.BufferedOutputStream;
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.net.URISyntaxException;
711
import jenkins.MasterToSlaveFileCallable;
812
import org.apache.commons.io.IOUtils;
913
import org.eclipse.jgit.errors.NotSupportedException;
@@ -20,12 +24,6 @@
2024
import org.eclipse.jgit.transport.URIish;
2125
import org.eclipse.jgit.transport.UploadPack;
2226

23-
import java.io.BufferedInputStream;
24-
import java.io.BufferedOutputStream;
25-
import java.io.File;
26-
import java.io.IOException;
27-
import java.net.URISyntaxException;
28-
2927
/**
3028
* {@link Transport} implementation across pipes.
3129
*
@@ -34,15 +32,14 @@
3432
public class ChannelTransport extends Transport implements PackTransport {
3533
private final FilePath remoteRepository;
3634

37-
public static Transport open(Repository local, FilePath remoteRepository) throws NotSupportedException, URISyntaxException, TransportException {
38-
if (remoteRepository.isRemote())
39-
return new ChannelTransport(local,remoteRepository);
40-
else
41-
return Transport.open(local,remoteRepository.getRemote());
35+
public static Transport open(Repository local, FilePath remoteRepository)
36+
throws NotSupportedException, URISyntaxException, TransportException {
37+
if (remoteRepository.isRemote()) return new ChannelTransport(local, remoteRepository);
38+
else return Transport.open(local, remoteRepository.getRemote());
4239
}
4340

4441
public ChannelTransport(Repository local, FilePath remoteRepository) throws URISyntaxException {
45-
super(local, new URIish("channel:"+remoteRepository.getRemote()));
42+
super(local, new URIish("channel:" + remoteRepository.getRemote()));
4643
this.remoteRepository = remoteRepository;
4744
}
4845

@@ -54,15 +51,18 @@ public FetchConnection openFetch() throws NotSupportedException, TransportExcept
5451
try {
5552
remoteRepository.actAsync(new GitFetchTask(l2r, r2l));
5653
} catch (IOException e) {
57-
throw new TransportException("Failed to open a fetch connection",e);
54+
throw new TransportException("Failed to open a fetch connection", e);
5855
} catch (InterruptedException e) {
59-
throw new TransportException("Failed to open a fetch connection",e);
56+
Thread.currentThread().interrupt();
57+
throw new TransportException("Failed to open a fetch connection", e);
6058
}
6159

62-
return new BasePackFetchConnection(this) {{
63-
init(new BufferedInputStream(r2l.getIn()), new BufferedOutputStream(l2r.getOut()));
64-
readAdvertisedRefs();
65-
}};
60+
return new BasePackFetchConnection(this) {
61+
{
62+
init(new BufferedInputStream(r2l.getIn()), new BufferedOutputStream(l2r.getOut()));
63+
readAdvertisedRefs();
64+
}
65+
};
6666
}
6767

6868
@Override
@@ -73,15 +73,18 @@ public PushConnection openPush() throws NotSupportedException, TransportExceptio
7373
try {
7474
remoteRepository.actAsync(new GitPushTask(l2r, r2l));
7575
} catch (IOException e) {
76-
throw new TransportException("Failed to open a fetch connection",e);
76+
throw new TransportException("Failed to open a fetch connection", e);
7777
} catch (InterruptedException e) {
78-
throw new TransportException("Failed to open a fetch connection",e);
78+
Thread.currentThread().interrupt();
79+
throw new TransportException("Failed to open a fetch connection", e);
7980
}
8081

81-
return new BasePackPushConnection(this) {{
82-
init(new BufferedInputStream(r2l.getIn()), new BufferedOutputStream(l2r.getOut()));
83-
readAdvertisedRefs();
84-
}};
82+
return new BasePackPushConnection(this) {
83+
{
84+
init(new BufferedInputStream(r2l.getIn()), new BufferedOutputStream(l2r.getOut()));
85+
readAdvertisedRefs();
86+
}
87+
};
8588
}
8689

8790
@Override
@@ -99,15 +102,13 @@ public GitFetchTask(Pipe l2r, Pipe r2l) {
99102
}
100103

101104
public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
102-
Repository repo = new FileRepositoryBuilder().setWorkTree(f).build();
103-
try {
105+
try (Repository repo = new FileRepositoryBuilder().setWorkTree(f).build()) {
104106
final UploadPack rp = new UploadPack(repo);
105107
rp.upload(new BufferedInputStream(l2r.getIn()), new BufferedOutputStream(r2l.getOut()), null);
106108
return null;
107109
} finally {
108110
IOUtils.closeQuietly(l2r.getIn());
109111
IOUtils.closeQuietly(r2l.getOut());
110-
repo.close();
111112
}
112113
}
113114
}
@@ -122,15 +123,13 @@ public GitPushTask(Pipe l2r, Pipe r2l) {
122123
}
123124

124125
public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
125-
Repository repo = new FileRepositoryBuilder().setWorkTree(f).build();
126-
try {
126+
try (Repository repo = new FileRepositoryBuilder().setWorkTree(f).build()) {
127127
final ReceivePack rp = new ReceivePack(repo);
128128
rp.receive(new BufferedInputStream(l2r.getIn()), new BufferedOutputStream(r2l.getOut()), null);
129129
return null;
130130
} finally {
131131
IOUtils.closeQuietly(l2r.getIn());
132132
IOUtils.closeQuietly(r2l.getOut());
133-
repo.close();
134133
}
135134
}
136135
}

0 commit comments

Comments
 (0)