]> git.somenet.org - pub/jan/dst18.git/blob - ass2-service/api/src/main/java/dst/ass2/service/api/auth/IAuthenticationService.java
Add template for assignment 2
[pub/jan/dst18.git] / ass2-service / api / src / main / java / dst / ass2 / service / api / auth / IAuthenticationService.java
1 package dst.ass2.service.api.auth;
2
3 public interface IAuthenticationService {
4
5     /**
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
9      * returned.
10      *
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
16      */
17     String authenticate(String email, String password) throws NoSuchUserException, AuthenticationException;
18
19     /**
20      * Changes the password of the given user in the database. Also updates the in-memory cache in a thread-safe way.
21      *
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
25      */
26     void changePassword(String email, String newPassword) throws NoSuchUserException;
27
28     /**
29      * Returns the user that is associated with this token. Returns null if the token does not exist.
30      *
31      * @param token an authentication token previously created via {@link #authenticate(String, String)}
32      * @return the user's email address or null
33      */
34     String getUser(String token);
35
36     /**
37      * Checks whether the given token is valid (i.e., was issued by this service and has not been invalidated).
38      *
39      * @param token the token to validate
40      * @return true if the token is valid, false otherwise
41      */
42     boolean isValid(String token);
43
44     /**
45      * Invalidates the given token, i.e., removes it from the cache. Returns false if the token did not exist.
46      *
47      * @param token the token to invalidate
48      * @return true if the token existed and was successfully invalidated, false otherwise
49      */
50     boolean invalidate(String token);
51
52 }