hudson.util.ListBoxModel Java Examples

The following examples show how to use hudson.util.ListBoxModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GerritSCMSource.java    From gerrit-code-review-plugin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public ListBoxModel doFillCredentialsIdItems(
    @AncestorInPath Item context,
    @QueryParameter String remote,
    @QueryParameter String credentialsId) {
  if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)
      || context != null && !context.hasPermission(Item.EXTENDED_READ)) {
    return new StandardListBoxModel().includeCurrentValue(credentialsId);
  }
  return new StandardListBoxModel()
      .includeEmptyValue()
      .includeMatchingAs(
          context instanceof Queue.Task
              ? Tasks.getAuthenticationOf((Queue.Task) context)
              : ACL.SYSTEM,
          context,
          StandardUsernameCredentials.class,
          URIRequirementBuilder.fromUri(remote).build(),
          GitClient.CREDENTIALS_MATCHER)
      .includeCurrentValue(credentialsId);
}
 
Example #2
Source File: BuildScanner.java    From acunetix-plugin with MIT License 6 votes vote down vote up
public ListBoxModel doFillGApiKeyIDItems(
        @AncestorInPath Item item) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (item == null) {
        if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
            return result.includeCurrentValue(gApiKeyID);
        }
    } else {
        if (!item.hasPermission(Item.EXTENDED_READ)
                && !item.hasPermission(CredentialsProvider.USE_ITEM)) {
            return result.includeCurrentValue(gApiKeyID);
        }
    }
    if (gApiKeyID != null) {
        result.includeMatchingAs(ACL.SYSTEM, Jenkins.getInstance(), StringCredentials.class,
                Collections.<DomainRequirement> emptyList(), CredentialsMatchers.allOf(CredentialsMatchers.withId(gApiKeyID)));
    }
    return result
            .includeMatchingAs(ACL.SYSTEM, Jenkins.getInstance(), StringCredentials.class,
                    Collections.<DomainRequirement> emptyList(), CredentialsMatchers.allOf(CredentialsMatchers.instanceOf(StringCredentials.class)));
}
 
Example #3
Source File: ClusterConfig.java    From jenkins-client-plugin with Apache License 2.0 6 votes vote down vote up
public static ListBoxModel doFillCredentialsIdItems(String credentialsId) {
    if (credentialsId == null) {
        credentialsId = "";
    }

    if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
        // Important! Otherwise you expose credentials metadata to random
        // web requests.
        return new StandardListBoxModel()
                .includeCurrentValue(credentialsId);
    }

    return new StandardListBoxModel()
            .includeEmptyValue()
            .includeAs(ACL.SYSTEM, Jenkins.getInstance(),
                    OpenShiftTokenCredentials.class)
            // .includeAs(ACL.SYSTEM, Jenkins.getInstance(),
            // StandardUsernamePasswordCredentials.class)
            // .includeAs(ACL.SYSTEM, Jenkins.getInstance(),
            // StandardCertificateCredentials.class)
            // TODO: Make own type for token or use the existing token
            // generator auth type used by sync plugin? or kubernetes?
            .includeCurrentValue(credentialsId);
}
 
Example #4
Source File: KafkaKubernetesCloud.java    From remoting-kafka-plugin with MIT License 6 votes vote down vote up
@RequirePOST
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl) {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    return new StandardListBoxModel().withEmptySelection()
            .withMatching(
                    CredentialsMatchers.anyOf(
                            CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class),
                            CredentialsMatchers.instanceOf(FileCredentials.class),
                            CredentialsMatchers.instanceOf(TokenProducer.class),
                            CredentialsMatchers.instanceOf(StandardCertificateCredentials.class),
                            CredentialsMatchers.instanceOf(StringCredentials.class)),
                    CredentialsProvider.lookupCredentials(StandardCredentials.class,
                            Jenkins.get(),
                            ACL.SYSTEM,
                            serverUrl != null ? URIRequirementBuilder.fromUri(serverUrl).build()
                                    : Collections.EMPTY_LIST
                    ));
}
 
