Class AbstractPrincipalAuthenticator<A extends PrincipalCredentials,B extends Credentials,C extends PrincipalAuthentication>
- Type Parameters:
A
- the type of principal credentials to authenticateB
- the type of credentials resolved by the credentials resolverC
- the type of authentication
- All Implemented Interfaces:
Authenticator<A,
C>
- Direct Known Subclasses:
PrincipalAuthenticator
,UserAuthenticator
Base principal authenticator implementation used to authenticate PrincipalCredentials
.
This implementation relies on a CredentialsResolver
to resolve trusted credentials from a trusted source (i.e. a trusted repository, a trusted directory service...) and a
CredentialsMatcher
to match the provided credentials with the resolved trusted credentials.
Implementators must implement the createAuthenticated(io.inverno.mod.security.authentication.Credentials)
and
createDenied(io.inverno.mod.security.authentication.PrincipalCredentials, io.inverno.mod.security.authentication.AuthenticationException)
methods which creates the resulting
authentication in case of successful or failed authentication.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Field Summary
Modifier and TypeFieldDescriptionprotected final CredentialsMatcher
<? super A, ? super B> The credentials matcher.protected final CredentialsResolver
<? extends B> The credentials resolver. -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractPrincipalAuthenticator
(CredentialsResolver<? extends B> credentialsResolver, CredentialsMatcher<? super A, ? super B> credentialsMatcher) Creates a terminal principal authenticator with the specified credentials resolver and credentials matcher. -
Method Summary
Modifier and TypeMethodDescriptionauthenticate
(A credentials) Authenticates the specified credentials and returns an authentication.protected abstract C
createAuthenticated
(B resolvedCredentials) Creates an authenticated authentication resulting from a successful authentication using the resolved trusted credentials.protected abstract C
createDenied
(A credentials, AuthenticationException cause) Creates a denied authentication resulting from a failed authentication.void
setTerminal
(boolean terminal) Sets whether the authenticator is terminal and should return denied authentication on failed authentication or no authentication to indicate it was not able to authenticate credentials.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.inverno.mod.security.authentication.Authenticator
failOnDenied, failOnDeniedAndAnonymous, flatMap, map, or
-
Field Details
-
credentialsResolver
The credentials resolver. -
credentialsMatcher
protected final CredentialsMatcher<? super A extends PrincipalCredentials,? super B extends Credentials> credentialsMatcherThe credentials matcher.
-
-
Constructor Details
-
AbstractPrincipalAuthenticator
protected AbstractPrincipalAuthenticator(CredentialsResolver<? extends B> credentialsResolver, CredentialsMatcher<? super A, ? super B> credentialsMatcher) Creates a terminal principal authenticator with the specified credentials resolver and credentials matcher.
The resulting authenticator is terminal and returns denied authentication when the credentials resolver returns no matching credentials corresponding to the credentials to authenticate or when they do not match.
- Parameters:
credentialsResolver
- a credentials resolvercredentialsMatcher
- a credentials matcher
-
-
Method Details
-
setTerminal
public void setTerminal(boolean terminal) Sets whether the authenticator is terminal and should return denied authentication on failed authentication or no authentication to indicate it was not able to authenticate credentials.
- Parameters:
terminal
- true to terminate authentication, false otherwise
-
authenticate
Description copied from interface:Authenticator
Authenticates the specified credentials and returns an authentication.
Implementations can return an empty mono to indicate that they were unable to authenticate the credentials. This does not mean credentials are invalid, this simply mean that a particular authenticator does not manage them and therefore can's possibly determine whether they are valid. For example, when considering login credentials composed of a user and a password, an authenticator which does not manage that particular user can return an empty mono.
Implementations must return denied authentications with
AuthenticationException
when they were able to authenticate credentials which turned out to be invalid. For example, a login credentials authenticator must return a denied authentication exception when it does manage a particular username but the provided password was invalid.A denied authentication can also bre reported by throwing an
AuthenticationException
when returning an actual authentication instance is not practical.- Specified by:
authenticate
in interfaceAuthenticator<A extends PrincipalCredentials,
B extends Credentials> - Parameters:
credentials
- the credentials to authenticate- Returns:
- a mono emitting an authentication, an error mono or an empty mono if the authenticator could not authenticate the credentials
-
createAuthenticated
Creates an authenticated authentication resulting from a successful authentication using the resolved trusted credentials.
- Parameters:
resolvedCredentials
- the resolved trusted credentials- Returns:
- an authenticated authentication
- Throws:
AuthenticationException
- if there was an error generating the authentication
-
createDenied
protected abstract C createDenied(A credentials, AuthenticationException cause) throws AuthenticationException Creates a denied authentication resulting from a failed authentication.
- Parameters:
credentials
- the invalid credentialscause
- the authentication error- Returns:
- a denied authentication
- Throws:
AuthenticationException
- if there was an error generating the authentication
-