/** * 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 ? Tasks.getDefaultAuthenticationOf((Queue.Task) context) : ACL.SYSTEM, context, StandardUsernameCredentials.class, githubDomainRequirements(apiUri), GitClient.CREDENTIALS_MATCHER ); }
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.getActiveInstance().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> build = URIRequirementBuilder.fromUri(url).build(); CredentialsMatcher always = CredentialsMatchers.always(); Class<StandardUsernameCredentials> type = StandardUsernameCredentials.class; result.includeEmptyValue(); if (item != null) { result.includeMatchingAs(authentication, item, type, build, always); } else { result.includeMatchingAs(authentication, Jenkins.getActiveInstance(), type, build, always); } return result; }
@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 ); }
/** * 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.getActiveInstance().checkPermission(Jenkins.ADMINISTER); StandardListBoxModel result = new StandardListBoxModel(); serverUrl = GiteaServers.normalizeServerUrl(serverUrl); result.includeMatchingAs( ACL.SYSTEM, Jenkins.getActiveInstance(), StandardCredentials.class, URIRequirementBuilder.fromUri(serverUrl).build(), AuthenticationTokens.matcher(GiteaAuth.class) ); return result; }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String serverUrl, @QueryParameter String credentialsId) { StandardListBoxModel result = new StandardListBoxModel(); if (context == null) { if (!Jenkins.getActiveInstance().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 ? Tasks.getDefaultAuthenticationOf((Queue.Task) context) : ACL.SYSTEM, context, StandardCredentials.class, URIRequirementBuilder.fromUri(serverUrl).build(), AuthenticationTokens.matcher(GiteaAuth.class) ); return result; }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String serverUrl, @QueryParameter String credentialsId) { StandardListBoxModel result = new StandardListBoxModel(); if (context == null) { if (!Jenkins.getActiveInstance().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 ? Tasks.getDefaultAuthenticationOf((Queue.Task) context) : ACL.SYSTEM, context, StandardCredentials.class, URIRequirementBuilder.fromUri(serverUrl).build(), AuthenticationTokens.matcher(GiteaAuth.class) ); return result; }
/** * 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.getActiveInstance().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 ? Tasks.getDefaultAuthenticationOf((Queue.Task) context) : ACL.SYSTEM, context, StandardUsernameCredentials.class, Connector.githubDomainRequirements(apiUri), CredentialsMatchers.instanceOf(SSHUserPrivateKey.class) ); }
result.includeMatchingAs( context instanceof Queue.Task ? Tasks.getDefaultAuthenticationOf((Queue.Task) context)