Class AbstractIdCredentialsListBoxModel<T extends AbstractIdCredentialsListBoxModel<T,C>,C extends IdCredentials>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<ListBoxModel.Option>
-
- hudson.util.ListBoxModel
-
- com.cloudbees.plugins.credentials.common.AbstractIdCredentialsListBoxModel<T,C>
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<ListBoxModel.Option>
,Collection<ListBoxModel.Option>
,List<ListBoxModel.Option>
,RandomAccess
,org.kohsuke.stapler.HttpResponse
- Direct Known Subclasses:
StandardListBoxModel
,StandardUsernameListBoxModel
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
orconfig.jelly
fragment for a collection of objects of someIdCredentials
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 thedoFillCredentialsIdItems
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:- System-level settings
-
If your model is a singleton in the whole Jenkins instance, things that belong to the root
Jenkins
(such as agents), or do not have any ancestors serving as the context, then useJenkins.get()
as the context. - Job-level settings
-
If your model is a configuration fragment added to a
Item
(such as its major subtypeJob
), then use thatItem
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); }
- Since:
- 1.6
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class hudson.util.ListBoxModel
ListBoxModel.Option
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description AbstractIdCredentialsListBoxModel()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method 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(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>
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>
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>
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>
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 credentialAbstractIdCredentialsListBoxModel<T,C>
includeEmptyValue()
Adds an "empty" credential to signify selection of no credential.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>
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>
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>
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>
with(C u)
Adds a single credential.AbstractIdCredentialsListBoxModel<T,C>
withAll(C... credentials)
Deprecated.prefer using theinclude(Item, Class)
orincludeAs(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 theinclude(Item, Class)
orincludeAs(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 theinclude(Item, Class)
orincludeAs(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 theincludeMatching(Item, Class, List, CredentialsMatcher)
orincludeMatchingAs(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 theincludeMatching(Item, Class, List, CredentialsMatcher)
orincludeMatchingAs(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 theincludeMatching(Item, Class, List, CredentialsMatcher)
orincludeMatchingAs(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.-
Methods inherited from class hudson.util.ListBoxModel
add, add, add, generateResponse, values, writeTo
-
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Methods inherited from class java.util.AbstractCollection
containsAll, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.List
containsAll
-
-
-
-
Method Detail
-
describe
@NonNull protected abstract String describe(@NonNull C c)
Generate a description of the supplied credential.- Parameters:
c
- the credential.- Returns:
- the description.
-
with
@NonNull public AbstractIdCredentialsListBoxModel<T,C> with(@CheckForNull C u)
Adds a single credential.- Parameters:
u
- the credential to add.- Returns:
this
for method chaining.
-
withEmptySelection
@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withEmptySelection()
Deprecated.Adds an "empty" credential to signify selection of no credential.- Returns:
this
for method chaining.
-
includeEmptyValue
@NonNull public AbstractIdCredentialsListBoxModel<T,C> includeEmptyValue()
Adds an "empty" credential to signify selection of no credential.- Returns:
this
for method chaining.- Since:
- 2.1.0
-
withAll
@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withAll(@NonNull C... credentials)
Deprecated.prefer using theinclude(Item, Class)
orincludeAs(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.Adds supplied credentials to the model.- Parameters:
credentials
- the credentials.- Returns:
this
for method chaining.
-
withAll
@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withAll(@NonNull Iterable<? extends C> credentials)
Deprecated.prefer using theinclude(Item, Class)
orincludeAs(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.Adds supplied credentials to the model.- Parameters:
credentials
- the credentials.- Returns:
this
for method chaining.
-
withAll
@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withAll(@NonNull Iterator<? extends C> credentials)
Deprecated.prefer using theinclude(Item, Class)
orincludeAs(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.Adds supplied credentials to the model.- Parameters:
credentials
- the credentials.- Returns:
this
for method chaining.
-
withMatching
@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withMatching(@NonNull CredentialsMatcher matcher, @NonNull C... credentials)
Deprecated.prefer using theincludeMatching(Item, Class, List, CredentialsMatcher)
orincludeMatchingAs(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.Adds the matching subset of supplied credentials to the model.- Parameters:
matcher
- the matcher.credentials
- the superset of credentials.- Returns:
this
for method chaining.
-
withMatching
@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withMatching(@NonNull CredentialsMatcher matcher, @NonNull Iterable<? extends C> credentials)
Deprecated.prefer using theincludeMatching(Item, Class, List, CredentialsMatcher)
orincludeMatchingAs(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.Adds the matching subset of supplied credentials to the model.- Parameters:
matcher
- the matcher.credentials
- the superset of credentials.- Returns:
this
for method chaining.
-
withMatching
@Deprecated @NonNull public AbstractIdCredentialsListBoxModel<T,C> withMatching(@NonNull CredentialsMatcher matcher, @NonNull Iterator<? extends C> credentials)
Deprecated.prefer using theincludeMatching(Item, Class, List, CredentialsMatcher)
orincludeMatchingAs(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.Adds the matching subset of supplied credentials to the model.- Parameters:
matcher
- the matcher.credentials
- the superset of credentials.- Returns:
this
for method chaining.
-
include
public AbstractIdCredentialsListBoxModel<T,C> include(@Nullable Item context, @NonNull Class<? extends C> type)
Adds the ids of the specified credential type that are available to the specified context as the current authentication.- Parameters:
context
- the context to add credentials from.type
- the base class of the credentials to add.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
-
include
public AbstractIdCredentialsListBoxModel<T,C> include(@NonNull ItemGroup context, @NonNull Class<? extends C> type)
Adds the ids of the specified credential type that are available to the specified context as the current authentication.- Parameters:
context
- the context to add credentials from.type
- the base class of the credentials to add.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
-
includeAs
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type)
Adds the ids of the specified credential type that are available to the specified context as the specified authentication.- Parameters:
authentication
- the authentication to search withcontext
- the context to add credentials from.type
- the base class of the credentials to add.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
-
includeAs
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type)
Adds the ids of the specified credential type that are available to the specified context as the specified authentication.- Parameters:
authentication
- the authentication to search withcontext
- the context to add credentials from.type
- the base class of the credentials to add.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
-
include
public AbstractIdCredentialsListBoxModel<T,C> include(@Nullable Item context, @NonNull Class<? extends C> type, @NonNull 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.- Parameters:
context
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
-
include
public AbstractIdCredentialsListBoxModel<T,C> include(@NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull 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.- Parameters:
context
- the context to add credentials from.type
- the base class of the credentials to add.domainRequirements
- the domain requirements.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
-
includeAs
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull 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.- Parameters:
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.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
-
includeAs
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull 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.- Parameters:
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.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
-
includeMatching
public AbstractIdCredentialsListBoxModel<T,C> includeMatching(@Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull 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.- Parameters:
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.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
-
includeMatching
public AbstractIdCredentialsListBoxModel<T,C> includeMatching(@NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull 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.- Parameters:
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.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
-
includeMatchingAs
public AbstractIdCredentialsListBoxModel<T,C> includeMatchingAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull 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.- Parameters:
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.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
-
includeMatchingAs
public AbstractIdCredentialsListBoxModel<T,C> includeMatchingAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull 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.- Parameters:
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.- Returns:
this
for method chaining.- Since:
- 2.1.0
- See Also:
CredentialsProvider.listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
-
includeCurrentValue
public AbstractIdCredentialsListBoxModel<T,C> includeCurrentValue(@NonNull 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- Parameters:
value
- the current value.- Returns:
this
for method chaining.- Since:
- 2.1.0
-
addMissing
public boolean addMissing(@NonNull 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. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this list, and this list is nonempty.)- Parameters:
c
- collection containing elements to be added to this list- Returns:
true
if this list changed as a result of the call- Since:
- 2.1.0
-
-