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
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:
- 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:
-
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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
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
Generate a description of the supplied credential.Adds the ids of the specified credential type that are available to the specified context as the current authentication.Adds the ids of the specified credential type that are available to the specified context as the current authentication with the specified domain requirements.Adds the ids of the specified credential type that are available to the specified context as the current authentication.Adds the ids of the specified credential type that are available to the specified context as the current authentication with the specified domain requirements.includeAs
(Authentication authentication, ItemGroup context, Class<? extends C> type) Deprecated.includeAs
(Authentication authentication, ItemGroup context, Class<? extends C> type, List<DomainRequirement> domainRequirements) Deprecated.UseincludeAs(Authentication, ItemGroup, Class, List)
instead.includeAs
(Authentication authentication, Item context, Class<? extends C> type) Deprecated.UseincludeAs(Authentication, Item, Class)
instead.includeAs
(Authentication authentication, Item context, Class<? extends C> type, List<DomainRequirement> domainRequirements) Deprecated.UseincludeAs(Authentication, Item, Class, List)
instead.includeAs
(org.springframework.security.core.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.includeAs
(org.springframework.security.core.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.includeAs
(org.springframework.security.core.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.includeAs
(org.springframework.security.core.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.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 credentialAdds an "empty" credential to signify selection of no credential.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.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.includeMatchingAs
(Authentication authentication, ItemGroup context, Class<? extends C> type, List<DomainRequirement> domainRequirements, CredentialsMatcher matcher) Deprecated.includeMatchingAs
(Authentication authentication, Item context, Class<? extends C> type, List<DomainRequirement> domainRequirements, CredentialsMatcher matcher) Deprecated.includeMatchingAs
(org.springframework.security.core.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.includeMatchingAs
(org.springframework.security.core.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.Adds a single credential.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.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.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.Deprecated.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.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.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
-
Constructor Details
-
AbstractIdCredentialsListBoxModel
public AbstractIdCredentialsListBoxModel()
-
-
Method Details
-
describe
Generate a description of the supplied credential.- Parameters:
c
- the credential.- Returns:
- the description.
-
with
Adds a single credential.- Parameters:
u
- the credential to add.- Returns:
this
for method chaining.
-
withEmptySelection
Deprecated.Adds an "empty" credential to signify selection of no credential.- Returns:
this
for method chaining.
-
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:
-
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:
-
includeAs
@Deprecated public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type) Deprecated.UseincludeAs(Authentication, Item, Class)
instead. -
includeAs
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull org.springframework.security.core.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:
- TODO
- See Also:
-
includeAs
@Deprecated public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type) Deprecated.UseincludeAs(Authentication, ItemGroup, Class)
instead. -
includeAs
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull org.springframework.security.core.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:
- TODO
- See Also:
-
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:
-
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:
-
includeAs
@Deprecated public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements) Deprecated.UseincludeAs(Authentication, Item, Class, List)
instead. -
includeAs
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull org.springframework.security.core.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:
- TODO
- See Also:
-
includeAs
@Deprecated public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements) Deprecated.UseincludeAs(Authentication, ItemGroup, Class, List)
instead. -
includeAs
public AbstractIdCredentialsListBoxModel<T,C> includeAs(@NonNull org.springframework.security.core.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:
- TODO
- See Also:
-
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:
-
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:
-
includeMatchingAs
@Deprecated public AbstractIdCredentialsListBoxModel<T,C> includeMatchingAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) Deprecated. -
includeMatchingAs
public AbstractIdCredentialsListBoxModel<T,C> includeMatchingAs(@NonNull org.springframework.security.core.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:
- TODO
- See Also:
-
includeMatchingAs
@Deprecated public AbstractIdCredentialsListBoxModel<T,C> includeMatchingAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) Deprecated. -
includeMatchingAs
public AbstractIdCredentialsListBoxModel<T,C> includeMatchingAs(@NonNull org.springframework.security.core.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:
- TODO
- See Also:
-
includeCurrentValue
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
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
-
includeAs(Authentication, ItemGroup, Class)
instead.