Skip to content

Commit 676f564

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, and add it along with credentials this way HttpClientBuilder builder = HttpClientBuilder.create(); builder.setSslcontext(sslContext); JenkinsHttpClient client = new JenkinsHttpClient(uri, builder, username, password); JenkinsServer jenkins = new JenkinsServer(client);
1 parent 42a15c9 commit 676f564

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ public JenkinsHttpClient(URI uri, String username, String password) {
122122
}
123123
}
124124

125+
/**
126+
* Create an authenticated Jenkins HTTP client
127+
*
128+
* @param uri Location of the jenkins server (ex. http://localhost:8080)
129+
* @param builder Configured HttpClientBuilder to be used
130+
* @param username Username to use when connecting
131+
* @param password Password or auth token to use when connecting
132+
*/
133+
public JenkinsHttpClient(URI uri, HttpClientBuilder builder, String username, String password) {
134+
this(uri, addAuthentication(builder, uri, username, password));
135+
if (isNotBlank(username)) {
136+
localContext = new BasicHttpContext();
137+
localContext.setAttribute("preemptive-auth", new BasicScheme());
138+
}
139+
}
140+
125141
/**
126142
* Perform a GET request and parse the response to the given class
127143
*

0 commit comments

Comments
 (0)