diff options
author | Tyler Ferrari <69283684+Sowgro@users.noreply.github.com> | 2025-03-17 16:44:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-17 16:44:16 -0400 |
commit | ed3d0e5e5f9c58c3926ea55a422212f4da1c8849 (patch) | |
tree | a33f760bb831c948ebf1844ca52d7625ca7f6fe7 /ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java | |
parent | 9baaa0590fbc38c06d530786a1de804ee9edd7db (diff) | |
parent | 0377515c685b3ced5f67ae6d2ffee22893943acb (diff) | |
download | JellySolutions-ed3d0e5e5f9c58c3926ea55a422212f4da1c8849.tar.gz JellySolutions-ed3d0e5e5f9c58c3926ea55a422212f4da1c8849.tar.bz2 JellySolutions-ed3d0e5e5f9c58c3926ea55a422212f4da1c8849.zip |
Merge pull request #9 from RIT-SWEN-261-02/service-tests
service-tests merge
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.java | 13 |
1 files changed, 10 insertions, 3 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 591d891..5a1a492 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 @@ -1,5 +1,6 @@ package com.ufund.api.ufundapi.service; +import com.ufund.api.ufundapi.model.User; import com.ufund.api.ufundapi.model.UserAuth; import com.ufund.api.ufundapi.persistence.UserAuthDAO; import org.springframework.stereotype.Component; @@ -20,13 +21,19 @@ public class AuthService { /** * Check if the provided key has access to the provided user. * - * @param username The username of the user trying to be accessed. + * @param targetUsername The targetUsername 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, IOException { + public void authenticate(String targetUsername, String key) throws IllegalAccessException, IOException { var userAuth = userAuthDAO.getUserAuth(key); - if (userAuth == null || !userAuth.getUsername().equals(username)) { + if (userAuth == null) { + throw new IllegalAccessException("Unauthenticated"); + } + + var username = userAuth.getUsername(); + var userType = userService.getUser(username).getType(); + if (!username.equals(targetUsername) && userType != User.UserType.MANAGER) { throw new IllegalAccessException("Unauthorized"); } } |