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 CredentialsMatcher
allOf
(CredentialsMatcher... matchers) Creates a matcher that matches when all of the supplied matchers match.static CredentialsMatcher
always()
Creates a matcher that always matches.static CredentialsMatcher
anyOf
(CredentialsMatcher... matchers) Creates a matcher that matches when any of the supplied matchers match.static CredentialsMatcher
both
(CredentialsMatcher matcher1, CredentialsMatcher matcher2) Creates a matcher that matches when both of the supplied matchers match.static String
describe
(CredentialsMatcher matcher) Attempts to describe the suppliedCredentialsMatcher
in terms of a Credentials Query Language.static CredentialsMatcher
either
(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 ornull
if none match.static CredentialsMatcher
instanceOf
(Class clazz) Creates a matcher that matches credentials of the specified type.static CredentialsMatcher
never()
Creates a matcher that never matches.static CredentialsMatcher
noneOf
(CredentialsMatcher... matchers) Creates a matcher that matches when none of the supplied matchers match.static CredentialsMatcher
not
(CredentialsMatcher matcher) Creates a matcher that inverts the supplied matcher.static CredentialsMatcher
Attempts to parse a Credentials Query Language expression and construct the corresponding matcher.static CredentialsMatcher
Creates a matcher that matchesIdCredentials
with the suppliedIdCredentials.getId()
static <T extends Serializable>
CredentialsMatcherwithProperty
(String name, T expected) Creates a matcher that matches a named Java Bean property against the supplied expected value.static CredentialsMatcher
withScope
(CredentialsScope scope) Creates a matcher that matchesCredentials
with the suppliedCredentialsScope
.static CredentialsMatcher
withScopes
(CredentialsScope... scopes) Creates a matcher that matchesCredentials
with the suppliedCredentialsScope
.static CredentialsMatcher
withScopes
(Collection<CredentialsScope> scopes) Creates a matcher that matchesCredentials
with the suppliedCredentialsScope
.static CredentialsMatcher
withUsername
(String username) Creates a matcher that matchesUsernameCredentials
with 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 matchesIdCredentials
with the suppliedIdCredentials.getId()
- Parameters:
id
- theIdCredentials.getId()
to match.- Returns:
- a matcher that matches
IdCredentials
with the suppliedIdCredentials.getId()
-
withScope
Creates a matcher that matchesCredentials
with the suppliedCredentialsScope
.- Parameters:
scope
- theCredentialsScope
to match.- Returns:
- a matcher that matches
Credentials
with the suppliedCredentialsScope
.
-
withScopes
Creates a matcher that matchesCredentials
with the suppliedCredentialsScope
.- Parameters:
scopes
- theCredentialsScope
s to match.- Returns:
- a matcher that matches
Credentials
with the suppliedCredentialsScope
s.
-
withScopes
Creates a matcher that matchesCredentials
with the suppliedCredentialsScope
.- Parameters:
scopes
- theCredentialsScope
s to match.- Returns:
- a matcher that matches
Credentials
with the suppliedCredentialsScope
s.
-
withUsername
Creates a matcher that matchesUsernameCredentials
with the suppliedUsernameCredentials.getUsername()
- Parameters:
username
- theUsernameCredentials.getUsername()
to match.- Returns:
- a matcher that matches
UsernameCredentials
with the suppliedUsernameCredentials.getUsername()
-
withProperty
public static <T extends Serializable> CredentialsMatcher withProperty(@NonNull String name, @CheckForNull T expected) Creates a matcher that matches a named Java Bean property against the supplied expected value.- Type Parameters:
T
- the type of expected value.- Parameters:
name
- the name of the property to match.expected
- the expected value of the property.- Returns:
- a matcher that matches a named Java Bean property against the supplied expected value.
- Since:
- 2.1.0
-
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:
K
- the type of the map keys.C
- the type of credentials.- 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 ornull
if 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.
-
describe
Attempts to describe the suppliedCredentialsMatcher
in terms of a Credentials Query Language. The basic form of the query language should follow Java expression syntax assuming that there is one variable in scope, namely the credential. The Java Bean style properties will be exposed as variables in the context. Example:(instanceof com.cloudbees.plugins.credentials.common.UsernameCredentials) && !(username == "bob")
will match all instances ofUsernameCredentials
withUsernameCredentials.getUsername()
not equal to bob. See alsoCQLParser
.- Parameters:
matcher
- theCredentialsMatcher
to describe.- Returns:
- the CQL description or
null
if theCredentialsMatcher
cannot be mapped to CQL. - Since:
- 2.1.0
-
parse
Attempts to parse a Credentials Query Language expression and construct the corresponding matcher.- Parameters:
cql
- the Credentials Query Language expression to parse.- Returns:
- a
CredentialsMatcher
for this expression. - Throws:
CQLSyntaxException
- if the expression could not be parsed.- Since:
- 2.1.0
-