public ListBoxModel doFillApiTokenIdItems(@QueryParameter String name, @QueryParameter String url) { if (Jenkins.getInstance().hasPermission(Item.CONFIGURE)) { AbstractIdCredentialsListBoxModel<StandardListBoxModel, StandardCredentials> options = new StandardListBoxModel() .includeEmptyValue() .includeMatchingAs(ACL.SYSTEM, Jenkins.getActiveInstance(), StandardCredentials.class, URIRequirementBuilder.fromUri(url).build(), new GitLabCredentialMatcher()); if (name != null && connectionMap.containsKey(name)) { String apiTokenId = connectionMap.get(name).getApiTokenId(); options.includeCurrentValue(apiTokenId); for (ListBoxModel.Option option : options) { if (option.value.equals(apiTokenId)) { option.selected = true; } } } return options; } return new StandardListBoxModel(); }
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)); } }
@SuppressWarnings("unused") public ListBoxModel doFillCredentialsIdItems(@QueryParameter String credentialsId) { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { return new StandardListBoxModel().includeCurrentValue(credentialsId); } return new StandardListBoxModel() .includeEmptyValue() .includeMatchingAs( ACL.SYSTEM, Jenkins.getInstance(), StringCredentials.class, Collections.<DomainRequirement>emptyList(), CredentialsMatchers.always() ); } }
@SuppressWarnings("unused") public ListBoxModel doFillCredentialsIdItems(@QueryParameter String apiUrl, @QueryParameter String credentialsId) { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { return new StandardListBoxModel().includeCurrentValue(credentialsId); } return new StandardListBoxModel() .includeEmptyValue() .includeMatchingAs(ACL.SYSTEM, Jenkins.getInstance(), StringCredentials.class, fromUri(defaultIfBlank(apiUrl, GITHUB_URL)).build(), CredentialsMatchers.always() ); }
@SuppressWarnings("unused") public ListBoxModel doFillCredentialsIdItems(@QueryParameter String apiUrl, @QueryParameter String credentialsId) { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { return new StandardUsernameListBoxModel().includeCurrentValue(credentialsId); } return new StandardUsernameListBoxModel() .includeEmptyValue() .includeMatchingAs( ACL.SYSTEM, Jenkins.getInstance(), StandardUsernamePasswordCredentials.class, fromUri(defaultIfBlank(apiUrl, GITHUB_URL)).build(), CredentialsMatchers.always() ) .includeMatchingAs( Jenkins.getAuthentication(), Jenkins.getInstance(), StandardUsernamePasswordCredentials.class, fromUri(defaultIfBlank(apiUrl, GITHUB_URL)).build(), CredentialsMatchers.always() ); }
/** * 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 ? Tasks.getDefaultAuthenticationOf((Queue.Task) context) : ACL.SYSTEM, context, StandardUsernameCredentials.class, githubDomainRequirements(apiUri), githubScanCredentialsMatcher() ); }
/** * Adds the ids of the specified credential type that are available to the specified context as the current * authentication with the specified domain requirements and match the specified filter. * * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @param matcher the filter to apply to the credentials. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeMatching(@Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) { return includeMatchingAs(Jenkins.getAuthentication(), context, type, domainRequirements, matcher); }
/** * Adds the ids of the specified credential type that are available to the specified context as the current * authentication with the specified domain requirements and match the specified filter. * * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @param matcher the filter to apply to the credentials. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeMatching(@NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) { return includeMatchingAs(Jenkins.getAuthentication(), context, type, domainRequirements, matcher); }
/** * Adds the ids of the specified credential type that are available to the specified context as the specified * authentication with the specified domain requirements. * * @param authentication the authentication to search with * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements) { return includeMatchingAs(authentication, context, type, domainRequirements, CredentialsMatchers.always()); }
/** * Adds the ids of the specified credential type that are available to the specified context as the specified * authentication with the specified domain requirements. * * @param authentication the authentication to search with * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements) { return includeMatchingAs(authentication, context, type, domainRequirements, CredentialsMatchers.always()); }
/** * Adds the ids of the specified credential type that are available to the specified context as the current * authentication with the specified domain requirements and match the specified filter. * * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @param matcher the filter to apply to the credentials. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeMatching(@Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) { return includeMatchingAs(Jenkins.getAuthentication(), context, type, domainRequirements, matcher); }
/** * Adds the ids of the specified credential type that are available to the specified context as the current * authentication with the specified domain requirements and match the specified filter. * * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @param matcher the filter to apply to the credentials. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeMatching(@NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) { return includeMatchingAs(Jenkins.getAuthentication(), context, type, domainRequirements, matcher); }
/** * Adds the ids of the specified credential type that are available to the specified context as the specified * authentication with the specified domain requirements. * * @param authentication the authentication to search with * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements) { return includeMatchingAs(authentication, context, type, domainRequirements, CredentialsMatchers.always()); }
/** * Adds the ids of the specified credential type that are available to the specified context as the specified * authentication with the specified domain requirements. * * @param authentication the authentication to search with * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements) { return includeMatchingAs(authentication, context, type, domainRequirements, CredentialsMatchers.always()); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item project, @QueryParameter String url, @QueryParameter String credentialsId) { if (project == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) || project != null && !project.hasPermission(Item.EXTENDED_READ)) { return new StandardListBoxModel().includeCurrentValue(credentialsId); } if (project == null) { /* Construct a fake project */ project = new FreeStyleProject(Jenkins.getInstance(), "fake-" + UUID.randomUUID().toString()); } return new StandardListBoxModel() .includeEmptyValue() .includeMatchingAs( project instanceof Queue.Task ? Tasks.getAuthenticationOf((Queue.Task) project) : ACL.SYSTEM, project, StandardUsernameCredentials.class, GitURIRequirementsBuilder.fromUri(url).build(), GitClient.CREDENTIALS_MATCHER) .includeCurrentValue(credentialsId); }
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); }
public static ListBoxModel doFillCredentialsIdItems(Item item, String credentialsId, String uri) { 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); }