com.cloudbees.plugins.credentials.common.StandardListBoxModel Java Examples

The following examples show how to use com.cloudbees.plugins.credentials.common.StandardListBoxModel. 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: GiteaServer.java    From gitea-plugin with MIT License 6 votes vote down vote up
/**
 * Stapler form completion.
 *
 * @param serverUrl the server URL.
 * @return the available credentials.
 */
@Restricted(NoExternalUse.class) // stapler
@SuppressWarnings("unused")
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl) {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    StandardListBoxModel result = new StandardListBoxModel();
    serverUrl = GiteaServers.normalizeServerUrl(serverUrl);
    result.includeMatchingAs(
            ACL.SYSTEM,
            Jenkins.get(),
            StandardCredentials.class,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            AuthenticationTokens.matcher(GiteaAuth.class)
    );
    return result;
}
 
Example #2
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 #3
Source File: WithAWSStep.java    From pipeline-aws-plugin with Apache License 2.0 6 votes vote down vote up
public ListBoxModel doFillCredentialsItems(@AncestorInPath Item context) {

			if (context == null || !context.hasPermission(Item.CONFIGURE)) {
				return new ListBoxModel();
			}

			return new StandardListBoxModel()
					.includeEmptyValue()
					.includeMatchingAs(
							context instanceof Queue.Task
									? Tasks.getAuthenticationOf((Queue.Task) context)
									: ACL.SYSTEM,
							context,
							StandardUsernamePasswordCredentials.class,
							Collections.emptyList(),
							CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class))
					.includeMatchingAs(context instanceof Queue.Task
									? Tasks.getAuthenticationOf((Queue.Task) context)
									: ACL.SYSTEM,
							context,
							AmazonWebServicesCredentials.class,
							Collections.emptyList(),
							CredentialsMatchers.instanceOf(AmazonWebServicesCredentials.class));
		}
 
Example #4
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 #5
Source File: CredentialsHelper.java    From violation-comments-to-github-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 #6
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 #7
Source File: GitLabSCMSourceSettings.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Restricted(NoExternalUse.class)
public ListBoxModel doFillCheckoutCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String connectionName, @QueryParameter String checkoutCredentialsId) {
    if (context == null && !Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER) ||
            context != null && !context.hasPermission(Item.EXTENDED_READ)) {
        return new StandardListBoxModel().includeCurrentValue(checkoutCredentialsId);
    }

    StandardListBoxModel result = new StandardListBoxModel();
    result.add("- anonymous -", CHECKOUT_CREDENTIALS_ANONYMOUS);
    return result.includeMatchingAs(
            context instanceof Queue.Task
                    ? Tasks.getDefaultAuthenticationOf((Queue.Task) context)
                    : ACL.SYSTEM,
            context,
            StandardUsernameCredentials.class,
            SettingsUtils.gitLabConnectionRequirements(connectionName),
            GitClient.CREDENTIALS_MATCHER
    );
}
 
Example #8
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 #9
Source File: SSHCheckoutTrait.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
/**
 * Form completion.
 *
 * @param context       the context.
 * @param apiUri        the server url.
 * @param credentialsId the current selection.
 * @return the form items.
 */
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler form binding
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);
    }
    StandardListBoxModel result = new StandardListBoxModel();
    result.add(Messages.SSHCheckoutTrait_useAgentKey(), "");
    return result.includeMatchingAs(
            context instanceof Queue.Task
                    ? ((Queue.Task) context).getDefaultAuthentication()
                    : ACL.SYSTEM,
            context,
            StandardUsernameCredentials.class,
            Connector.githubDomainRequirements(apiUri),
            CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)
    );
}
 
Example #10
Source File: Connector.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
/**
 * Populates a {@link ListBoxModel} with the checkout 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 listCheckoutCredentials(@CheckForNull Item context, String apiUri) {
    StandardListBoxModel result = new StandardListBoxModel();
    result.includeEmptyValue();
    result.add("- same as scan credentials -", GitHubSCMSource.DescriptorImpl.SAME);
    result.add("- anonymous -", GitHubSCMSource.DescriptorImpl.ANONYMOUS);
    return result.includeMatchingAs(
            context instanceof Queue.Task
                    ? ((Queue.Task) context).getDefaultAuthentication()
                    : ACL.SYSTEM,
            context,
            StandardUsernameCredentials.class,
            githubDomainRequirements(apiUri),
            GitClient.CREDENTIALS_MATCHER
    );
}
 
Example #11
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 #12
Source File: KubernetesCloud.java    From kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@RequirePOST
@SuppressWarnings("unused") // used by jelly
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String serverUrl) {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    StandardListBoxModel result = new StandardListBoxModel();
    result.includeEmptyValue();
    result.includeMatchingAs(
        ACL.SYSTEM,
        context,
        StandardCredentials.class,
        serverUrl != null ? URIRequirementBuilder.fromUri(serverUrl).build()
                    : Collections.EMPTY_LIST,
        CredentialsMatchers.anyOf(
            AuthenticationTokens.matcher(KubernetesAuth.class)
        )
    );
    return result;
}
 
Example #13
Source File: GitLabPersonalAccessTokenCreator.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
@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 StandardUsernameListBoxModel()
        .includeEmptyValue()
        .includeMatchingAs(
            ACL.SYSTEM,
            jenkins,
            StandardUsernamePasswordCredentials.class,
            fromUri(defaultIfBlank(serverUrl, GitLabServer.GITLAB_SERVER_URL)).build(),
            CredentialsMatchers.always()
        ).includeMatchingAs(
            Jenkins.getAuthentication(),
            jenkins,
            StandardUsernamePasswordCredentials.class,
            fromUri(defaultIfBlank(serverUrl, GitLabServer.GITLAB_SERVER_URL)).build(),
            CredentialsMatchers.always()
        );
}
 
Example #14
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 #15
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 #16
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 #17
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 #18
Source File: AxivionSuite.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
/**
 * Shows the user all available credential id items.
 *
 * @param item
 *         jenkins configuration
 * @param credentialsId
 *         current used credentials
 *
 * @return a list view of all credential ids
 */