Example #5
Source File: GlobalKafkaConfiguration.java    From remoting-kafka-plugin with MIT License 6 votes vote down vote up
private ListBoxModel fillCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (item == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            return result.includeCurrentValue(credentialsId);
        }
    }
    return result
            .includeMatchingAs(
                    ACL.SYSTEM,
                    Jenkins.get(),
                    StandardUsernamePasswordCredentials.class,
                    Collections.singletonList(KAFKA_SCHEME),
                    CredentialsMatchers.always()
            )
            .includeCurrentValue(credentialsId);
}
 
Example #6
Source File: GlobalKafkaConfiguration.java    From remoting-kafka-plugin with MIT License 6 votes vote down vote up
@RequirePOST
public ListBoxModel doFillKubernetesCredentialsIdItems() {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    return new StandardListBoxModel().withEmptySelection()
            .withMatching(
                    CredentialsMatchers.anyOf(
                            CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class),
                            CredentialsMatchers.instanceOf(FileCredentials.class),
                            CredentialsMatchers.instanceOf(TokenProducer.class),
                            CredentialsMatchers.instanceOf(StandardCertificateCredentials.class),
                            CredentialsMatchers.instanceOf(StringCredentials.class)),
                    CredentialsProvider.lookupCredentials(StandardCredentials.class,
                            Jenkins.get(),
                            ACL.SYSTEM,
                            Collections.EMPTY_LIST
                    ));
}
 
Example #7
Source File: DockerComputerSSHConnector.java    From docker-plugin with MIT License 6 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item context, @QueryParameter String credentialsId) {
    if ( !hasPermission(context)) {
        return new StandardUsernameListBoxModel()
                .includeCurrentValue(credentialsId);
    }
    // Functionally the same as SSHLauncher's descriptor method, but without
    // filtering by host/port as we don't/can't know those yet.
    return new StandardUsernameListBoxModel()
            .includeMatchingAs(
                    ACL.SYSTEM,
                    context,
                    StandardUsernameCredentials.class,
                    Collections.emptyList(),
                    SSHAuthenticator.matcher(Connection.class))
            .includeCurrentValue(credentialsId);
}
 
Example #8
Source File: EC2FleetCloudTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void descriptorImpl_doFillFleetItems_returnEmptyIfFleetTypeIsNull() {
    AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class);
    when(ec2Api.connect(anyString(), anyString(), anyString())).thenReturn(amazonEC2Client);

    DescribeSpotFleetRequestsResult describeSpotFleetRequestsResult = mock(DescribeSpotFleetRequestsResult.class);
    when(amazonEC2Client.describeSpotFleetRequests(any(DescribeSpotFleetRequestsRequest.class)))
            .thenReturn(describeSpotFleetRequestsResult);

    spotFleetRequestConfig8.getSpotFleetRequestConfig().setType((String) null);
    when(describeSpotFleetRequestsResult.getSpotFleetRequestConfigs())
            .thenReturn(Arrays.asList(spotFleetRequestConfig8));

    ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems(
            false, "", "", "", "");

    assertEquals(0, r.size());
}
 
Example #9
Source File: AWSDeviceFarmRecorder.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Populate the project drop-down Appium Version.
 *
 * @return The ListBoxModel for the UI.
 */
@SuppressWarnings("unused")
public ListBoxModel doFillAppiumVersionJunitItems(@QueryParameter String currentAppiumVersion) {
    List<ListBoxModel.Option> entries = new ArrayList<ListBoxModel.Option>();
    ArrayList<String> appiumVersions = new ArrayList<String>();
    appiumVersions.add(APPIUM_VERSION_1_4_16);
    appiumVersions.add(APPIUM_VERSION_1_6_3);
    appiumVersions.add(APPIUM_VERSION_1_6_5);
    appiumVersions.add(APPIUM_VERSION_1_7_1);
    appiumVersions.add(APPIUM_VERSION_1_7_2);
    appiumVersions.add(APPIUM_VERSION_1_9_1);
    for (String appiumVersion: appiumVersions) {
        entries.add(new ListBoxModel.Option(appiumVersion, appiumVersion, appiumVersion.equals(currentAppiumVersion)));
    }
    return new ListBoxModel(entries);
}
 
