public abstract class AbstractIdCredentialsListBoxModel<T extends AbstractIdCredentialsListBoxModel<T,C>,C extends IdCredentials> extends ListBoxModel
ListBoxModel
with support for credentials.
This class is convenient for providing the config.groovy
or config.jelly
fragment for a collection
of objects of some IdCredentials
subtype.
If you want to let the user configure a credentials object, do the following:
First, create a field that stores the credentials ID and defines a corresponding parameter in the constructor:
private String credentialsId; @DataBoundConstructor public MyModel( .... , String credentialsId) { this.credentialsId = credentialsId; ... } public String getCredentialsId() {return credentialsId;}
Your config.groovy
should have the following entry to render a drop-down list box:
f.entry(title:_("Credentials"), field:"credentialsId") { f.select() }
Finally, your Descriptor
implementation should have the doFillCredentialsIdItems
method, which
lists up the credentials available in this context:
public ListBoxModel doFillCredentialsIdItems(@QueryParam String value) { if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { // or whatever permission is appropriate for this page // Important! Otherwise you expose credentials metadata to random web requests. return new StandardUsernameListBoxModel().includeCurrentValue(value); } return new StandardUsernameListBoxModel() .includeEmptySelection() .include(StandardUsernameCredentials.class,...)) .includeCurrentValue(value); }
Exactly which overloaded version of the include(Item, Class)
depends on
the context in which your model operates. Here are a few common examples:
Jenkins
(such as slaves), or do not have any ancestors serving as the context, then use Jenkins.get()
as the
context.
Item
(such as its major subtype Job
),
then use that Item
as the context.
For example:
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item context, @QueryParameter String source) { if (context == null || !context.hasPermission(Item.CONFIGURE)) { return new StandardUsernameListBoxModel().includeCurrentValue(value); } return new StandardUsernameListBoxModel() .includeEmptySelection() .includeAs(Tasks.getAuthenticationOf(context), context, StandardUsernameCredentials.class, URIRequirementBuilder.fromUri(source).build()) .includeCurrentValue(value); }
ListBoxModel.Option
modCount
Constructor and Description |
---|
AbstractIdCredentialsListBoxModel() |
Modifier and Type | Method and Description |
---|---|
boolean |
addMissing(Collection<? extends ListBoxModel.Option> c)
Appends all of the missing elements from the specified collection to the end of
this list, in the order that they are returned by the
specified collection's Iterator.
|
protected abstract String |
describe(C c)
Generate a description of the supplied credential.
|
AbstractIdCredentialsListBoxModel<T,C> |
include(Item context,
Class<? extends C> type)
Adds the ids of the specified credential type that are available to the specified context as the current
authentication.
|
AbstractIdCredentialsListBoxModel<T,C> |
include(Item context,
Class<? extends C> type,
List<DomainRequirement> domainRequirements)
Adds the ids of the specified credential type that are available to the specified context as the current
authentication with the specified domain requirements.
|
AbstractIdCredentialsListBoxModel<T,C> |
include(ItemGroup context,
Class<? extends C> type)
Adds the ids of the specified credential type that are available to the specified context as the current
authentication.
|
AbstractIdCredentialsListBoxModel<T,C> |
include(ItemGroup context,
Class<? extends C> type,
List<DomainRequirement> domainRequirements)
Adds the ids of the specified credential type that are available to the specified context as the current
authentication with the specified domain requirements.
|
AbstractIdCredentialsListBoxModel<T,C> |
includeAs(Authentication authentication,
Item context,
Class<? extends C> type)
Adds the ids of the specified credential type that are available to the specified context as the specified
authentication.
|
AbstractIdCredentialsListBoxModel<T,C> |
includeAs(Authentication authentication,
Item context,
Class<? extends C> type,
List<DomainRequirement> domainRequirements)
Adds the ids of the specified credential type that are available to the specified context as the specified
authentication with the specified domain requirements.
|
AbstractIdCredentialsListBoxModel<T,C> |
includeAs(Authentication authentication,
ItemGroup context,
Class<? extends C> type)
Adds the ids of the specified credential type that are available to the specified context as the specified
authentication.
|
AbstractIdCredentialsListBoxModel<T,C> |
includeAs(Authentication authentication,
ItemGroup context,
Class<? extends C> type,
List<DomainRequirement> domainRequirements)
Adds the ids of the specified credential type that are available to the specified context as the specified
authentication with the specified domain requirements.
|
AbstractIdCredentialsListBoxModel<T,C> |
includeCurrentValue(String value)
Ensures that the current value is present so that the form can be idempotently saved in those cases where the
user saving the form cannot view the current credential
|
AbstractIdCredentialsListBoxModel<T,C> |
includeEmptyValue()
Adds an "empty" credential to signify selection of no credential.
|
AbstractIdCredentialsListBoxModel<T,C> |
includeMatching(Item context,
Class<? extends C> type,
List<DomainRequirement> domainRequirements,
CredentialsMatcher 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.
|
AbstractIdCredentialsListBoxModel<T,C> |
includeMatching(ItemGroup context,
Class<? extends C> type,
List<DomainRequirement> domainRequirements,
CredentialsMatcher 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.
|
AbstractIdCredentialsListBoxModel<T,C> |
includeMatchingAs(Authentication authentication,
Item context,
Class<? extends C> type,
List<DomainRequirement> domainRequirements,
CredentialsMatcher 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 and match the specified filter.
|
AbstractIdCredentialsListBoxModel<T,C> |
includeMatchingAs(Authentication authentication,
ItemGroup context,
Class<? extends C> type,
List<DomainRequirement> domainRequirements,
CredentialsMatcher 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 and match the specified filter.
|
AbstractIdCredentialsListBoxModel<T,C> |
with(C u)
Adds a single credential.
|
AbstractIdCredentialsListBoxModel<T,C> |
withAll(C... credentials)
Deprecated.
prefer using the
include(Item, Class) or includeAs(Authentication, Item, Class)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins. |
AbstractIdCredentialsListBoxModel<T,C> |
withAll(Iterable<? extends C> credentials)
Deprecated.
prefer using the
include(Item, Class) or includeAs(Authentication, Item, Class)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins. |
AbstractIdCredentialsListBoxModel<T,C> |
withAll(Iterator<? extends C> credentials)
Deprecated.
prefer using the
include(Item, Class) or includeAs(Authentication, Item, Class)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins. |
AbstractIdCredentialsListBoxModel<T,C> |
withEmptySelection()
Deprecated.
|
AbstractIdCredentialsListBoxModel<T,C> |
withMatching(CredentialsMatcher matcher,
C... credentials)
Deprecated.
prefer using the
includeMatching(Item, Class, List, CredentialsMatcher)
or includeMatchingAs(Authentication, Item, Class, List, CredentialsMatcher)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins. |
AbstractIdCredentialsListBoxModel<T,C> |
withMatching(CredentialsMatcher matcher,
Iterable<? extends C> credentials)
Deprecated.
prefer using the
includeMatching(Item, Class, List, CredentialsMatcher)
or includeMatchingAs(Authentication, Item, Class, List, CredentialsMatcher)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins. |
AbstractIdCredentialsListBoxModel<T,C> |
withMatching(CredentialsMatcher matcher,
Iterator<? extends C> credentials)
Deprecated.
prefer using the
includeMatching(Item, Class, List, CredentialsMatcher)
or includeMatchingAs(Authentication, Item, Class, List, CredentialsMatcher)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins. |
add, add, add, generateResponse, values, writeTo
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
equals, hashCode
containsAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, equals, hashCode
parallelStream, stream
@NonNull protected abstract String describe(@NonNull C c)
c
- the credential.@NonNull public AbstractIdCredentialsListBoxModel<T,C> with(@CheckForNull C u)
u
- the credential to add.this
for method chaining.@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withEmptySelection()
includeEmptyValue()
this
for method chaining.@NonNull public AbstractIdCredentialsListBoxModel<T,C> includeEmptyValue()
this
for method chaining.@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withAll(@NonNull C... credentials)
include(Item, Class)
or includeAs(Authentication, Item, Class)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins.credentials
- the credentials.this
for method chaining.@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withAll(@NonNull Iterable<? extends C> credentials)
include(Item, Class)
or includeAs(Authentication, Item, Class)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins.credentials
- the credentials.this
for method chaining.@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withAll(@NonNull Iterator<? extends C> credentials)
include(Item, Class)
or includeAs(Authentication, Item, Class)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins.credentials
- the credentials.this
for method chaining.@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withMatching(@NonNull CredentialsMatcher matcher, @NonNull C... credentials)
includeMatching(Item, Class, List, CredentialsMatcher)
or includeMatchingAs(Authentication, Item, Class, List, CredentialsMatcher)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins.matcher
- the matcher.credentials
- the superset of credentials.this
for method chaining.@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withMatching(@NonNull CredentialsMatcher matcher, @NonNull Iterable<? extends C> credentials)
includeMatching(Item, Class, List, CredentialsMatcher)
or includeMatchingAs(Authentication, Item, Class, List, CredentialsMatcher)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins.matcher
- the matcher.credentials
- the superset of credentials.this
for method chaining.@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withMatching(@NonNull CredentialsMatcher matcher, @NonNull Iterator<? extends C> credentials)
includeMatching(Item, Class, List, CredentialsMatcher)
or includeMatchingAs(Authentication, Item, Class, List, CredentialsMatcher)
methods to build the list box contents in order to allow credentials providers to not have to instantiate
a full credential instance where those credential providers store the secrets external from Jenkins.matcher
- the matcher.credentials
- the superset of credentials.this
for method chaining.public AbstractIdCredentialsListBoxModel<T,C> include(@Nullable Item context, @NonNull Class<? extends C> type)
context
- the context to add credentials from.type
- the base class of the credentials to add.this
for method chaining.CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> include(@NonNull ItemGroup context, @NonNull Class<? extends C> type)
context
- the context to add credentials from.type
- the base class of the credentials to add.this
for method chaining.CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type)
authentication
- the authentication to search withcontext
- the context to add credentials from.type
- the base class of the credentials to add.this
for method chaining.CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type)
authentication
- the authentication to search withcontext
- the context to add credentials from.type
- the base class of the credentials to add.this
for method chaining.CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> include(@Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements)
context
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.this
for method chaining.CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> include(@NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements)
context
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.this
for method chaining.CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements)
authentication
- the authentication to search withcontext
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.this
for method chaining.CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements)
authentication
- the authentication to search withcontext
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.this
for method chaining.CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> includeMatching(@Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher)
context
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.matcher
- the filter to apply to the credentials.this
for method chaining.CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> includeMatching(@NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher)
context
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.matcher
- the filter to apply to the credentials.this
for method chaining.CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> includeMatchingAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher)
authentication
- the authentication to search withcontext
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.matcher
- the filter to apply to the credentials.this
for method chaining.CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> includeMatchingAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher)
authentication
- the authentication to search withcontext
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.matcher
- the filter to apply to the credentials.this
for method chaining.CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
public AbstractIdCredentialsListBoxModel<T,C> includeCurrentValue(@NonNull String value)
value
- the current value.this
for method chaining.public boolean addMissing(@NonNull Collection<? extends ListBoxModel.Option> c)
c
- collection containing elements to be added to this listtrue
if this list changed as a result of the callCopyright © 2016–2021. All rights reserved.