public abstract class AbstractIdCredentialsListBoxModel<T extends AbstractIdCredentialsListBoxModel<T,C>,C extends IdCredentials>
extends hudson.util.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() {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { // or whatever permission is appropriate for this page
// Important! Otherwise you expose credentials metadata to random web requests.
return new ListBoxModel();
}
return new StandardUsernameListBoxModel().withEmptySelection().withAll(
CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class,...));
}
Exactly which overloaded version of the CredentialsProvider.lookupCredentials(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.getInstance() 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 ListBoxModel();
}
return new StandardUsernameListBoxModel().withEmptySelection().withAll(
CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM, URIRequirementBuilder.fromUri(source).build()));
}
modCount| Constructor and Description |
|---|
AbstractIdCredentialsListBoxModel() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract String |
describe(C c)
Generate a description of the supplied credential.
|
AbstractIdCredentialsListBoxModel<T,C> |
with(C u)
Adds a single credential.
|
AbstractIdCredentialsListBoxModel<T,C> |
withAll(C... credentials)
Adds supplied credentials to the model.
|
AbstractIdCredentialsListBoxModel<T,C> |
withAll(Iterable<? extends C> credentials)
Adds supplied credentials to the model.
|
AbstractIdCredentialsListBoxModel<T,C> |
withAll(Iterator<? extends C> credentials)
Adds supplied credentials to the model.
|
AbstractIdCredentialsListBoxModel<T,C> |
withEmptySelection()
Adds an "empty" credential to signify selection of no credential.
|
AbstractIdCredentialsListBoxModel<T,C> |
withMatching(CredentialsMatcher matcher,
C... credentials)
Adds the matching subset of suppled credentials to the model.
|
AbstractIdCredentialsListBoxModel<T,C> |
withMatching(CredentialsMatcher matcher,
Iterable<? extends C> credentials)
Adds the matching subset of suppled credentials to the model.
|
AbstractIdCredentialsListBoxModel<T,C> |
withMatching(CredentialsMatcher matcher,
Iterator<? extends C> credentials)
Adds the matching subset of suppled credentials to the model.
|
add, add, add, generateResponse, values, writeToadd, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeRange, retainAll, set, size, subList, toArray, toArray, trimToSizeequals, hashCodecontainsAll, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitcontainsAll, equals, hashCode@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.@NonNull public AbstractIdCredentialsListBoxModel<T,C> withEmptySelection()
this for method chaining.@NonNull public AbstractIdCredentialsListBoxModel<T,C> withAll(@NonNull C... credentials)
credentials - the credentials.this for method chaining.@NonNull public AbstractIdCredentialsListBoxModel<T,C> withAll(@NonNull Iterable<? extends C> credentials)
credentials - the credentials.this for method chaining.@NonNull public AbstractIdCredentialsListBoxModel<T,C> withAll(@NonNull Iterator<? extends C> credentials)
credentials - the credentials.this for method chaining.@NonNull public AbstractIdCredentialsListBoxModel<T,C> withMatching(@NonNull CredentialsMatcher matcher, @NonNull C... credentials)
matcher - the matcher.credentials - the superset of credentials.this for method chaining.@NonNull public AbstractIdCredentialsListBoxModel<T,C> withMatching(@NonNull CredentialsMatcher matcher, @NonNull Iterable<? extends C> credentials)
matcher - the matcher.credentials - the superset of credentials.this for method chaining.@NonNull public AbstractIdCredentialsListBoxModel<T,C> withMatching(@NonNull CredentialsMatcher matcher, @NonNull Iterator<? extends C> credentials)
matcher - the matcher.credentials - the superset of credentials.this for method chaining.Copyright © 2004-2015. All Rights Reserved.