Example #10
Source File: GitLabServer.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
/**
 * Stapler form completion.
 *
 * @param serverUrl the server URL.
 * @param credentialsId the credentials Id
 * @return the available credentials.
 */
@Restricted(NoExternalUse.class) // stapler
@SuppressWarnings("unused")
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl,
    @QueryParameter String credentialsId) {
    Jenkins jenkins = Jenkins.get();
    if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
        return new StandardListBoxModel().includeCurrentValue(credentialsId);
    }
    return new StandardListBoxModel()
        .includeEmptyValue()
        .includeMatchingAs(ACL.SYSTEM,
            jenkins,
            StandardCredentials.class,
            fromUri(serverUrl).build(),
            CREDENTIALS_MATCHER
        );
}
 
Example #11
Source File: CredentialsHelper.java    From violation-comments-to-stash-plugin with MIT License 6 votes vote down vote up
@SuppressFBWarnings("NP_NULL_PARAM_DEREF")
public static ListBoxModel doFillCredentialsIdItems(
    final Item item, final String credentialsId, final String uri) {
  final StandardListBoxModel result = new StandardListBoxModel();
  if (item == null) {
    if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
      return result.includeCurrentValue(credentialsId);
    }
  } else {
    if (!item.hasPermission(Item.EXTENDED_READ)
        && !item.hasPermission(CredentialsProvider.USE_ITEM)) {
      return result.includeCurrentValue(credentialsId);
    }
  }
  return result //
      .includeEmptyValue() //
      .includeMatchingAs(
          item instanceof Queue.Task ? Tasks.getAuthenticationOf((Queue.Task) item) : ACL.SYSTEM,
          item,
          StandardCredentials.class,
          URIRequirementBuilder.fromUri(uri).build(),
          CredentialsMatchers.anyOf(
              CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class),
              CredentialsMatchers.instanceOf(StringCredentials.class)))
      .includeCurrentValue(credentialsId);
}
 
Example #12
Source File: ConduitCredentialsDescriptor.java    From phabricator-jenkins-plugin with MIT License 6 votes vote down vote up
public static ListBoxModel doFillCredentialsIDItems(@AncestorInPath Jenkins context) {
    if (context == null || !context.hasPermission(Item.CONFIGURE)) {
        return new StandardListBoxModel();
    }

    List<DomainRequirement> domainRequirements = new ArrayList<DomainRequirement>();
    return new StandardListBoxModel()
            .withEmptySelection()
            .withMatching(
                    CredentialsMatchers.anyOf(
                            CredentialsMatchers.instanceOf(ConduitCredentials.class)),
                    CredentialsProvider.lookupCredentials(
                            StandardCredentials.class,
                            context,
                            ACL.SYSTEM,
                            domainRequirements));
}
 
Example #13
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 6 votes vote down vote up
/**
 * Verifies doFillHttpCredentialsIdItems adds the passed in current value
 */
@Test
public void testDoFillHttpCredentialsIdItemsAddsCurrent() {
    BuildStatusConfig instance = new BuildStatusConfig();

    final String currentValue = "mock-id";
    ListBoxModel model = instance.doFillHttpCredentialsIdItems(currentValue);

    assertEquals(2, model.size());
    ListBoxModel.Option item1 = model.get(0);
    assertEquals("", item1.value);
    assertEquals("- none -", item1.name);

    ListBoxModel.Option item2 = model.get(1);
    assertEquals(currentValue, item2.value);
}
 
Example #14
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 6 votes vote down vote up
/**
 * Verifies doFillCredentialsIdItems adds values from the credentials store
 * @throws IOException
 */
