diff --git a/skill-tree/src/main/java/com/RDS/skilltree/apis/AuthApi.java b/skill-tree/src/main/java/com/RDS/skilltree/apis/AuthApi.java deleted file mode 100644 index 245d339..0000000 --- a/skill-tree/src/main/java/com/RDS/skilltree/apis/AuthApi.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.RDS.skilltree.apis; - -import com.RDS.skilltree.services.AuthService; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@Slf4j -@RestController -@RequiredArgsConstructor -@RequestMapping("v1/auth") -public class AuthApi { - private final AuthService authService; - - @GetMapping("/rds/login") - public void signInWithRds(HttpServletRequest request, HttpServletResponse response) - throws IOException { - authService.signInWithRds(request, response); - } - - @GetMapping("/rds/callback") - public void signInWithRdsCallback(HttpServletRequest request, HttpServletResponse response) - throws IOException { - authService.signInWithRdsCallback(request, response); - } -} diff --git a/skill-tree/src/main/java/com/RDS/skilltree/services/AuthService.java b/skill-tree/src/main/java/com/RDS/skilltree/services/AuthService.java deleted file mode 100644 index a7eb773..0000000 --- a/skill-tree/src/main/java/com/RDS/skilltree/services/AuthService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.RDS.skilltree.services; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; - -public interface AuthService { - void signInWithRds(HttpServletRequest request, HttpServletResponse response) throws IOException; - - void signInWithRdsCallback(HttpServletRequest request, HttpServletResponse response) - throws IOException; -} diff --git a/skill-tree/src/main/java/com/RDS/skilltree/services/AuthServiceImplementation.java b/skill-tree/src/main/java/com/RDS/skilltree/services/AuthServiceImplementation.java deleted file mode 100644 index 2b4da80..0000000 --- a/skill-tree/src/main/java/com/RDS/skilltree/services/AuthServiceImplementation.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.RDS.skilltree.services; - -import com.RDS.skilltree.services.external.RdsService; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpHeaders; -import org.springframework.stereotype.Service; - -@Service -@RequiredArgsConstructor -public class AuthServiceImplementation implements AuthService { - private final RdsService rdsService; - - @Value("${skilltree.frontendBaseUrl}") - private String skilltreeFrontendBaseUrl; - - @Value("${skilltree.backendBaseUrl}") - private String skilltreeBackendBaseUrl; - - @Override - public void signInWithRds(HttpServletRequest request, HttpServletResponse response) - throws IOException { - String callbackUrl = skilltreeBackendBaseUrl + "/v1/auth/rds/callback"; - String redirectUrl = rdsService.signIn(callbackUrl); - - response.sendRedirect(redirectUrl); - } - - @Override - public void signInWithRdsCallback(HttpServletRequest request, HttpServletResponse response) - throws IOException { - String dashboardUrl = skilltreeFrontendBaseUrl + "/dashboard"; - String authCookie = request.getHeader(HttpHeaders.COOKIE); - - response.addHeader(HttpHeaders.SET_COOKIE, authCookie); - response.sendRedirect(dashboardUrl); - } -} diff --git a/skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java b/skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java index 6215e2d..3c7d02a 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java @@ -131,8 +131,8 @@ public EndorsementViewModel update(Integer endorsementId, UpdateEndorsementViewM Optional exitingEndorsement = endorsementRepository.findById(endorsementId); if (exitingEndorsement.isEmpty()) { - throw new EndorsementNotFoundException( - String.format("Endorsement with id: %s not found", endorsementId)); + log.error(String.format("Endorsement with id: %s not found", endorsementId)); + throw new EndorsementNotFoundException("Endorsement not found"); } Endorsement endorsement = exitingEndorsement.get(); diff --git a/skill-tree/src/main/java/com/RDS/skilltree/services/external/RdsService.java b/skill-tree/src/main/java/com/RDS/skilltree/services/external/RdsService.java index c136fb1..191b4eb 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/services/external/RdsService.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/services/external/RdsService.java @@ -4,6 +4,4 @@ public interface RdsService { RdsGetUserDetailsResDto getUserDetails(String id); - - String signIn(String callbackUrl); } diff --git a/skill-tree/src/main/java/com/RDS/skilltree/services/external/RdsServiceImplementation.java b/skill-tree/src/main/java/com/RDS/skilltree/services/external/RdsServiceImplementation.java index 93b34bc..8bbb98d 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/services/external/RdsServiceImplementation.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/services/external/RdsServiceImplementation.java @@ -1,18 +1,14 @@ package com.RDS.skilltree.services.external; import com.RDS.skilltree.dtos.RdsGetUserDetailsResDto; -import com.RDS.skilltree.exceptions.InternalServerErrorException; import com.RDS.skilltree.exceptions.UserNotFoundException; import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpHeaders; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; @Service @RequiredArgsConstructor @@ -33,28 +29,4 @@ public RdsGetUserDetailsResDto getUserDetails(String id) { throw new UserNotFoundException("Error getting user details"); } } - - @Override - public String signIn(String callbackUrl) { - String url = - UriComponentsBuilder.fromUriString(rdsBackendBaseUrl) - .path("/auth/github/login") - .queryParam("redirectURL", callbackUrl) - .queryParam("v2", true) - .toUriString(); - - try { - ResponseEntity response = restTemplate.getForEntity(url, String.class); - - if (response.getStatusCode().is5xxServerError() - || response.getStatusCode().is4xxClientError()) { - throw new InternalServerErrorException("Something went wrong during authentication"); - } - - return response.getHeaders().getFirst(HttpHeaders.LOCATION); - } catch (RestClientException error) { - log.error("Error calling url: {}, Error : {}", url, error.getMessage()); - throw new RuntimeException("Failed to communicate with RDS backend"); - } - } }