Class CredentialsResolver<F extends Credentials,T extends Credentials>
- java.lang.Object
-
- com.cloudbees.plugins.credentials.CredentialsResolver<F,T>
-
- Type Parameters:
F
- the class that the resolver resolves from.T
- the class that the resolver resolves to. Typically this class will have areadResolve()
method that returns an instance of the class that the resolver resolves from.
public abstract class CredentialsResolver<F extends Credentials,T extends Credentials> extends Object
TranslatesCredentials
from one type into another. We only support point-to-point translation, not a chain. Translation is designed to help plugins migrate towards common credential interfaces once they have been standardized, so the intention is that a plugin that implemented an old credential type and has migrated to the new type would also provide a translator.- Since:
- 1.6
- See Also:
ResolveWith
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CredentialsResolver(Class<F> fromClass)
Infers the to type of the correspondingCredentials
from the outer class.protected
CredentialsResolver(Class<F> fromClass, Class<T> toClass)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract T
doResolve(F original)
Resolves the supplied credentials.Class<F>
getFromClass()
Returns the class to resolve from.static <C extends Credentials>
CredentialsResolver<Credentials,C>getResolver(Class<C> clazz)
Retrieves theCredentialsResolver
for the specified type (if it exists)Class<T>
getToClass()
Returns the class to resolve to.T
resolve(F original)
Resolves the supplied credentials.List<T>
resolve(Collection<? extends F> originals)
Resolves the supplied credentials.
-
-
-
Constructor Detail
-
CredentialsResolver
protected CredentialsResolver(@NonNull Class<F> fromClass, @NonNull Class<T> toClass)
Constructor.- Parameters:
fromClass
- the class to resolve from.toClass
- the class to resolve to.
-
CredentialsResolver
protected CredentialsResolver(@NonNull Class<F> fromClass)
Infers the to type of the correspondingCredentials
from the outer class. This version works when you follow the common convention, where a resolver is written as the static nested class of the resolved class.- Parameters:
fromClass
- the class to resolve from.
-
-
Method Detail
-
getResolver
@CheckForNull public static <C extends Credentials> CredentialsResolver<Credentials,C> getResolver(@NonNull Class<C> clazz)
Retrieves theCredentialsResolver
for the specified type (if it exists)- Type Parameters:
C
- the type.- Parameters:
clazz
- the type.- Returns:
- the
CredentialsResolver
to use ornull
if no resolver is required.
-
getFromClass
@NonNull public Class<F> getFromClass()
Returns the class to resolve from.- Returns:
- the class to resolve from.
-
getToClass
@NonNull public Class<T> getToClass()
Returns the class to resolve to.- Returns:
- the class to resolve to.
-
resolve
@NonNull public T resolve(@NonNull F original)
Resolves the supplied credentials.- Parameters:
original
- the original type of credential.- Returns:
- the resolved credentials or the original if they already implement the required interface.
-
resolve
@NonNull public final List<T> resolve(@CheckForNull Collection<? extends F> originals)
Resolves the supplied credentials.- Parameters:
originals
- credentials of the original type.- Returns:
- the resolved credentials.
-
-