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 |
---|---|
R |
authenticate(C credentials)
Tries to authenticate the passed credentials and returns an apropriate
result.
|
static <C,R> Authenticator<C,R> |
lambda(Authenticator<C,R> lambda)
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).
Example: Authenticator
<C,R> chained = ((c,r) -> debugAuth(c)).then((c,r) -> authenticate(c));
With this trivial helper method, this is possible: Authenticator
<C,R>
chained = lambda((c,r) -> debugAuth(c)).then((c,r) -> authenticate(c));
|
static <C,R> Authenticator<C,R> |
sequence(Authenticator<? super C,R>... authenticators)
Returns a new
Authenticator instance that wraps a sequence of
passed authenticators. |
default Authenticator<C,R> |
then(Authenticator<C,R> other)
Chains the passed
Authenticator instance to this one to be
evaluated in case the evaluation of this one returns a negative result. |
R authenticate(C credentials) throws AuthenticationFailedException
credentials
- the credentials to be authenticatedAuthenticationFailedException
default Authenticator<C,R> then(Authenticator<C,R> other)
Authenticator
instance 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 (return lambda;
.
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)
Authenticator
instance that wraps a sequence of
passed authenticators. For further details, see
SequenceAuthenticator
.authenticators
- the Authenticator
instances sequence to be wrapped.SequenceAuthenticator
instance.