public interface Authenticator<T extends ExecutionContext>
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PASSWORD
This constant is provided an a convenience, to specify a "password" credential in a
Map . |
static java.lang.String |
VERIFICATION_CODE
This constant is provided an a convenience, to specify a "verification code" credential in a
Map . |
Modifier and Type | Method and Description |
---|---|
boolean |
authenticate(T context,
java.lang.String id,
java.util.Map<java.lang.String,java.lang.String> credentials)
Authenticate the user with the given unique id and valid credentials and, if successful, populating the given
ExecutionContext with the user data from the backing data store.
|
default boolean |
authenticate(T context,
java.lang.String id,
java.lang.String password)
Authenticate the user with the given unique id and valid password and, if successful, populating the given
ExecutionContext with the user data from the backing data store.
|
void |
close()
Close the backing database connection.
|
boolean |
credentialsValid(java.lang.String id,
java.util.Map<java.lang.String,java.lang.String> credentials)
Determine whether the given credentials are valid for the user with the specified unique identifier.
|
boolean |
isAuthenticated(java.lang.String id)
Determine whether the user specified by the given unique identifier is authenticated.
|
default boolean |
passwordValid(java.lang.String id,
java.lang.String password)
Determine whether the given password is valid.
|
void |
populate(T context,
java.lang.String id)
Populate the given ExecutionContext with data for the user with the given unique identifier.
|
boolean |
unauthenticate(T context,
java.lang.String id)
Unauthenticate the user with the given unique id, restoring the given context to an unauthenticated state.
|
boolean |
update(T context,
java.lang.String id)
Update the backing data store, for the user with the given id, with data from the given context.
|
boolean |
userExists(java.lang.String id)
Determine whether the user specified by the given unique identifier exists.
|
static final java.lang.String PASSWORD
Map
.static final java.lang.String VERIFICATION_CODE
Map
.boolean isAuthenticated(java.lang.String id) throws AuthenticationException
id
- The unique user identifier.AuthenticationException
- If there is an exception when determining authentication status.boolean userExists(java.lang.String id) throws AuthenticationException
id
- The unique identifier of the user.AuthenticationException
- If there is an exception when determining if the user exists/boolean credentialsValid(java.lang.String id, java.util.Map<java.lang.String,java.lang.String> credentials) throws AuthenticationException
id
- The unique user identifier.credentials
- A map of credentials containing key-value pairs, where the key is the name of
credential and the value is the plaintext credential. Several constants that may be helpful key
choices are provided by this interface.AuthenticationException
- If there is an exception when determining the validity of the credentials.default boolean passwordValid(java.lang.String id, java.lang.String password) throws AuthenticationException
PASSWORD
constant is the key used for storing passwords in the credentials Map.id
- The unique user identifier.password
- The plaintext password.AuthenticationException
- If there is an exception when determining password validity.boolean authenticate(T context, java.lang.String id, java.util.Map<java.lang.String,java.lang.String> credentials) throws AuthenticationException
boolean canLogin =
this.userExists(id) && !this.isAuthenticated(id) && this.credentialsValid(id,credentials);
if (canLogin) {
populate(context, id);
}
return canLogin;
context
- The context to be populated with user data if authentication is successful. This object
should not be modified if the authentication was unsuccessful.id
- The unique user identifier.credentials
- A map of credentials containing key-value pairs, where the key is the name of
credential and the value is the plaintext credential. Several constants that may be helpful key
choices are provided by this interface.context
parameter not be modified.AuthenticationException
- If there is an exception when authenticating the user.default boolean authenticate(T context, java.lang.String id, java.lang.String password) throws AuthenticationException
PASSWORD
constant is the key used for storing passwords in the credentials Map.context
- The context to be populated with user data if authentication is successful. This object
should not be modified if the authentication was unsuccessful.id
- The unique user identifier.password
- The plaintext password.context
parameter not be modified.AuthenticationException
- If there is an exception when authenticating the user.boolean unauthenticate(T context, java.lang.String id) throws AuthenticationException
context
- The context for the user to be unauthenticated; shouldid
- The unique user identifier.AuthenticationException
- If there is an exception during unauthentication.void populate(T context, java.lang.String id) throws AuthenticationException
Note: This method should not attempt any sort of authentication; credentials are not provided, it exists for the sole purpose of retrieving and populating user data. For authentication, use thecredentialsValid(String, Map)
,authenticate(ExecutionContext, String, Map)
, andauthenticate(ExecutionContext, String, String)
methods.
context
- The context to populate with user data.id
- The unique user identifier.AuthenticationException
- If there is an exception when populating the user data.boolean update(T context, java.lang.String id) throws AuthenticationException
context
- The context containing data to be placed in the backing data store.id
- The unique user id.true
If the update was successful and the backing data store was modified.AuthenticationException
- If there is an exception during the update.void close() throws AuthenticationException
AuthenticationException
- If there is an exception when closing the backing database connection.