Skip to content
Permalink
Browse files

[JENKINS-38048] Permits credentialsId dropdowns to be used from a glo…

…bal configuration screen.
  • Loading branch information
jglick committed Sep 8, 2016
1 parent 7550539 commit 1355c64e36933049fcb3c2f50cc3eaf189cef241
@@ -114,7 +114,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1.16</version>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -3013,13 +3013,14 @@ public String getDisplayName() {
}

public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item context, @QueryParameter String remote) {
if (context == null || !context.hasPermission(Item.EXTENDED_READ)) {
if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
context != null && !context.hasPermission(Item.EXTENDED_READ)) {
return new StandardListBoxModel();
}
return fillCredentialsIdItems(context, remote);
}

public ListBoxModel fillCredentialsIdItems(@Nonnull Item context, String remote) {
public ListBoxModel fillCredentialsIdItems(@CheckForNull Item context, String remote) {
List<DomainRequirement> domainRequirements;
if (remote == null) {
domainRequirements = Collections.<DomainRequirement>emptyList();
@@ -3075,7 +3076,8 @@ public FormValidation doCheckCredentialsId(StaplerRequest req, @AncestorInPath I
@QueryParameter String remote, @QueryParameter String value) {

// Test the connection only if we may use the credentials (cf. hudson.plugins.git.UserRemoteConfig.DescriptorImpl.doCheckUrl)
if (context == null || !context.hasPermission(CredentialsProvider.USE_ITEM)) {
if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
context != null && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
return FormValidation.ok();
}
return checkCredentialsId(req, context, remote, value);
@@ -3297,7 +3299,8 @@ public String getDisplayName() {

public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item context,
@QueryParameter String realm) {
if (context == null || !context.hasPermission(Item.EXTENDED_READ)) {
if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
context != null && !context.hasPermission(Item.EXTENDED_READ)) {
return new StandardListBoxModel();
}
List<DomainRequirement> domainRequirements;
@@ -340,7 +340,7 @@ public String getDisplayName() {
}

public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item context, @AncestorInPath Run run) {
if (context == null || !context.hasPermission(SCM.TAG)) {
if (/* TODO consider making available in global context as well */context == null || !context.hasPermission(SCM.TAG)) {
return new ListBoxModel();
}
Set<StandardCredentials> c = new LinkedHashSet<StandardCredentials>();
@@ -41,6 +41,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import jenkins.model.Jenkins;

/**
* {@link RepositoryBrowser} for Sventon 1.x.
@@ -99,7 +100,10 @@ public String getDisplayName() {
public FormValidation doCheckUrl(@AncestorInPath Item project,
@QueryParameter(fixEmpty=true) final String value)
throws IOException, ServletException {
if(!project.hasPermission(Item.EXTENDED_READ)) return FormValidation.ok(); // can't check
if (project == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
project != null && !project.hasPermission(Item.EXTENDED_READ)) {
return FormValidation.ok();
}
if(value==null) // nothing entered yet
return FormValidation.ok();

@@ -42,6 +42,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import jenkins.model.Jenkins;

/**
* {@link RepositoryBrowser} for Sventon 2.x.
@@ -120,7 +121,10 @@ public String getDisplayName() {
public FormValidation doCheckUrl(@AncestorInPath Item project,
@QueryParameter(fixEmpty=true) final String value)
throws IOException, ServletException {
if(!project.hasPermission(Item.EXTENDED_READ)) return FormValidation.ok(); // can't check
if (project == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
project != null && !project.hasPermission(Item.EXTENDED_READ)) {
return FormValidation.ok();
}
if(value==null) // nothing entered yet
return FormValidation.ok();

@@ -103,6 +103,7 @@
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.DataBoundSetter;

/**
@@ -784,13 +785,16 @@ public String getDisplayName() {
*/
@SuppressWarnings("unused") // by stapler
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
@QueryParameter String remoteBase) {
if (context == null || !context.hasPermission(Item.EXTENDED_READ)) {
return new StandardListBoxModel();
@QueryParameter String remoteBase,
@QueryParameter String credentialsId) {
if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
context != null && !context.hasPermission(Item.EXTENDED_READ)) {
return new StandardListBoxModel().includeCurrentValue(credentialsId);
}
List<DomainRequirement> domainRequirements;
domainRequirements = URIRequirementBuilder.fromUri(remoteBase.trim()).build();
return new StandardListBoxModel()
// TODO JENKINS-35553 update to newer APIs
.withEmptySelection()
.withMatching(
CredentialsMatchers.anyOf(
@@ -811,7 +815,8 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner cont
public FormValidation doCheckCredentialsId(StaplerRequest req, @AncestorInPath SCMSourceOwner context, @QueryParameter String remoteBase, @QueryParameter String value) {
// TODO suspiciously similar to SubversionSCM.ModuleLocation.DescriptorImpl.checkCredentialsId; refactor into shared method?
// Test the connection only if we may use the credentials
if (context == null || !context.hasPermission(CredentialsProvider.USE_ITEM)) {
if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
context != null && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
return FormValidation.ok();
}

0 comments on commit 1355c64

Please sign in to comment.
You can’t perform that action at this time.