public ListBoxModel doFillCredentialsIdItems(
        @AncestorInPath final Item item, @QueryParameter final String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (item == null) {
        if (!new JenkinsFacade().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.includeAs(
            ACL.SYSTEM,
            item,
            StandardUsernamePasswordCredentials.class,
            Collections.emptyList())
            .includeCurrentValue(credentialsId);
}
 
Example #19
Source File: DockerRegistryEndpoint.java    From docker-commons-plugin with MIT License 6 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item) {
    if (item == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
        item != null && !item.hasPermission(Item.EXTENDED_READ)) {
        return new StandardListBoxModel();
    }
    // TODO may also need to specify a specific authentication and domain requirements
    return new StandardListBoxModel()
            .withEmptySelection()
            .withMatching(AuthenticationTokens.matcher(DockerRegistryToken.class),
                    CredentialsProvider.lookupCredentials(
                            StandardCredentials.class,
                            item,
                            null,
                            Collections.<DomainRequirement>emptyList()
                    )
            );
}
 
Example #20
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 #21
Source File: JiraCloudSiteConfig.java    From atlassian-jira-software-cloud-plugin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
public ListBoxModel doFillCredentialsIdItems(@QueryParameter final String credentialsId) {
    Jenkins instance = Jenkins.get();
    if (!instance.hasPermission(Jenkins.ADMINISTER)) {
        return new StandardListBoxModel().includeCurrentValue(credentialsId);
    }

    return new StandardListBoxModel()
            .includeEmptyValue()
            .includeMatchingAs(
                    ACL.SYSTEM,
                    instance,
                    StringCredentials.class,
                    URIRequirementBuilder.fromUri(ATLASSIAN_API_URL).build(),
                    CredentialsMatchers.always());
}
 
Example #22
Source File: GitLabSCMSource.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
        @QueryParameter String serverName, @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        // must have admin if you want the list without a context
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            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, fromUri(getServerUrlFromName(serverName)).build(),
            GitClient.CREDENTIALS_MATCHER);
    return result;
}
 
Example #23
Source File: GitHubSCMNavigator.java    From github-branch-source-plugin with 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 #24
Source File: AnsiblePlaybookStep.java    From ansible-plugin with Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Project project) {
    return new StandardListBoxModel()
        .withEmptySelection()
        .withMatching(anyOf(
            instanceOf(SSHUserPrivateKey.class),
            instanceOf(UsernamePasswordCredentials.class)),
            CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, project));
}
 
Example #25
Source File: AbstractAnsibleBuilderDescriptor.java    From ansible-plugin with Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Project project) {
    return new StandardListBoxModel()
            .withEmptySelection()
            .withMatching(anyOf(
                        instanceOf(SSHUserPrivateKey.class),
                        instanceOf(UsernamePasswordCredentials.class)),
                    CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, project));
}
 
Example #26
Source File: GitLabConnectionProperty.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
public ListBoxModel doFillJobCredentialIdItems(@AncestorInPath Item item, @QueryParameter String url,
       @QueryParameter String jobCredentialId) {
    StandardListBoxModel result = new StandardListBoxModel();
    return result.includeEmptyValue()
            .includeMatchingAs(ACL.SYSTEM, item, StandardCredentials.class,
                    URIRequirementBuilder.fromUri(url).build(), new GitLabCredentialMatcher())
            .includeCurrentValue(jobCredentialId);
}
 
Example #27
Source File: DockerServerEndpoint.java    From docker-commons-plugin with MIT License 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String uri) {
    if (item == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
        item != null && !item.hasPermission(Item.EXTENDED_READ)) {
        return new StandardListBoxModel();
    }
    List<DomainRequirement> domainRequirements = URIRequirementBuilder.fromUri(uri).build();
    domainRequirements.add(new DockerServerDomainRequirement());
    return new StandardListBoxModel()
            .withEmptySelection()
            .withMatching(
                    AuthenticationTokens.matcher(KeyMaterialFactory.class),
                    CredentialsProvider
                            .lookupCredentials(BASE_CREDENTIAL_TYPE, item, null, domainRequirements)
            );
}
 
Example #28
Source File: GitHubSCMSource.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
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 #29
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 #30
Source File: GitLabConnection.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
public ListBoxModel doFillApiTokenIdItems(@QueryParameter String url, @QueryParameter String apiTokenId) {
    if (Jenkins.get().hasPermission(Item.CONFIGURE)) {
        return new StandardListBoxModel()
            .includeEmptyValue()
            .includeMatchingAs(ACL.SYSTEM,
                Jenkins.get(),
                StandardCredentials.class,
                URIRequirementBuilder.fromUri(url).build(),
                new GitLabCredentialMatcher())
            .includeCurrentValue(apiTokenId);
    }
    return new StandardListBoxModel();
}