aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-03-06 21:41:39 -0500
committersowgro <tpoke.ferrari@gmail.com>2025-03-06 21:41:39 -0500
commitbb9ce55cb5b55a6aaed2399e39a01d68f2491ce3 (patch)
tree7df43079fa8d3e5c7b34c5ab13389018c1216078 /ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java
parenteb4edcc7e7e4f9a6a59bed6d3952486f179fc445 (diff)
downloadJellySolutions-bb9ce55cb5b55a6aaed2399e39a01d68f2491ce3.tar.gz
JellySolutions-bb9ce55cb5b55a6aaed2399e39a01d68f2491ce3.tar.bz2
JellySolutions-bb9ce55cb5b55a6aaed2399e39a01d68f2491ce3.zip
Push current changes (working on documentation and tests)
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java32
1 files changed, 27 insertions, 5 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java
index 2e644ee..ac86ff1 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java
@@ -17,17 +17,29 @@ public class AuthService {
this.userService = userService;
}
- public UserAuth getUserAuth(String key) {
- return userAuthDAO.getUserAuth(key);
- }
-
+ /**
+ * Check if the provided key has access to the provided user.
+ *
+ * @param username The username of the user trying to be accessed.
+ * @param key The api key obtained by the client from logging in.
+ * @throws IllegalAccessException Thrown if access was denied to the user.
+ */
public void authenticate(String username, String key) throws IllegalAccessException {
- var userAuth = getUserAuth(key);
+ var userAuth = userAuthDAO.getUserAuth(key);
if (userAuth == null || !userAuth.getUsername().equals(username)) {
throw new IllegalAccessException("Unauthorized");
}
}
+ /**
+ * Attempt to log in with the provided credentials
+ *
+ * @param username The username of the user
+ * @param password The password of the user
+ * @return An API key if the authentication was successful.
+ * @throws IllegalAccessException Thrown if the username or password was incorrect
+ * @throws IOException If there was an issue saving the authentication
+ */
public String login(String username, String password) throws IllegalAccessException, IOException {
var usr = userService.getUser(username);
if (usr == null || !usr.verifyPassword(password)) {
@@ -38,4 +50,14 @@ public class AuthService {
return userAuth.getKey();
}
+ /**
+ * Logs out the current user
+ *
+ * @param key The API key to of the client
+ * @throws IOException Thrown if there was an error saving the authentication
+ */
+ public void logout(String key) throws IOException {
+ userAuthDAO.removeUserAuth(key);
+ }
+
}