Class CredentialsMatchers
java.lang.Object
com.cloudbees.plugins.credentials.CredentialsMatchers
Some standard matchers and filtering utility methods.
- Since:
- 1.5
-
Method Summary
Modifier and TypeMethodDescriptionstatic CredentialsMatcherallOf(CredentialsMatcher... matchers) Creates a matcher that matches when all of the supplied matchers match.static CredentialsMatcheralways()Creates a matcher that always matches.static CredentialsMatcheranyOf(CredentialsMatcher... matchers) Creates a matcher that matches when any of the supplied matchers match.static CredentialsMatcherboth(CredentialsMatcher matcher1, CredentialsMatcher matcher2) Creates a matcher that matches when both of the supplied matchers match.static CredentialsMatchereither(CredentialsMatcher matcher1, CredentialsMatcher matcher2) Creates a matcher that matches when either of the supplied matchers match.static <C extends Credentials>
Iterable<C> filter(Iterable<C> credentials, CredentialsMatcher matcher) Filters credentials using the supplied matcher.static <C extends Credentials>
Collection<C> filter(Collection<C> credentials, CredentialsMatcher matcher) Filters credentials using the supplied matcher.static <C extends Credentials>
List<C> filter(List<C> credentials, CredentialsMatcher matcher) Filters credentials using the supplied matcher.static <C extends Credentials>
Set<C> filter(Set<C> credentials, CredentialsMatcher matcher) Filters credentials using the supplied matcher.static <C extends Credentials,V>
Map<C, V> filterKeys(Map<C, V> credentialMap, CredentialsMatcher matcher) Filters a map keyed by credentials using the supplied matcher.static <C extends Credentials,K>
Map<K, C> filterValues(Map<K, C> credentialMap, CredentialsMatcher matcher) Filters a map based on credential values using the supplied matcher.static <C extends Credentials>
CfirstOrDefault(Iterable<C> credentials, CredentialsMatcher matcher, C defaultIfNone) Returns the first credential from a collection that matches the supplied matcher or if none match then the specified default.static <C extends Credentials>
CfirstOrNull(Iterable<C> credentials, CredentialsMatcher matcher) Returns the first credential from a collection that matches the supplied matcher ornullif none match.static CredentialsMatcherinstanceOf(Class clazz) Creates a matcher that matches credentials of the specified type.static CredentialsMatchernever()Creates a matcher that never matches.static CredentialsMatchernoneOf(CredentialsMatcher... matchers) Creates a matcher that matches when none of the supplied matchers match.static CredentialsMatchernot(CredentialsMatcher matcher) Creates a matcher that inverts the supplied matcher.static CredentialsMatcherCreates a matcher that matchesIdCredentialswith the suppliedIdCredentials.getId()static CredentialsMatcherwithScope(CredentialsScope scope) Creates a matcher that matchesCredentialswith the suppliedCredentialsScope.static CredentialsMatcherwithScopes(CredentialsScope... scopes) Creates a matcher that matchesCredentialswith the suppliedCredentialsScope.static CredentialsMatcherwithScopes(Collection<CredentialsScope> scopes) Creates a matcher that matchesCredentialswith the suppliedCredentialsScope.static CredentialsMatcherwithUsername(String username) Creates a matcher that matchesUsernameCredentialswith the suppliedUsernameCredentials.getUsername()
-
Method Details
-
always
Creates a matcher that always matches.- Returns:
- a matcher that always matches.
-
never
Creates a matcher that never matches.- Returns:
- a matcher that never matches.
-
not
Creates a matcher that inverts the supplied matcher.- Parameters:
matcher- matcher to invert.- Returns:
- a matcher that is the opposite of the supplied matcher.
-
instanceOf
Creates a matcher that matches credentials of the specified type.- Parameters:
clazz- the type of credential to match.- Returns:
- a matcher that matches credentials of the specified type.
-
withId
Creates a matcher that matchesIdCredentialswith the suppliedIdCredentials.getId()- Parameters:
id- theIdCredentials.getId()to match.- Returns:
- a matcher that matches
IdCredentialswith the suppliedIdCredentials.getId() - See Also:
-
withScope
Creates a matcher that matchesCredentialswith the suppliedCredentialsScope.- Parameters:
scope- theCredentialsScopeto match.- Returns:
- a matcher that matches
Credentialswith the suppliedCredentialsScope.
-
withScopes
Creates a matcher that matchesCredentialswith the suppliedCredentialsScope.- Parameters:
scopes- theCredentialsScopes to match.- Returns:
- a matcher that matches
Credentialswith the suppliedCredentialsScopes.
-
withScopes
Creates a matcher that matchesCredentialswith the suppliedCredentialsScope.- Parameters:
scopes- theCredentialsScopes to match.- Returns:
- a matcher that matches
Credentialswith the suppliedCredentialsScopes.
-
withUsername
Creates a matcher that matchesUsernameCredentialswith the suppliedUsernameCredentials.getUsername()- Parameters:
username- theUsernameCredentials.getUsername()to match.- Returns:
- a matcher that matches
UsernameCredentialswith the suppliedUsernameCredentials.getUsername()
-
allOf
Creates a matcher that matches when all of the supplied matchers match.- Parameters:
matchers- the matchers to match.- Returns:
- a matcher that matches when all of the supplied matchers match.
-
anyOf
Creates a matcher that matches when any of the supplied matchers match.- Parameters:
matchers- the matchers to match.- Returns:
- a matcher that matches when any of the supplied matchers match.
-
both
@NonNull public static CredentialsMatcher both(@NonNull CredentialsMatcher matcher1, @NonNull CredentialsMatcher matcher2) Creates a matcher that matches when both of the supplied matchers match.- Parameters:
matcher1- the first matcher to match.matcher2- the second matcher to match.- Returns:
- a matcher that matches when both of the supplied matchers match.
-
either
@NonNull public static CredentialsMatcher either(@NonNull CredentialsMatcher matcher1, @NonNull CredentialsMatcher matcher2) Creates a matcher that matches when either of the supplied matchers match.- Parameters:
matcher1- the first matcher to match.matcher2- the second matcher to match.- Returns:
- a matcher that matches when either of the supplied matchers match.
-
noneOf
Creates a matcher that matches when none of the supplied matchers match.- Parameters:
matchers- the matchers to match.- Returns:
- a matcher that matches when none of the supplied matchers match.
-
filter
@NonNull public static <C extends Credentials> Collection<C> filter(@NonNull Collection<C> credentials, @NonNull CredentialsMatcher matcher) Filters credentials using the supplied matcher.- Type Parameters:
C- the type of credentials.- Parameters:
credentials- the credentials to filter.matcher- the matcher to match on.- Returns:
- only those credentials that match the supplied matcher.
-
filter
@NonNull public static <C extends Credentials> Set<C> filter(@NonNull Set<C> credentials, @NonNull CredentialsMatcher matcher) Filters credentials using the supplied matcher.- Type Parameters:
C- the type of credentials.- Parameters:
credentials- the credentials to filter.matcher- the matcher to match on.- Returns:
- only those credentials that match the supplied matcher.
-
filter
@NonNull public static <C extends Credentials> List<C> filter(@NonNull List<C> credentials, @NonNull CredentialsMatcher matcher) Filters credentials using the supplied matcher.- Type Parameters:
C- the type of credentials.- Parameters:
credentials- the credentials to filter.matcher- the matcher to match on.- Returns:
- only those credentials that match the supplied matcher.
-
filter
@NonNull public static <C extends Credentials> Iterable<C> filter(@NonNull Iterable<C> credentials, @NonNull CredentialsMatcher matcher) Filters credentials using the supplied matcher.- Type Parameters:
C- the type of credentials.- Parameters:
credentials- the credentials to filter.matcher- the matcher to match on.- Returns:
- only those credentials that match the supplied matcher.
-
filterKeys
@NonNull public static <C extends Credentials,V> Map<C,V> filterKeys(@NonNull Map<C, V> credentialMap, @NonNull CredentialsMatcher matcher) Filters a map keyed by credentials using the supplied matcher.- Type Parameters:
C- the type of credentials.V- the type of the map values.- Parameters:
credentialMap- the map keyed by credentials to filter.matcher- the matcher to match on.- Returns:
- only those entries with keys that that match the supplied matcher.
-
filterValues
@NonNull public static <C extends Credentials,K> Map<K,C> filterValues(@NonNull Map<K, C> credentialMap, @NonNull CredentialsMatcher matcher) Filters a map based on credential values using the supplied matcher.- Type Parameters:
C- the type of credentials.K- the type of the map keys.- Parameters:
credentialMap- the map with credentials values to filter.matcher- the matcher to match on.- Returns:
- only those entries with keys that that match the supplied matcher.
-
firstOrDefault
@CheckForNull public static <C extends Credentials> C firstOrDefault(@NonNull Iterable<C> credentials, @NonNull CredentialsMatcher matcher, @CheckForNull C defaultIfNone) Returns the first credential from a collection that matches the supplied matcher or if none match then the specified default.- Type Parameters:
C- the type of credential.- Parameters:
credentials- the credentials to select from.matcher- the matcher.defaultIfNone- the default value if no match found.- Returns:
- a matching credential or the supplied default.
-
firstOrNull
@CheckForNull public static <C extends Credentials> C firstOrNull(@NonNull Iterable<C> credentials, @NonNull CredentialsMatcher matcher) Returns the first credential from a collection that matches the supplied matcher ornullif none match.- Type Parameters:
C- the type of credential.- Parameters:
credentials- the credentials to select from.matcher- the matcher.- Returns:
- a matching credential or the supplied default.
-