Skip to content

Commit

Permalink
Fix JENKINS-35560
Browse files Browse the repository at this point in the history
  • Loading branch information
felfert committed Oct 3, 2016
1 parent 70fe2c9 commit ac28c2d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 30 deletions.
5 changes: 5 additions & 0 deletions jclouds-plugin/pom.xml
Expand Up @@ -20,6 +20,11 @@
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
Expand Down
Expand Up @@ -44,7 +44,6 @@
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
Expand Down Expand Up @@ -220,12 +219,12 @@ public FormValidation doCheckEndPointUrl(@QueryParameter String value) {
return FormValidation.ok();
}

public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) {
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String currentValue) {
if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getActiveInstance()).hasPermission(Computer.CONFIGURE)) {
return new ListBoxModel();
return new StandardUsernameListBoxModel().includeCurrentValue(currentValue);
}
return new StandardUsernameListBoxModel().withAll(
CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM));
return new StandardUsernameListBoxModel()
.includeAs(ACL.SYSTEM, context, StandardUsernameCredentials.class).includeCurrentValue(currentValue);
}

public ListBoxModel doFillProviderNameItems(@AncestorInPath ItemGroup context) {
Expand Down
Expand Up @@ -19,7 +19,6 @@
import hudson.model.AutoCompletionCandidates;
import hudson.model.Computer;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.ItemGroup;
import hudson.model.Label;
import hudson.model.Node;
Expand Down Expand Up @@ -66,6 +65,7 @@
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey;
Expand Down Expand Up @@ -161,8 +161,8 @@ public String getGlobalPublicKey() {
private String getPrivateKeyFromCredential(final String id) {
if (!Strings.isNullOrEmpty(id)) {
SSHUserPrivateKey supk = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, Hudson.getInstance(), ACL.SYSTEM),
CredentialsMatchers.withId(id));
CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, Jenkins.getActiveInstance(), ACL.SYSTEM,
Collections.<DomainRequirement>emptyList()), CredentialsMatchers.withId(id));
if (null != supk) {
return supk.getPrivateKey();
}
Expand Down Expand Up @@ -506,20 +506,20 @@ public ListBoxModel doFillProviderNameItems() {
return m;
}

public ListBoxModel doFillCloudCredentialsIdItems(@AncestorInPath ItemGroup context) {
public ListBoxModel doFillCloudCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String currentValue) {
if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getActiveInstance()).hasPermission(Computer.CONFIGURE)) {
return new ListBoxModel();
return new StandardUsernameListBoxModel().includeCurrentValue(currentValue);
}
return new StandardUsernameListBoxModel().withAll(
CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM));
return new StandardUsernameListBoxModel()
.includeAs(ACL.SYSTEM, context, StandardUsernameCredentials.class).includeCurrentValue(currentValue);
}

public ListBoxModel doFillCloudGlobalKeyIdItems(@AncestorInPath ItemGroup context) {
public ListBoxModel doFillCloudGlobalKeyIdItems(@AncestorInPath ItemGroup context, @QueryParameter String currentValue) {
if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getActiveInstance()).hasPermission(Computer.CONFIGURE)) {
return new ListBoxModel();
return new StandardUsernameListBoxModel().includeCurrentValue(currentValue);
}
return new StandardUsernameListBoxModel().withAll(
CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, context, ACL.SYSTEM));
return new StandardUsernameListBoxModel()
.includeAs(ACL.SYSTEM, context, SSHUserPrivateKey.class).includeCurrentValue(currentValue);
}

public AutoCompletionCandidates doAutoCompleteProviderName(@QueryParameter final String value) {
Expand Down
Expand Up @@ -30,7 +30,6 @@
import hudson.model.Computer;
import hudson.model.Descriptor;
import hudson.model.Label;
import hudson.model.Hudson;
import hudson.model.Node.Mode;
import hudson.model.ItemGroup;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -78,6 +77,7 @@
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;

import com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator;
Expand Down Expand Up @@ -231,7 +231,8 @@ public String getJenkinsPrivateKey() {
return getCloud().getGlobalPrivateKey();
}
SSHUserPrivateKey supk = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, Hudson.getInstance(), ACL.SYSTEM),
CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, Jenkins.getActiveInstance(), ACL.SYSTEM,
Collections.<DomainRequirement>emptyList()),
CredentialsMatchers.withId(credentialsId));
if (null != supk) {
return supk.getPrivateKey();
Expand Down Expand Up @@ -784,22 +785,24 @@ public int compare(Location o1, Location o2) {
return m;
}

public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) {
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String currentValue) {
if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getActiveInstance()).hasPermission(Computer.CONFIGURE)) {
return new ListBoxModel();
return new StandardUsernameListBoxModel().includeCurrentValue(currentValue);
}
return new StandardUsernameListBoxModel().withMatching(SSHAuthenticator.matcher(Connection.class),
CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, context,
ACL.SYSTEM, SSHLauncher.SSH_SCHEME));
return new StandardUsernameListBoxModel().includeMatchingAs(
ACL.SYSTEM, context, StandardUsernameCredentials.class,
Collections.<DomainRequirement>singletonList(SSHLauncher.SSH_SCHEME),
SSHAuthenticator.matcher(Connection.class)).includeCurrentValue(currentValue);
}

public ListBoxModel doFillAdminCredentialsIdItems(@AncestorInPath ItemGroup context) {
public ListBoxModel doFillAdminCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String currentValue) {
if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getActiveInstance()).hasPermission(Computer.CONFIGURE)) {
return new ListBoxModel();
return new StandardUsernameListBoxModel().includeCurrentValue(currentValue);
}
return new StandardUsernameListBoxModel().withEmptySelection().withMatching(SSHAuthenticator.matcher(Connection.class),
CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, context,
ACL.SYSTEM, SSHLauncher.SSH_SCHEME));
return new StandardUsernameListBoxModel().includeMatchingAs(
ACL.SYSTEM, context, StandardUsernameCredentials.class,
Collections.<DomainRequirement>singletonList(SSHLauncher.SSH_SCHEME),
SSHAuthenticator.matcher(Connection.class)).includeCurrentValue(currentValue);
}

public FormValidation doValidateLocationId(@QueryParameter String providerName, @QueryParameter String cloudCredentialsId,
Expand Down Expand Up @@ -925,7 +928,7 @@ private String convertJenkinsUser(final String user, final String description,

private StandardUsernameCredentials retrieveExistingCredentials(final String username, final String privkey) {
return CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class,
Hudson.getInstance(), ACL.SYSTEM, SSHLauncher.SSH_SCHEME), CredentialsMatchers.allOf(
Jenkins.getActiveInstance(), ACL.SYSTEM, SSHLauncher.SSH_SCHEME), CredentialsMatchers.allOf(
CredentialsMatchers.withUsername(username),
new CredentialsMatcher() {
public boolean matches(Credentials item) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -32,7 +32,7 @@
<test.jenkins.blobstore.identity>FIXME_IDENTITY</test.jenkins.blobstore.identity>
<test.jenkins.blobstore.credential>FIXME_CREDENTIALS</test.jenkins.blobstore.credential>
<jclouds.version>1.9.1</jclouds.version>
<jenkins.version>1.609.3</jenkins.version>
<jenkins.version>1.625.1</jenkins.version>
<jenkins.parent.version>${project.parent.version}</jenkins.parent.version>
</properties>
<modules>
Expand Down

0 comments on commit ac28c2d

Please sign in to comment.