C- the type of the credentials instance to be authenticated.
R- the type of the result/response instance to be returned upon an authentication attempt.
@FunctionalInterface public interface Authenticator<C,R>
Type parameter C (credentials) can for example be
CredentialsUsernamePassword. It could also be a specific type of a
user or subject in order to authenticate already existing user instances.
Type parameter R (result) can be a Boolean for a simple information, if the authentication succeeded or failed. It can also be a concrete user instance in case a successful authentication has to create the user instance itself.
|Modifier and Type||Method and Description|
Tries to authenticate the passed credentials and returns an apropriate result.
Trivial helper method to compensate for the Java 8 lambda extension loophole that a lambda expression cannot be recognized without a target (variable declaration or method call).
With this trivial helper method, this is possible:
Returns a new
Chains the passed
R authenticate(C credentials) throws AuthenticationFailedException
credentials- the credentials to be authenticated
default Authenticator<C,R> then(Authenticator<C,R> other)
Authenticatorinstance to this one to be evaluated in case the evaluation of this one returns a negative result.
Note that multiple authenticators can be chained in sequence
other- the authenticator instance to be chained.
static <C,R> Authenticator<C,R> lambda(Authenticator<C,R> lambda)
Authenticator <C,R> chained = ((c,r) -> debugAuth(c)).then((c,r) -> authenticate(c));
Authenticator <C,R> chained = lambda((c,r) -> debugAuth(c)).then((c,r) -> authenticate(c));
Trivially always returns the passed instance (
Note that trivial static methods like this get eliminated (inlined) by the JIT compiler at runtime, so this convenience method does NOT come with a performance penalty.
lambda- the lambda instance to make recognizable to the compiler.
@SafeVarargs static <C,R> Authenticator<C,R> sequence(Authenticator<? super C,R>... authenticators)
Authenticatorinstance that wraps a sequence of passed authenticators. For further details, see