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 index 0f447c5..245d339 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/apis/AuthApi.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/apis/AuthApi.java @@ -3,14 +3,13 @@ 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; -import java.io.IOException; - @Slf4j @RestController @RequiredArgsConstructor @@ -18,14 +17,15 @@ public class AuthApi { private final AuthService authService; - @GetMapping("/rds/login") - public void signInWithRds(HttpServletRequest request, HttpServletResponse response) throws IOException { + 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 { + public void signInWithRdsCallback(HttpServletRequest request, HttpServletResponse response) + throws IOException { authService.signInWithRdsCallback(request, response); } } diff --git a/skill-tree/src/main/java/com/RDS/skilltree/config/SecurityConfig.java b/skill-tree/src/main/java/com/RDS/skilltree/config/SecurityConfig.java index 072821e..41e4182 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/config/SecurityConfig.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/config/SecurityConfig.java @@ -4,6 +4,8 @@ import com.RDS.skilltree.Authentication.CustomAccessDeniedHandler; import com.RDS.skilltree.User.UserRoleEnum; import com.RDS.skilltree.utils.JWTAuthenticationFilter; +import java.util.Arrays; +import java.util.List; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; @@ -18,9 +20,6 @@ import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import java.util.Arrays; -import java.util.List; - @EnableWebSecurity @Configuration public class SecurityConfig { diff --git a/skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java b/skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java index 751ba2a..f42d241 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java @@ -2,6 +2,7 @@ import com.RDS.skilltree.utils.GenericResponse; import jakarta.validation.ConstraintViolationException; +import java.util.List; import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.websocket.AuthenticationException; import org.springframework.http.HttpStatus; @@ -14,8 +15,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.WebRequest; -import java.util.List; - @Slf4j @ControllerAdvice public class GlobalExceptionHandler { @@ -138,8 +137,10 @@ public ResponseEntity handleForbiddenException(ForbiddenException ex, WebRequ } @ExceptionHandler(InternalServerErrorException.class) - public ResponseEntity handleInternalServerErrorException(InternalServerErrorException ex, WebRequest request) { + public ResponseEntity handleInternalServerErrorException( + InternalServerErrorException ex, WebRequest request) { log.error("Exception - Error : {}", ex.getMessage(), ex); - return new ResponseEntity<>(new GenericResponse<>(null, ex.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>( + new GenericResponse<>(null, ex.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR); } } 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 index 7cd66fb..a7eb773 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/services/AuthService.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/services/AuthService.java @@ -2,11 +2,11 @@ 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; + 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 index faf9672..2b4da80 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/services/AuthServiceImplementation.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/services/AuthServiceImplementation.java @@ -3,13 +3,12 @@ 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; -import java.io.IOException; - @Service @RequiredArgsConstructor public class AuthServiceImplementation implements AuthService { @@ -22,7 +21,8 @@ public class AuthServiceImplementation implements AuthService { private String skilltreeBackendBaseUrl; @Override - public void signInWithRds(HttpServletRequest request, HttpServletResponse response) throws IOException { + public void signInWithRds(HttpServletRequest request, HttpServletResponse response) + throws IOException { String callbackUrl = skilltreeBackendBaseUrl + "/v1/auth/rds/callback"; String redirectUrl = rdsService.signIn(callbackUrl); @@ -30,7 +30,8 @@ public void signInWithRds(HttpServletRequest request, HttpServletResponse respon } @Override - public void signInWithRdsCallback(HttpServletRequest request, HttpServletResponse response) throws IOException { + public void signInWithRdsCallback(HttpServletRequest request, HttpServletResponse response) + throws IOException { String dashboardUrl = skilltreeFrontendBaseUrl + "/dashboard"; String authCookie = request.getHeader(HttpHeaders.COOKIE); 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 d340a8d..bfdaf86 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 @@ -30,17 +30,18 @@ public RdsUserViewModel getUserDetails(String id) { @Override public String signIn(String callbackUrl) { - String url = UriComponentsBuilder - .fromUriString(rdsBackendBaseUrl) - .path("/auth/github/login") - .queryParam("redirectURL", callbackUrl) - .queryParam("v2", true) - .toUriString(); + 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()) { + if (response.getStatusCode().is5xxServerError() + || response.getStatusCode().is4xxClientError()) { throw new InternalServerErrorException("Something went wrong during authentication"); } diff --git a/skill-tree/src/main/java/com/RDS/skilltree/utils/JWTAuthenticationFilter.java b/skill-tree/src/main/java/com/RDS/skilltree/utils/JWTAuthenticationFilter.java index 304d17d..5877a42 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/utils/JWTAuthenticationFilter.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/utils/JWTAuthenticationFilter.java @@ -8,6 +8,7 @@ import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -18,16 +19,13 @@ import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.util.WebUtils; -import java.io.IOException; - @Slf4j public class JWTAuthenticationFilter extends OncePerRequestFilter { @Value("${cookieName}") private String cookieName; - @Autowired - private JWTUtils jwtUtils; + @Autowired private JWTUtils jwtUtils; private static final String BEARER_PREFIX = "Bearer "; @Override