Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
yesyash committed Jul 26, 2024
1 parent e527944 commit fd78cc2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
10 changes: 5 additions & 5 deletions skill-tree/src/main/java/com/RDS/skilltree/apis/AuthApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
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
@RequestMapping("v1/auth")
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,15 +21,17 @@ 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);

response.sendRedirect(redirectUrl);
}

@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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit fd78cc2

Please sign in to comment.