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 doFillCredentialsIdItems() { return new StandardListBoxModel() .withEmptySelection() .withMatching( CredentialsMatchers.always(), CredentialsProvider.lookupCredentials(AmazonWebServicesCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.emptyList())); } }
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() ) ); }
/** * This method is called to populate the credentials list on the Jenkins * config page. */ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter("target") final String target) { StandardListBoxModel result = new StandardListBoxModel(); result.includeEmptyValue(); result.withMatching(CredentialsMatchers.instanceOf(StandardCredentials.class), CredentialsProvider.lookupCredentials(StandardCredentials.class, context, ACL.SYSTEM, URIRequirementBuilder.fromUri(target).build())); return result; }
public StandardListBoxModel doFillDefaultValueItems(@AncestorInPath Item context, @QueryParameter(required = true) String credentialType) { // TODO switch to Jenkins.getInstance() once 2.0+ is the baseline Jenkins jenkins = Jenkins.getActiveInstance(); final ACL acl = context == null ? jenkins.getACL() : context.getACL(); final Class<? extends StandardCredentials> typeClass = decodeType(credentialType); final List<DomainRequirement> domainRequirements = Collections.<DomainRequirement>emptyList(); final StandardListBoxModel result = new StandardListBoxModel(); result.includeEmptyValue(); if (acl.hasPermission(CredentialsProvider.USE_ITEM)) { result.includeAs(CredentialsProvider.getDefaultAuthenticationOf(context), context, typeClass, domainRequirements); } return result; }
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(DoNotUse.class) // Stapler only. @SuppressWarnings("unused") // Used by stapler. @RequirePOST public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String master) { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); List<DomainRequirement> domainRequirements = (master == null) ? Collections.<DomainRequirement>emptyList() : URIRequirementBuilder.fromUri(master.trim()).build(); return new StandardListBoxModel().withEmptySelection().withMatching( CredentialsMatchers.instanceOf(UsernamePasswordCredentials.class), CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class, item, null, domainRequirements) ); }
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); } return Connector.listScanCredentials(context, apiUri); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String value) { AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (!ac.hasPermission(Jenkins.ADMINISTER)) { return new StandardListBoxModel().includeCurrentValue(value); } return new StandardListBoxModel().includeAs( ACL.SYSTEM, context, DockerServerCredentials.class, Collections.<DomainRequirement>emptyList()); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item context, @QueryParameter String tagsDir) { if (context == null || !context.hasPermission(Item.EXTENDED_READ)) { return new StandardListBoxModel(); } return Jenkins.getInstance().getDescriptorByType( SubversionSCM.ModuleLocation.DescriptorImpl.class).fillCredentialsIdItems(context, tagsDir); }
@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 ); }
@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() ); } }
/** * 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) ); }
@SuppressWarnings("unused") public ListBoxModel doFillCredentialsIdItems( @QueryParameter final String collectionUrl) { final Jenkins jenkins = Jenkins.getInstance(); String hostName = null; try { final URI uri = new URI(collectionUrl); hostName = uri.getHost(); } catch (final URISyntaxException ignored) { } if (hostName == null || !jenkins.hasPermission(Jenkins.ADMINISTER)) { return new ListBoxModel(); } final List<StandardUsernamePasswordCredentials> matches = findCredentials(hostName); return new StandardListBoxModel() .withEmptySelection() .withAll(matches); } }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item project) { Jenkins jenkins = Jenkins.getInstance(); if (project != null && project.hasPermission(Item.CONFIGURE)) { return new StandardListBoxModel() .withEmptySelection() .withMatching( new StashCredentialMatcher(), CredentialsProvider.lookupCredentials( StandardCredentials.class, project, ACL.SYSTEM, new ArrayList<DomainRequirement>())); } else if (jenkins != null && jenkins.hasPermission(Item.CONFIGURE)) { return new StandardListBoxModel() .withEmptySelection() .withMatching( new StashCredentialMatcher(), CredentialsProvider.lookupCredentials( StandardCredentials.class, jenkins, ACL.SYSTEM, new ArrayList<DomainRequirement>())); } return new StandardListBoxModel(); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item owner, @QueryParameter String collectionUrl) { StandardListBoxModel listBoxModel = new StandardListBoxModel(); listBoxModel.withEmptySelection(); String hostName = null; try { final URI uri = new URI(collectionUrl); hostName = uri.getHost(); } catch (final URISyntaxException ignored) { } listBoxModel.withAll(TeamCollectionConfiguration.findCredentials(hostName, owner)); return listBoxModel; }
public ListBoxModel doFillJdbcCredentialsIdItems() { // use deprecated "withMatching" because, even after 20 mins of research, // I didn't understand how to use the new "recommended" API return new StandardListBoxModel() .includeEmptyValue() .withMatching( CredentialsMatchers.always(), CredentialsProvider.lookupCredentials(UsernamePasswordCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.EMPTY_LIST)); } public FormValidation doValidateJdbcConnection(
/** * 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 doFillReleaseDefinitionNameItems(@QueryParameter String collectionUrl, @QueryParameter String credentialsId, @QueryParameter String projectName) { StandardListBoxModel listBoxModel = new StandardListBoxModel(); listBoxModel.withEmptySelection(); listBoxModel.add(releaseDefinition.getName());
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); }