@Test
public void testDoFillHttpCredentialsIdItemsAddsFromCredentialsStore() throws IOException {
    StandardUsernameCredentials user = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, testCredentials, "Description", testCredentialsUser, testCredentialsPassword);
    CredentialsProvider.lookupStores(j.getInstance()).iterator().next().addCredentials(Domain.global(), user);

    BuildStatusConfig instance = new BuildStatusConfig();
    instance.setCredentialsId(testCredentials);

    ListBoxModel model = instance.doFillHttpCredentialsIdItems(testCredentials);

    assertEquals(2, model.size());
    ListBoxModel.Option item1 = model.get(0);
    assertEquals("", item1.value);
    assertEquals("- none -", item1.name);

    ListBoxModel.Option item2 = model.get(1);
    assertEquals(testCredentials, item2.value);
}
 
Example #15
Source File: DockerConnector.java    From yet-another-docker-plugin with MIT License 6 votes vote down vote up
@RequirePOST
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) {
    AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance());
    if (!ac.hasPermission(Jenkins.ADMINISTER)) {
        return new ListBoxModel();
    }

    List<StandardCredentials> credentials =
            CredentialsProvider.lookupCredentials(StandardCredentials.class,
                    context,
                    ACL.SYSTEM,
                    Collections.emptyList());

    return new CredentialsListBoxModel()
            .includeEmptyValue()
            .withMatching(CredentialsMatchers.always(), credentials);
}
 
Example #16
Source File: WithAWSStepTest.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testListCredentials() throws Exception {
	Folder folder = jenkinsRule.jenkins.createProject(Folder.class, "folder" + jenkinsRule.jenkins.getItems().size());
	CredentialsStore folderStore = this.getFolderStore(folder);
	StandardUsernamePasswordCredentials folderCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL,
			"folder-creds", "test-creds", "aws-access-key-id", "aws-secret-access-key");
	StandardUsernamePasswordCredentials globalCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL,
			"global-creds", "test-creds", "aws-access-key-id", "aws-secret-access-key");

	folderStore.addCredentials(Domain.global(), folderCredentials);
	SystemCredentialsProvider.getInstance().getCredentials().add(globalCredentials);
	SystemCredentialsProvider.getInstance().save();

	WorkflowJob job = folder.createProject(WorkflowJob.class, "testStepWithFolderCredentials");
	final WithAWSStep.DescriptorImpl descriptor = jenkinsRule.jenkins.getDescriptorByType(WithAWSStep.DescriptorImpl.class);

	// 3 options: Root credentials, folder credentials and "none"
	ListBoxModel list = descriptor.doFillCredentialsItems(job);
	Assert.assertEquals(3, list.size());

	StandardUsernamePasswordCredentials systemCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM,
			"system-creds", "test-creds", "aws-access-key-id", "aws-secret-access-key");
	SystemCredentialsProvider.getInstance().getCredentials().add(systemCredentials);

	// Still 3 options: Root credentials, folder credentials and "none"
	list = descriptor.doFillCredentialsItems(job);
	Assert.assertEquals(3, list.size());
}
 
Example #17
Source File: ZAProxy.java    From zaproxy-plugin with MIT License 5 votes vote down vote up
/**
 * List model to choose the alert report format
 * 
 * @return a {@link ListBoxModel}
 */
public ListBoxModel doFillChosenFormatsItems() {
	ListBoxModel items = new ListBoxModel();
	for(String format: mapFormatReport.keySet()) {
		items.add(format);
	}
	return items;
}
 
Example #18
Source File: CodeBuilder.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillS3LogsStatusOverrideItems() {
    final ListBoxModel selections = new ListBoxModel();

    for(LogsConfigStatusType t : LogsConfigStatusType.values()) {
        selections.add(t.toString());
    }
    selections.add("");
    return selections;
}
 
Example #19
Source File: Connector.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Populates a {@link ListBoxModel} with the scan credentials appropriate for the supplied context against the
 * supplied API endpoint.
 *
 * @param context the context.
 * @param apiUri  the api endpoint.
 * @return a {@link ListBoxModel}.
 */
