Java Code Examples for hudson.util.ListBoxModel

The following examples show how to use hudson.util.ListBoxModel. These examples are extracted from open source projects. 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
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 2
@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 3
Source Project: gitlab-branch-source-plugin   Source File: GitLabServer.java    License: 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 4
Source Project: docker-plugin   Source File: DockerComputerSSHConnector.java    License: 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 5
Source Project: ec2-spot-jenkins-plugin   Source File: EC2FleetCloudTest.java    License: 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 6
/**
 * 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 7
Source Project: gerrit-code-review-plugin   Source File: GerritSCMSource.java    License: 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 8
Source Project: yet-another-docker-plugin   Source File: DockerConnector.java    License: 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 9
Source Project: remoting-kafka-plugin   Source File: GlobalKafkaConfiguration.java    License: 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 10
Source Project: remoting-kafka-plugin   Source File: GlobalKafkaConfiguration.java    License: 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 11
Source Project: remoting-kafka-plugin   Source File: KafkaKubernetesCloud.java    License: 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 12
Source Project: acunetix-plugin   Source File: BuildScanner.java    License: 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 13
Source Project: jenkins-client-plugin   Source File: ClusterConfig.java    License: 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 14
Source Project: github-autostatus-plugin   Source File: BuildStatusConfigTest.java    License: 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 15
Source Project: github-autostatus-plugin   Source File: BuildStatusConfigTest.java    License: 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 16
Source Project: github-branch-source-plugin   Source File: Connector.java    License: 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 17
@SuppressWarnings("unused")
public ListBoxModel doFillEnvironmentTypeItems() {
    ListBoxModel items = new ListBoxModel();
    items.add("development", "development");
    items.add("testing", "testing");
    items.add("staging", "staging");
    items.add("production", "production");

    return items;
}
 
Example 18
@SuppressWarnings("unused")
public ListBoxModel doFillStateItems() {
    ListBoxModel items = new ListBoxModel();
    for (String state : State.ALLOWED_STATES) {
        items.add(state, state);
    }
    return items;
}
 
Example 19
Source Project: gitlab-branch-source-plugin   Source File: GitLabServers.java    License: MIT License 5 votes vote down vote up
/**
 * Populates a {@link ListBoxModel} with the servers.
 *
 * @return A {@link ListBoxModel} with all the servers
 */
public ListBoxModel getServerItems() {
    ListBoxModel result = new ListBoxModel();
    for (GitLabServer server : getServers()) {
        String serverUrl = server.getServerUrl();
        String serverName = server.getName(); // serverName or name or displayName
        result.add(
            StringUtils.isBlank(serverName) ? serverUrl : serverName + " (" + serverUrl + ")",
            serverName);
    }
    return result;
}
 
Example 20
/**
 * Populates the strategy options.
 *
 * @return the stategy options.
 */
@NonNull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler
public ListBoxModel doFillStrategyIdItems() {
    ListBoxModel result = new ListBoxModel();
    result.add(Messages.ForkMergeRequestDiscoveryTrait_mergeOnly(), "1");
    result.add(Messages.ForkMergeRequestDiscoveryTrait_headOnly(), "2");
    result.add(Messages.ForkMergeRequestDiscoveryTrait_headAndMerge(), "3");
    return result;
}
 
Example 21
/**
 * Populates the strategy options.
 *
 * @return the stategy options.
 */
@NonNull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler
public ListBoxModel doFillStrategyIdItems() {
    ListBoxModel result = new ListBoxModel();
    result.add(Messages.ProjectNamingStrategyTrait_fullProjectPath(), "1");
    result.add(Messages.ProjectNamingStrategyTrait_projectName(), "2");
    return result;
}
 
Example 22
Source Project: credentials-binding-plugin   Source File: BindingDescriptor.java    License: MIT License 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item owner) {
    if (owner == null || !owner.hasPermission(Item.CONFIGURE)) {
        return new ListBoxModel();
    }
    // when configuring the job, you only want those credentials that are available to ACL.SYSTEM selectable
    // as we cannot select from a user's credentials unless they are the only user submitting the build
    // (which we cannot assume) thus ACL.SYSTEM is correct here.
    return new Model().withAll(CredentialsProvider.lookupCredentials(type(), owner, ACL.SYSTEM, Collections.<DomainRequirement>emptyList()));
}
 
