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 doFillKubeconfigIdItems(@AncestorInPath Item owner) { StandardListBoxModel model = new StandardListBoxModel(); model.includeEmptyValue(); model.includeAs(ACL.SYSTEM, owner, KubeconfigCredentials.class); return model; }
public ListBoxModel doFillSshCredentialIdItems(@AncestorInPath Item owner) { StandardListBoxModel model = new StandardListBoxModel(); model.includeEmptyValue(); model.includeAs(ACL.SYSTEM, owner, StandardUsernameCredentials.class); return model; } }
public ListBoxModel doFillAzureCredentialsIdItems(@AncestorInPath Item owner) { return new StandardListBoxModel() .includeEmptyValue() .withAll(CredentialsProvider.lookupCredentials(AzureCredentials.class, owner, ACL.SYSTEM, Collections.<DomainRequirement>emptyList())) .withAll(CredentialsProvider.lookupCredentials(AzureMsiCredentials.class, owner, ACL.SYSTEM, Collections.<DomainRequirement>emptyList())); }
@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() ); }
/** * 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; }
@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() ); } }
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(
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 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; }
/** * 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; }
/** * 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; }
/** * 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; }
@Restricted(DoNotUse.class) @RequirePOST public ListBoxModel doFillCredentialIdItems() { Jenkins jenkins = Jenkins.getInstance(); jenkins.checkPermission(Jenkins.ADMINISTER); List<StandardCredentials> credentials = CredentialsProvider.lookupCredentials( StandardCredentials.class, jenkins, ACL.SYSTEM, Collections.emptyList() ); return new StandardListBoxModel() .includeEmptyValue() .withMatching(CredentialsMatchers.instanceOf(OpenstackCredential.class), credentials) ; } }
/** * 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 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 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)); } }
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 fillAuthenticationItems(Item project, String url) { if (project == null || !project.hasPermission(Item.CONFIGURE)) { return new StandardListBoxModel(); } List<Option> options = new ArrayList<>(); for (BasicDigestAuthentication basic : HttpRequestGlobalConfig.get().getBasicDigestAuthentications()) { options.add(new Option("(deprecated - use Jenkins Credentials) " + basic.getKeyName(), basic.getKeyName())); } for (FormAuthentication formAuthentication : HttpRequestGlobalConfig.get().getFormAuthentications()) { options.add(new Option(formAuthentication.getKeyName())); } AbstractIdCredentialsListBoxModel<StandardListBoxModel, StandardCredentials> items = new StandardListBoxModel() .includeEmptyValue() .includeAs(ACL.SYSTEM, project, StandardUsernamePasswordCredentials.class, URIRequirementBuilder.fromUri(url).build()); items.addMissing(options); return items; }
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); }