Skip to content

Commit 2f9c8b4

Browse files
author
Jesper Terkelsen
committed
JENKINS-46445 Add support for both client TLS and basic authentication.
In some setups both client certificate TLS authentication and username password authentication is needed. Here is how you would set it up: - Create a sslContext - add it along with credentials to the new constructor HttpClientBuilder builder = HttpClientBuilder.create(); builder.setSslcontext(sslContext); JenkinsHttpClient client = new JenkinsHttpClient(uri, builder, username, password); JenkinsServer jenkins = new JenkinsServer(client);
1 parent 42a15c9 commit 2f9c8b4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

ReleaseNotes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## Release 0.3.8 (NOT RELEASED YET)
44

5+
* [JENKINS-46445](https://issues.jenkins-ci.org/browse/JENKINS-46445)
6+
7+
Add support for both client TLS and basic authentication.
8+
9+
```java
10+
HttpClientBuilder builder = HttpClientBuilder.create();
11+
builder.setSslcontext(sslContext);
12+
JenkinsHttpClient client = new JenkinsHttpClient(uri, builder, username, password);
13+
JenkinsServer jenkins = new JenkinsServer(client);
14+
```
15+
516
* [Fixed Issue 268][issue-268]
617

718
NullPointerException is thrown unless isRunning() is called first.

jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,19 @@ public JenkinsHttpClient(URI uri) {
115115
* @param password Password or auth token to use when connecting
116116
*/
117117
public JenkinsHttpClient(URI uri, String username, String password) {
118-
this(uri, addAuthentication(HttpClientBuilder.create(), uri, username, password));
118+
this(uri, HttpClientBuilder.create(), username, password);
119+
}
120+
121+
/**
122+
* Create an authenticated Jenkins HTTP client
123+
*
124+
* @param uri Location of the jenkins server (ex. http://localhost:8080)
125+
* @param builder Configured HttpClientBuilder to be used
126+
* @param username Username to use when connecting
127+
* @param password Password or auth token to use when connecting
128+
*/
129+
public JenkinsHttpClient(URI uri, HttpClientBuilder builder, String username, String password) {
130+
this(uri, addAuthentication(builder, uri, username, password));
119131
if (isNotBlank(username)) {
120132
localContext = new BasicHttpContext();
121133
localContext.setAttribute("preemptive-auth", new BasicScheme());

0 commit comments

Comments
 (0)