Skip to content
Permalink
Browse files
Merge pull request #120 from recena/JENKINS-29211
[JENKINS-29211] E200015: ISVNAuthentication provider did not provide credentials
  • Loading branch information
recena committed Jul 8, 2015
2 parents b0351ea + 3ff6d44 commit f7b8916b56583f36d7de289944ce84c54d16e00b
Showing with 41 additions and 13 deletions.
  1. +26 −3 src/main/java/hudson/scm/PerJobCredentialStore.java
  2. +15 −10 src/main/java/hudson/scm/SubversionSCM.java
@@ -4,18 +4,25 @@
import hudson.model.AbstractProject;
import hudson.model.Saveable;
import hudson.remoting.Channel;
import hudson.scm.SubversionSCM.ModuleLocation;
import hudson.scm.SubversionSCM.DescriptorImpl.Credential;
import hudson.scm.SubversionSCM.DescriptorImpl.RemotableSVNAuthenticationProvider;
import jenkins.model.Jenkins;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsStore;
import com.cloudbees.plugins.credentials.common.StandardCredentials;

import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Map;
import java.util.logging.Logger;

import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;

/**
* Persists the credential per job. This object is remotable.
@@ -105,8 +112,24 @@ private Object writeReplace() {
private static final ThreadLocal<Boolean> IS_SAVING = new ThreadLocal<Boolean>();

/*package*/ void migrateCredentials(SubversionSCM.DescriptorImpl descriptor) throws IOException {
for (Map.Entry<String, Credential> e : credentials.entrySet()) {
descriptor.migrateCredentials(project, e.getKey(), e.getValue());
Iterable<CredentialsStore> it = CredentialsProvider.lookupStores(project);
if (it != null && it.iterator().hasNext()) {
CredentialsStore store = it.iterator().next();
for (Map.Entry<String, Credential> e : credentials.entrySet()) {
StandardCredentials credential = descriptor.migrateCredentials(store, e.getKey(), e.getValue());
ModuleLocation[] locations = ((SubversionSCM) project.getScm()).getLocations();
for (int i = 0; i < locations.length; i++) {
try {
if (e.getKey().contains(locations[i].getSVNURL().getHost())) {
locations[i].setCredentialsId(credential.getId());
break;
}
} catch (SVNException ex) {
// Should not happen, but...
LOGGER.log(WARNING, "Repository location with a malformed URL: " + locations[i].remote, ex);
}
}
}
}
}
}
@@ -1621,8 +1621,9 @@ public void load() {
BulkChange bc = new BulkChange(this);
try {
mayHaveLegacyPerJobCredentials = true;
CredentialsStore store = CredentialsProvider.lookupStores(Jenkins.getInstance()).iterator().next();
for (Map.Entry<String, Credential> e : credentials.entrySet()) {
migrateCredentials(Jenkins.getInstance(), e.getKey(), e.getValue());
migrateCredentials(store, e.getKey(), e.getValue());
}
save();
bc.commit();
@@ -1648,9 +1649,9 @@ public void load() {
if (jobCredentials.isFile()) {
try {
new PerJobCredentialStore(job).migrateCredentials(this);
job.save();
if (!jobCredentials.delete()) {
LOGGER.log(Level.WARNING, "Could not remove legacy per-job credentials store file: {0}",
jobCredentials);
LOGGER.log(Level.WARNING, "Could not remove legacy per-job credentials store file: {0}", jobCredentials);
allOk = false;
}
} catch (IOException e) {
@@ -1663,9 +1664,8 @@ public void load() {
save();
}

/*package*/ StandardCredentials migrateCredentials(ModelObject context, String legacyRealm, Credential legacyCredential)
/*package*/ StandardCredentials migrateCredentials(CredentialsStore store, String legacyRealm, Credential legacyCredential)
throws IOException {
CredentialsStore store = CredentialsProvider.lookupStores(context).iterator().next();
StandardCredentials credential = legacyCredential.toCredentials(null, legacyRealm);
if (credential != null) {
return credential;
@@ -1792,8 +1792,7 @@ public SVNAuthentication createSVNAuthentication(String kind) {

@Override
public StandardCredentials toCredentials(String description) {
return new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, null, description, userName,
getPassword());
return new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, null, description, userName, getPassword());
}

@Override
@@ -1803,8 +1802,7 @@ public StandardCredentials toCredentials(ModelObject context, String description
findItemGroup(context),
ACL.SYSTEM,
Collections.<DomainRequirement>emptyList())) {
if (userName.equals(c.getUsername())
&& getPassword().equals(c.getPassword().getPlainText())) {
if (userName.equals(c.getUsername()) && getPassword().equals(c.getPassword().getPlainText())) {
return c;
}
}
@@ -2622,7 +2620,7 @@ public static void init() {}
/**
* The credentials to checkout with.
*/
public final String credentialsId;
public String credentialsId;

/**
* Remembers the user-given value.
@@ -2661,6 +2659,13 @@ public ModuleLocation(String remote, String local) {
this(remote, null, local, null, false);
}

/**
* Sets the credentials identifier.
*/
void setCredentialsId (final String id) {
credentialsId = id;
}

/**
* Constructor to support backwards compatibility.
*/

0 comments on commit f7b8916

Please sign in to comment.