Skip to content
Permalink
Browse files
Fix Config Page Auth validation
This fixes a problem whereby Test Connection (SSH and REST) fails
AFTER you have saved and re-loaded the config page.

[FIXED JENKINS-30370]
  • Loading branch information
Scott Hebert committed Nov 27, 2015
1 parent 7338bba commit 9bd6637c4456d01c4519540b6cf3ca89f139f100
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritServer.java
@@ -41,6 +41,7 @@
import hudson.model.Hudson;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import hudson.util.Secret;
import hudson.util.ListBoxModel.Option;

import java.io.File;
@@ -689,7 +690,7 @@ public FormValidation doTestConnection(
File file = new File(gerritAuthKeyFile);
String password = null;
if (gerritAuthKeyFilePassword != null && gerritAuthKeyFilePassword.length() > 0) {
password = gerritAuthKeyFilePassword;
password = Secret.fromString(gerritAuthKeyFilePassword).getPlainText();
}
if (SshUtil.checkPassPhrase(file, password)) {
if (file.exists() && file.isFile()) {
@@ -747,14 +748,17 @@ public FormValidation doTestRestConnection(
@QueryParameter("gerritFrontEndUrl") final String gerritFrontEndUrl,
@QueryParameter("gerritHttpUserName") final String gerritHttpUserName,
@QueryParameter("gerritHttpPassword") final String gerritHttpPassword) {

String password = Secret.fromString(gerritHttpPassword).getPlainText();

String restUrl = gerritFrontEndUrl;
if (gerritFrontEndUrl != null && !gerritFrontEndUrl.endsWith("/")) {
restUrl = gerritFrontEndUrl + "/";
}
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(null, -1),
new UsernamePasswordCredentials(gerritHttpUserName,
gerritHttpPassword));
password));
HttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();

0 comments on commit 9bd6637

Please sign in to comment.