diff --git a/src/main/java/com/dnd/gooding/global/config/security/SecurityConfiguration.java b/src/main/java/com/dnd/gooding/global/config/security/SecurityConfiguration.java index 86d8b3b..0f89b3e 100644 --- a/src/main/java/com/dnd/gooding/global/config/security/SecurityConfiguration.java +++ b/src/main/java/com/dnd/gooding/global/config/security/SecurityConfiguration.java @@ -39,7 +39,8 @@ public WebSecurityCustomizer webSecurityCustomizer() { "/static/css/**", "/static/scss/**", "/swagger-ui/**", - "/swagger-resources/**"); + "/swagger-resources/**", + "/v3/api-docs/**"); } @Bean @@ -51,6 +52,7 @@ public SecurityFilterChain httpSecurity(HttpSecurity http) throws Exception { .authorizeHttpRequests() .antMatchers("/").permitAll() .antMatchers("/health-check").permitAll() + .antMatchers("/docs").permitAll() .antMatchers("/api/v1/tokens/temp").permitAll() .anyRequest().authenticated() .and() diff --git a/src/main/java/com/dnd/gooding/global/controller/HealthCheckController.java b/src/main/java/com/dnd/gooding/global/controller/HealthCheckController.java index a8c4d53..0cecdf3 100644 --- a/src/main/java/com/dnd/gooding/global/controller/HealthCheckController.java +++ b/src/main/java/com/dnd/gooding/global/controller/HealthCheckController.java @@ -1,13 +1,18 @@ package com.dnd.gooding.global.controller; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HealthCheckController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + @GetMapping("/health-check") public String healthCheck() { + logger.info("[HealthCheckController] health-check"); return "health-check"; } } diff --git a/src/main/java/com/dnd/gooding/global/controller/SwaggerController.java b/src/main/java/com/dnd/gooding/global/controller/SwaggerController.java new file mode 100644 index 0000000..1c07312 --- /dev/null +++ b/src/main/java/com/dnd/gooding/global/controller/SwaggerController.java @@ -0,0 +1,18 @@ +package com.dnd.gooding.global.controller; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class SwaggerController { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @GetMapping("/docs") + public String docs() { + logger.info("[SwaggerController] docs"); + return "redirect:swagger-ui/index.html"; + } +} diff --git a/src/main/java/com/dnd/gooding/global/oauth/handler/CustomOAuth2FailureHandler.java b/src/main/java/com/dnd/gooding/global/oauth/handler/CustomOAuth2FailureHandler.java index eb77238..f2c4c6b 100644 --- a/src/main/java/com/dnd/gooding/global/oauth/handler/CustomOAuth2FailureHandler.java +++ b/src/main/java/com/dnd/gooding/global/oauth/handler/CustomOAuth2FailureHandler.java @@ -10,6 +10,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; import org.springframework.stereotype.Component; @@ -24,6 +26,7 @@ @RequiredArgsConstructor public class CustomOAuth2FailureHandler extends SimpleUrlAuthenticationFailureHandler { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private static final String DEFAULT_TARGET_URL = "/"; private final HttpCookieOAuthAuthorizationRequestRepository httpCookieOAuthAuthorizationRequestRepository; @@ -38,12 +41,14 @@ public void onAuthenticationFailure( .map(cookie -> URLDecoder.decode(cookie, UTF_8)) .orElse(DEFAULT_TARGET_URL); + logger.info("[CustomOAuth2FailureHandler] onAuthenticationFailure redirectUrl : " + redirectUrl); String targetUrl = UriComponentsBuilder.fromUriString(redirectUrl) .queryParam("error", specialCharactersRemove(exception.getMessage())) .build().toUriString(); httpCookieOAuthAuthorizationRequestRepository.removeAuthorizationRequestCookies(request, response); + logger.info("[CustomOAuth2FailureHandler] onAuthenticationFailure targetUrl : " + targetUrl); getRedirectStrategy().sendRedirect(request, response, targetUrl); } diff --git a/src/main/java/com/dnd/gooding/global/oauth/handler/CustomOAuth2SuccessHandler.java b/src/main/java/com/dnd/gooding/global/oauth/handler/CustomOAuth2SuccessHandler.java index 9c57b40..d2a13b6 100644 --- a/src/main/java/com/dnd/gooding/global/oauth/handler/CustomOAuth2SuccessHandler.java +++ b/src/main/java/com/dnd/gooding/global/oauth/handler/CustomOAuth2SuccessHandler.java @@ -13,6 +13,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.ResponseCookie; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; @@ -33,6 +35,7 @@ @RequiredArgsConstructor public class CustomOAuth2SuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final TokenService tokenService; @Override @@ -44,8 +47,10 @@ public void onAuthenticationSuccess( Tokens tokens = tokenService.createTokens(customOAuth2User.getUserInfo()); String targetUrl = determineTargetUrl(request, tokens.accessToken()); setRefreshTokenInCookie(response, tokens.refreshToken()); + logger.info("[CustomOAuth2SuccessHandler] onAuthenticationSuccess targetUrl : " + targetUrl); getRedirectStrategy().sendRedirect(request, response, targetUrl); } else { + logger.info("[CustomOAuth2SuccessHandler] onAuthenticationSuccess authentication : " + authentication); super.onAuthenticationSuccess(request, response, authentication); } } @@ -57,7 +62,7 @@ private String determineTargetUrl(HttpServletRequest request, String accessToken .map(cookie -> URLDecoder.decode(cookie, UTF_8)) .map(this::encodeKoreanCharacters) .orElse(getDefaultTargetUrl()); - + logger.info("[CustomOAuth2SuccessHandler] determineTargetUrl targetUrl : " + targetUrl); return UriComponentsBuilder.fromUriString(targetUrl) .queryParam("accessToken", accessToken) .build().toUriString(); diff --git a/src/main/java/com/dnd/gooding/global/token/api/TokenController.java b/src/main/java/com/dnd/gooding/global/token/api/TokenController.java index c2ea96c..78bde7a 100644 --- a/src/main/java/com/dnd/gooding/global/token/api/TokenController.java +++ b/src/main/java/com/dnd/gooding/global/token/api/TokenController.java @@ -2,6 +2,8 @@ import static org.springframework.http.HttpHeaders.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; import org.springframework.http.ResponseCookie; import org.springframework.http.ResponseEntity; @@ -24,13 +26,16 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirements; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Tag(name = "Token", description = "토큰 API") @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/tokens") public class TokenController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final TokenService tokenService; @Operation(summary = "임시 토큰을 발급 받는다.") @@ -38,6 +43,7 @@ public class TokenController { @GetMapping(value = "temp", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity tempAccessToken() { String tempAccessToken = tokenService.createAccessToken(1L, "ROLE_USER"); + logger.info("[TokenController] tempAccessToken : " + tempAccessToken); return ResponseEntity .ok() .body(new TokenResponse(tempAccessToken)); diff --git a/src/main/java/com/dnd/gooding/global/token/filter/JwtAuthenticationFilter.java b/src/main/java/com/dnd/gooding/global/token/filter/JwtAuthenticationFilter.java index c6a1476..8c98f98 100644 --- a/src/main/java/com/dnd/gooding/global/token/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/dnd/gooding/global/token/filter/JwtAuthenticationFilter.java @@ -7,6 +7,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; @@ -23,6 +25,7 @@ @RequiredArgsConstructor public class JwtAuthenticationFilter extends OncePerRequestFilter { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final TokenService tokenService; @Override @@ -35,7 +38,7 @@ public void doFilterInternal(HttpServletRequest request, HttpServletResponse res JwtAuthenticationToken authentication = tokenService.getAuthenticationByAccessToken(accessToken); SecurityContextHolder.getContext().setAuthentication(authentication); } - + logger.info("[JwtAuthenticationFilter] accessToken : " + accessToken); filterChain.doFilter(request, response); } diff --git a/src/main/java/com/dnd/gooding/global/util/CookieUtil.java b/src/main/java/com/dnd/gooding/global/util/CookieUtil.java index 1dc5396..2c3c5d9 100644 --- a/src/main/java/com/dnd/gooding/global/util/CookieUtil.java +++ b/src/main/java/com/dnd/gooding/global/util/CookieUtil.java @@ -10,6 +10,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.ResponseCookie; import org.springframework.util.SerializationUtils; @@ -18,6 +20,8 @@ @NoArgsConstructor(access = PRIVATE) public class CookieUtil { + private static final Logger logger = LoggerFactory.getLogger(CookieUtil.class); + public static Optional getCookie(HttpServletRequest request, String name) { Cookie[] cookies = request.getCookies(); @@ -28,6 +32,7 @@ public static Optional getCookie(HttpServletRequest request, String name .findFirst(); } + logger.info("[CookieUtil] getCookie cookies : " + cookies); return Optional.empty(); }