@NonNull
public static ListBoxModel listScanCredentials(@CheckForNull Item context, String apiUri) {
    return new StandardListBoxModel()
            .includeEmptyValue()
            .includeMatchingAs(
                    context instanceof Queue.Task
                            ? ((Queue.Task) context).getDefaultAuthentication()
                            : ACL.SYSTEM,
                    context,
                    StandardUsernameCredentials.class,
                    githubDomainRequirements(apiUri),
                    githubScanCredentialsMatcher()
            );
}
 
Example #20
Source File: TemplateImplementationProperty.java    From ez-templates with Apache License 2.0 5 votes vote down vote up
/**
 * Jenkins-convention to populate the drop-down box with discovered templates
 */
@SuppressWarnings("UnusedDeclaration")
public ListBoxModel doFillTemplateJobNameItems() {
    ListBoxModel items = new ListBoxModel();
    // Add null as first option - dangerous to force an existing project onto a template in case
    // a noob destroys their config
    items.add(Messages.TemplateImplementationProperty_noTemplateSelected(), null);
    // Add all discovered templates
    for (AbstractProject project : ProjectUtils.findProjectsWithProperty(TemplateProperty.class)) {
        // fullName includes any folder structure
        items.add(project.getFullDisplayName(), project.getFullName());
    }
    return items;
}
 
Example #21
Source File: GitLabSCMSource.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Restricted(NoExternalUse.class)
public ListBoxModel doFillProjectPathItems(@QueryParameter @RelativePath("sourceSettings") String connectionName) throws GitLabAPIException {
    ListBoxModel items = new ListBoxModel();
    // TODO: respect settings in nearest GitLabSCMNavigator
    for (GitLabProject project : gitLabAPI(connectionName).findProjects(VISIBLE, ALL, "")) {
        items.add(project.getPathWithNamespace());
    }
    return items;
}
 
Example #22
Source File: ViolationsToBitbucketServerConfig.java    From violation-comments-to-stash-plugin with MIT License 5 votes vote down vote up
@SuppressWarnings("unused") // Used by stapler
public ListBoxModel doFillCredentialsIdItems(
    @AncestorInPath final Item item,
    @QueryParameter final String credentialsId,
    @QueryParameter final String bitbucketServerUrl) {
  return CredentialsHelper.doFillCredentialsIdItems(item, credentialsId, bitbucketServerUrl);
}
 
Example #23
Source File: WithMavenStep.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
@Restricted(NoExternalUse.class) // Only for UI calls
public ListBoxModel doFillPublisherStrategyItems(@AncestorInPath ItemGroup context) {
    ListBoxModel r = new ListBoxModel();
    for(MavenPublisherStrategy publisherStrategy: MavenPublisherStrategy.values()) {
        r.add(publisherStrategy.getDescription(), publisherStrategy.name());
    }
    return r;
}
 
Example #24
Source File: OpenShift.java    From jenkins-client-plugin with Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillLogLevelItems() {
    ListBoxModel items = new ListBoxModel();
    items.add("0 - Least Logging", "0");
    for (int i = 1; i < 10; i++) {
        items.add("" + i, "" + i);
    }
    items.add("10 - Most Logging", "10");
    return items;
}
 