Example 23
Source Project: gitlab-branch-source-plugin   Source File: SSHCheckoutTrait.java    License: MIT License 5 votes vote down vote up
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler form binding
public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item context,
    @QueryParameter String serverUrl,
    @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
            && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.includeEmptyValue();
    result.includeMatchingAs(
        context instanceof Queue.Task
            ? ((Queue.Task) context).getDefaultAuthentication()
            : ACL.SYSTEM,
        context,
        StandardUsernameCredentials.class,
        URIRequirementBuilder.fromUri(serverUrl).build(),
        CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)
    );
    return result;
}
 
Example 24
Source Project: jobcacher-plugin   Source File: S3ItemStorage.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
public ListBoxModel doFillRegionItems() {
    final ListBoxModel model = new ListBoxModel();
    for (Regions r : Regions.values()) {
        model.add(r.getName(), r.getName());
    }
    return model;
}
 
Example 25
Source Project: github-branch-source-plugin   Source File: GitHubSCMNavigator.java    License: MIT License 5 votes vote down vote up
/**
 * Populates the drop-down list of credentials.
 *
 * @param context the context.
 * @param apiUri  the end-point.
 * @param credentialsId the existing selection;
 * @return the drop-down list.
 * @since 2.2.0
 */
@Restricted(NoExternalUse.class) // stapler
public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item context,
                                             @QueryParameter String apiUri,
                                             @QueryParameter String credentialsId) {
    if (context == null
            ? !Jenkins.get().hasPermission(Jenkins.ADMINISTER)
            : !context.hasPermission(Item.EXTENDED_READ)) {
        return new StandardListBoxModel().includeCurrentValue(credentialsId);
    }
    return Connector.listScanCredentials(context, apiUri);
}
 
Example 26
Source Project: aws-codebuild-jenkins-plugin   Source File: CodeBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillComputeTypeOverrideItems() {
    final ListBoxModel selections = new ListBoxModel();

    for (ComputeType t : ComputeType.values()) {
        selections.add(t.toString());
    }
    selections.add("");
    return selections;
}
 
Example 27
private ListBoxModel getOptions(boolean isWebHook) {
    ListBoxModel result = new ListBoxModel();
    String pronoun = isWebHook ? "Web Hook" : "System Hook";
    result.add(Messages.HookRegistrationTrait_disable(pronoun),
        GitLabHookRegistration.DISABLE.toString());
    result.add(Messages.HookRegistrationTrait_useSystem(pronoun),
        GitLabHookRegistration.SYSTEM.toString());
    result.add(Messages.HookRegistrationTrait_useItem(pronoun),
        GitLabHookRegistration.ITEM.toString());
    return result;
}
 
Example 28
Source Project: marathon-plugin   Source File: MarathonRecorder.java    License: Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item) {
    return new StandardListBoxModel().withEmptySelection().withMatching(
            CredentialsMatchers.anyOf(
                    CredentialsMatchers.instanceOf(StringCredentials.class),
                    CredentialsMatchers.instanceOf(UsernamePasswordCredentials.class)
            ),
            CredentialsProvider.lookupCredentials(StandardCredentials.class, item, null, Collections.<DomainRequirement>emptyList())
    );
}
 
Example 29
Source Project: github-branch-source-plugin   Source File: BranchDiscoveryTrait.java    License: MIT License 5 votes vote down vote up
/**
 * Populates the strategy options.
 *
 * @return the strategy options.
 */
@NonNull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler
public ListBoxModel doFillStrategyIdItems() {
    ListBoxModel result = new ListBoxModel();
    result.add(Messages.BranchDiscoveryTrait_excludePRs(), "1");
    result.add(Messages.BranchDiscoveryTrait_onlyPRs(), "2");
    result.add(Messages.BranchDiscoveryTrait_allBranches(), "3");
    return result;
}
 
Example 30
Source Project: aws-codebuild-jenkins-plugin   Source File: CodeBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillCwlStreamingDisabledItems() {
    final ListBoxModel selections = new ListBoxModel();

    for(BooleanValue t: BooleanValue.values()) {
        selections.add(t.toString());
    }

    return selections;
}