1 package dst.ass2.service.api.auth;
3 public interface IAuthenticationService {
6 * Attempts to authenticate the user with the given unique email address and the given password in plain text, by
7 * checking the data against the records in the database. If the credentials are successfully authenticated, the
8 * service generates a new authentication token which is stored (with the users email address) in-memory and then
11 * @param email the user email
12 * @param password the password
13 * @return a new authentication token
14 * @throws NoSuchUserException if the given user was not found
15 * @throws AuthenticationException if the credentials could not be authenticated
17 String authenticate(String email, String password) throws NoSuchUserException, AuthenticationException;
20 * Changes the password of the given user in the database. Also updates the in-memory cache in a thread-safe way.
22 * @param email the user email
23 * @param newPassword the new password in plain text.
24 * @throws NoSuchUserException if the given user was not found
26 void changePassword(String email, String newPassword) throws NoSuchUserException;
29 * Returns the user that is associated with this token. Returns null if the token does not exist.
31 * @param token an authentication token previously created via {@link #authenticate(String, String)}
32 * @return the user's email address or null
34 String getUser(String token);
37 * Checks whether the given token is valid (i.e., was issued by this service and has not been invalidated).
39 * @param token the token to validate
40 * @return true if the token is valid, false otherwise
42 boolean isValid(String token);
45 * Invalidates the given token, i.e., removes it from the cache. Returns false if the token did not exist.
47 * @param token the token to invalidate
48 * @return true if the token existed and was successfully invalidated, false otherwise
50 boolean invalidate(String token);