Example #25
Source File: WithAWSStepTest.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testListAWSCredentials() throws Exception {

	Folder folder = jenkinsRule.jenkins.createProject(Folder.class, "folder" + jenkinsRule.jenkins.getItems().size());
	CredentialsStore folderStore = this.getFolderStore(folder);
	AmazonWebServicesCredentials amazonWebServicesCredentials = new AWSCredentialsImpl(CredentialsScope.GLOBAL,
			"test-aws-creds", "global-aws-access-key-id", "global-aws-secret-access-key", "Aws-Description",
			"Arn::Something:or:Other", "12345678");
	AmazonWebServicesCredentials globalAmazonWebServicesCredentials = new AWSCredentialsImpl(CredentialsScope.GLOBAL,
			"global-test-aws-creds", "global-aws-access-key-id", "global-aws-secret-access-key", "Aws-Description",
			"Arn::Something:or:Other", "12345678");

	folderStore.addCredentials(Domain.global(), amazonWebServicesCredentials);
	SystemCredentialsProvider.getInstance().getCredentials().add(globalAmazonWebServicesCredentials);
	SystemCredentialsProvider.getInstance().save();

	WorkflowJob job = folder.createProject(WorkflowJob.class, "testStepWithFolderCredentials");
	final WithAWSStep.DescriptorImpl descriptor = jenkinsRule.jenkins.getDescriptorByType(WithAWSStep.DescriptorImpl.class);

	// 3 options: Root credentials, folder credentials and "none"
	ListBoxModel list = descriptor.doFillCredentialsItems(job);
	Assert.assertEquals(3, list.size());

	StandardUsernamePasswordCredentials systemCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM,
			"system-creds", "test-creds", "aws-access-key-id", "aws-secret-access-key");
	SystemCredentialsProvider.getInstance().getCredentials().add(systemCredentials);

	// Still 3 options: Root credentials, folder credentials and "none"
	list = descriptor.doFillCredentialsItems(job);
	Assert.assertEquals(3, list.size());
}
 
Example #26
Source File: CodeBuildStep.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillSourceTypeOverrideItems() {
    final ListBoxModel selections = new ListBoxModel();

    for (SourceType t : SourceType.values()) {
        if(!t.equals(SourceType.CODEPIPELINE)) {
            selections.add(t.toString());
        }
    }
    selections.add("");
    return selections;
}
 
Example #27
Source File: GitHubSCMNavigator.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
static ListBoxModel getPossibleApiUriItems() {
    ListBoxModel result = new ListBoxModel();
    result.add("GitHub", "");
    for (Endpoint e : GitHubConfiguration.get().getEndpoints()) {
        result.add(e.getName() == null ? e.getApiUri() : e.getName() + " (" + e.getApiUri() + ")",
                e.getApiUri());
    }
    return result;
}
 
Example #28
Source File: DockerPullImage.java    From yet-another-docker-plugin with MIT License 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) {
    List<DockerRegistryAuthCredentials> credentials =
            CredentialsProvider.lookupCredentials(DockerRegistryAuthCredentials.class, context, ACL.SYSTEM,
                    Collections.emptyList());

    return new StandardListBoxModel().withEmptySelection()
            .withMatching(CredentialsMatchers.instanceOf(DockerRegistryAuthCredentials.class), credentials);
}
 
Example #29
Source File: Site.java    From jira-steps-plugin with Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(final @AncestorInPath Item item,
    @QueryParameter String credentialsId,
    final @QueryParameter String url) {

  StandardListBoxModel result = new StandardListBoxModel();

  credentialsId = StringUtils.trimToEmpty(credentialsId);
  if (item == null) {
    if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
      return result.includeCurrentValue(credentialsId);
    }
  } else {
    if (!item.hasPermission(Item.EXTENDED_READ) && !item.hasPermission(CredentialsProvider.USE_ITEM)) {
      return result.includeCurrentValue(credentialsId);
    }
  }

  Authentication authentication = getAuthentication(item);
  List<DomainRequirement> domainRequirements = URIRequirementBuilder.fromUri(url).build();
  CredentialsMatcher always = CredentialsMatchers.always();
  Class<? extends StandardUsernameCredentials> type = UsernamePasswordCredentialsImpl.class;

  result.includeEmptyValue();
  if (item != null) {
    result.includeMatchingAs(authentication, item, type, domainRequirements, always);
  } else {
    result.includeMatchingAs(authentication, Jenkins.get(), type, domainRequirements, always);
  }
  return result;
}
 
Example #30
Source File: WithMavenStep.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
@Restricted(NoExternalUse.class) // Only for UI calls
public ListBoxModel doFillMavenItems() {
    ListBoxModel r = new ListBoxModel();
    r.add("--- Use system default Maven ---",null);
    for (MavenInstallation installation : getMavenDescriptor().getInstallations()) {
        r.add(installation.getName());
    }
    return r;
}