From 8e7f823b52c622f87a75e2915ac5151116e7b4f5 Mon Sep 17 00:00:00 2001 From: aesperer Date: Thu, 8 Aug 2024 18:39:34 +0900 Subject: [PATCH 1/9] update :: http logging body substring 55 --- src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt | 8 +++++--- .../selfstudy/service/impl/GetSelfStudyInfoServiceImpl.kt | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt b/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt index d492f8fa..abca7568 100644 --- a/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt +++ b/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt @@ -47,24 +47,26 @@ class HttpLoggingAspect { val headerName = headerNames.nextElement() headerSet.add(headerName) } + val code = UUID.randomUUID() log.info( "At {}#{} [Request:{}] IP: {}, Session-ID: {}, URI: {}, Params: {}, Content-Type: {}, User-Agent: {}, Headers: {}, Parameters: {}, Code: {}", - className,methodName,method,ip,sessionId,uri,params,contentType,userAgent,headerSet,params(proceedingJoinPoint),code + className, methodName, method, ip, sessionId, uri, params, contentType, userAgent, headerSet, params(proceedingJoinPoint), code ) val result = proceedingJoinPoint.proceed() when (result) { is ResponseEntity<*> -> { + val body = result.body.toString().substring(0, 55) log.info( "At {}#{} [Response:{}] IP: {}, Session-ID: {}, Headers: {}, Response: {}, Status-Code: {}, Code: {}", - className,methodName,method,ip,sessionId,result.headers,result.body,result.statusCode,code + className,methodName,method,ip,sessionId,result.headers,body,result.statusCode,code ) } null -> { log.info( "At {}#{} [Response: null] IP: {}, Session-ID: {}, Code: {}", - className,methodName,ip,sessionId,code + className, methodName, ip, sessionId, code ) } diff --git a/src/main/kotlin/com/dotori/v2/domain/selfstudy/service/impl/GetSelfStudyInfoServiceImpl.kt b/src/main/kotlin/com/dotori/v2/domain/selfstudy/service/impl/GetSelfStudyInfoServiceImpl.kt index 8d1714cb..50aa3f4c 100644 --- a/src/main/kotlin/com/dotori/v2/domain/selfstudy/service/impl/GetSelfStudyInfoServiceImpl.kt +++ b/src/main/kotlin/com/dotori/v2/domain/selfstudy/service/impl/GetSelfStudyInfoServiceImpl.kt @@ -17,6 +17,7 @@ class GetSelfStudyInfoServiceImpl( private val validDayOfWeekAndHourUtil: ValidDayOfWeekAndHourUtil, private val userUtil: UserUtil ) : GetSelfStudyInfoService { + override fun execute(): SelfStudyInfoResDto { val selfStudyCount = selfStudyCountRepository.findSelfStudyCountById(1) val member = userUtil.fetchCurrentUser() From ff1f0ed252bc0a3dcd7cea94c283a098e6d65740 Mon Sep 17 00:00:00 2001 From: aesperer Date: Thu, 8 Aug 2024 18:40:49 +0900 Subject: [PATCH 2/9] chore :: health check --- .../kotlin/com/dotori/v2/domain/health/HealthCheckController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/dotori/v2/domain/health/HealthCheckController.kt b/src/main/kotlin/com/dotori/v2/domain/health/HealthCheckController.kt index 41eeb7d0..57bbf086 100644 --- a/src/main/kotlin/com/dotori/v2/domain/health/HealthCheckController.kt +++ b/src/main/kotlin/com/dotori/v2/domain/health/HealthCheckController.kt @@ -8,6 +8,6 @@ import org.springframework.web.bind.annotation.RestController class HealthCheckController { @GetMapping - fun healthCheck() = ResponseEntity.ok("Dotori-V2 Server running") + fun healthCheck() = ResponseEntity.ok("Dotori Server running") } \ No newline at end of file From 778012c2cbea606cd52d382d74f28626e90e3cf4 Mon Sep 17 00:00:00 2001 From: aesperer Date: Thu, 8 Aug 2024 18:50:06 +0900 Subject: [PATCH 3/9] =?UTF-8?q?update=20::=20filter=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt | 3 +-- .../kotlin/com/dotori/v2/global/security/SecurityConfig.kt | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt b/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt index abca7568..932ca6e2 100644 --- a/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt +++ b/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt @@ -23,8 +23,7 @@ class HttpLoggingAspect { private val log = LoggerFactory.getLogger(this.javaClass.name) @Pointcut("within(@org.springframework.web.bind.annotation.RestController *)") - fun onRequest() { - } + fun onRequest() {} @Around("onRequest()") @Throws(Throwable::class) diff --git a/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt b/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt index 42f537ff..895a6042 100644 --- a/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt +++ b/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt @@ -69,8 +69,8 @@ class SecurityConfig( .accessDeniedHandler(CustomAccessDeniedHandler()) .authenticationEntryPoint(CustomAuthenticationEntryPointHandler()) .and() - .addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter::class.java) - .addFilterBefore(errorFilter, JwtReqFilter::class.java) + .addFilterBefore(jwtRequestFilter, JwtReqFilter::class.java) + .addFilterBefore(errorFilter, ErrorFilter::class.java) return http.build() } From b10e2323631595efd0b1bfd32002deaabb077ef0 Mon Sep 17 00:00:00 2001 From: aesperer Date: Thu, 8 Aug 2024 18:50:36 +0900 Subject: [PATCH 4/9] update :: loggin space --- src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt b/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt index 932ca6e2..4ccc9456 100644 --- a/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt +++ b/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt @@ -58,7 +58,7 @@ class HttpLoggingAspect { val body = result.body.toString().substring(0, 55) log.info( "At {}#{} [Response:{}] IP: {}, Session-ID: {}, Headers: {}, Response: {}, Status-Code: {}, Code: {}", - className,methodName,method,ip,sessionId,result.headers,body,result.statusCode,code + className, methodName, method, ip, sessionId, result.headers, body, result.statusCode, code ) } From 4053904c5ffd75fdb8e3baab49bd840e75b761df Mon Sep 17 00:00:00 2001 From: aesperer Date: Thu, 8 Aug 2024 19:13:00 +0900 Subject: [PATCH 5/9] delte :: jwt, error filter component @ --- .../com/dotori/v2/global/error/ErrorFilter.kt | 2 - .../v2/global/security/SecurityConfig.kt | 4 +- .../global/security/jwt/JwtExceptionFilter.kt | 50 ------------------- .../v2/global/security/jwt/JwtReqFilter.kt | 1 - 4 files changed, 2 insertions(+), 55 deletions(-) delete mode 100644 src/main/kotlin/com/dotori/v2/global/security/jwt/JwtExceptionFilter.kt diff --git a/src/main/kotlin/com/dotori/v2/global/error/ErrorFilter.kt b/src/main/kotlin/com/dotori/v2/global/error/ErrorFilter.kt index 00bed053..f4a64c24 100644 --- a/src/main/kotlin/com/dotori/v2/global/error/ErrorFilter.kt +++ b/src/main/kotlin/com/dotori/v2/global/error/ErrorFilter.kt @@ -10,11 +10,9 @@ import javax.servlet.http.HttpServletResponse import org.slf4j.LoggerFactory import org.springframework.http.HttpStatus import org.springframework.http.MediaType -import org.springframework.stereotype.Component import org.springframework.web.filter.OncePerRequestFilter import java.nio.charset.StandardCharsets -@Component class ErrorFilter : OncePerRequestFilter() { private val log = LoggerFactory.getLogger(this::class.simpleName) diff --git a/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt b/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt index 895a6042..42f537ff 100644 --- a/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt +++ b/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt @@ -69,8 +69,8 @@ class SecurityConfig( .accessDeniedHandler(CustomAccessDeniedHandler()) .authenticationEntryPoint(CustomAuthenticationEntryPointHandler()) .and() - .addFilterBefore(jwtRequestFilter, JwtReqFilter::class.java) - .addFilterBefore(errorFilter, ErrorFilter::class.java) + .addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter::class.java) + .addFilterBefore(errorFilter, JwtReqFilter::class.java) return http.build() } diff --git a/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtExceptionFilter.kt b/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtExceptionFilter.kt deleted file mode 100644 index ef41e3de..00000000 --- a/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtExceptionFilter.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.dotori.v2.global.security.jwt - -import com.dotori.v2.global.error.ErrorCode -import com.dotori.v2.global.error.ErrorResponse -import com.fasterxml.jackson.databind.ObjectMapper -import io.jsonwebtoken.ExpiredJwtException -import io.jsonwebtoken.JwtException -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Component -import org.springframework.web.filter.OncePerRequestFilter -import java.io.IOException -import javax.servlet.FilterChain -import javax.servlet.ServletException -import javax.servlet.http.HttpServletRequest -import javax.servlet.http.HttpServletResponse - -@Component -class JwtExceptionFilter( - private val objectMapper: ObjectMapper -) : OncePerRequestFilter() { - private val log = LoggerFactory.getLogger(this.javaClass.simpleName) - - @Throws(ServletException::class, IOException::class) - override fun doFilterInternal(request: HttpServletRequest, response: HttpServletResponse, filterChain: FilterChain) { - try { - filterChain.doFilter(request, response) - } catch (ex: ExpiredJwtException) { - log.debug("================= [ ExceptionHandlerFilter ] 에서 ExpiredJwtException 발생 ===================") - setErrorResponse(ErrorCode.TOKEN_EXPIRED, response) - } catch (ex: JwtException) { - log.debug("================= [ ExceptionHandlerFilter ] 에서 JwtException 발생 ===================") - setErrorResponse(ErrorCode.TOKEN_INVALID, response) - } catch (ex: IllegalArgumentException) { - log.debug("================= [ ExceptionHandlerFilter ] 에서 JwtException 발생 ===================") - setErrorResponse(ErrorCode.TOKEN_INVALID, response) - } catch (ex: Exception) { - log.debug("================= [ ExceptionHandlerFilter ] 에서 Exception 발생 ===================") - setErrorResponse(ErrorCode.UNKNOWN_ERROR, response) - } - } - - @Throws(IOException::class) - fun setErrorResponse(errorCode: ErrorCode, response: HttpServletResponse) { - response.status = errorCode.error - response.contentType = "application/json; charset=utf-8" - val errorResponse = ErrorResponse(errorCode) - val errorResponseEntityToJson = objectMapper.writeValueAsString(errorResponse) - response.writer.write(errorResponseEntityToJson.toString()) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtReqFilter.kt b/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtReqFilter.kt index c8d5cf5d..8a7b7d20 100644 --- a/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtReqFilter.kt +++ b/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtReqFilter.kt @@ -9,7 +9,6 @@ import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse -@Component class JwtReqFilter( private val tokenProvider: TokenProvider, ) : OncePerRequestFilter() { From 2608c87ad311e2a11f0561334a00c2627ee080d2 Mon Sep 17 00:00:00 2001 From: aesperer Date: Thu, 8 Aug 2024 19:15:57 +0900 Subject: [PATCH 6/9] add :: component re; --- src/main/kotlin/com/dotori/v2/global/error/ErrorFilter.kt | 2 ++ .../kotlin/com/dotori/v2/global/security/jwt/JwtReqFilter.kt | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/kotlin/com/dotori/v2/global/error/ErrorFilter.kt b/src/main/kotlin/com/dotori/v2/global/error/ErrorFilter.kt index f4a64c24..00bed053 100644 --- a/src/main/kotlin/com/dotori/v2/global/error/ErrorFilter.kt +++ b/src/main/kotlin/com/dotori/v2/global/error/ErrorFilter.kt @@ -10,9 +10,11 @@ import javax.servlet.http.HttpServletResponse import org.slf4j.LoggerFactory import org.springframework.http.HttpStatus import org.springframework.http.MediaType +import org.springframework.stereotype.Component import org.springframework.web.filter.OncePerRequestFilter import java.nio.charset.StandardCharsets +@Component class ErrorFilter : OncePerRequestFilter() { private val log = LoggerFactory.getLogger(this::class.simpleName) diff --git a/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtReqFilter.kt b/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtReqFilter.kt index 8a7b7d20..c8d5cf5d 100644 --- a/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtReqFilter.kt +++ b/src/main/kotlin/com/dotori/v2/global/security/jwt/JwtReqFilter.kt @@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse +@Component class JwtReqFilter( private val tokenProvider: TokenProvider, ) : OncePerRequestFilter() { From 1e6277b1a661139490b1171fde47833cbabf3034 Mon Sep 17 00:00:00 2001 From: aesperer Date: Thu, 8 Aug 2024 19:21:01 +0900 Subject: [PATCH 7/9] =?UTF-8?q?update=20::=20security=20config=20matchers?= =?UTF-8?q?=20=EC=9C=84=EC=B9=98=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dotori/v2/global/security/SecurityConfig.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt b/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt index 42f537ff..4e7c805c 100644 --- a/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt +++ b/src/main/kotlin/com/dotori/v2/global/security/SecurityConfig.kt @@ -42,11 +42,17 @@ class SecurityConfig( .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .authorizeHttpRequests() + + .antMatchers(HttpMethod.GET, "/").permitAll() + .antMatchers("/actuator/**").permitAll() .antMatchers("/v2/auth/**").permitAll() .antMatchers("/v2/health-check").permitAll() .antMatchers("/v2/refresh").permitAll() + .antMatchers(HttpMethod.GET, "/v2/home/board").authenticated() + .antMatchers(HttpMethod.GET, "/v2/home").authenticated() + .antMatchers("/v2/admin/**").hasRole("ADMIN") .antMatchers("/v2/member/**").hasRole("MEMBER") .antMatchers("/v2/councillor/**").hasRole("COUNCILLOR") @@ -57,12 +63,6 @@ class SecurityConfig( .antMatchers("/v2/email/**").permitAll() .antMatchers("/v2/members/**").authenticated() - - .antMatchers(HttpMethod.GET, "/v2/home/board").authenticated() - .antMatchers(HttpMethod.GET, "/v2/home").authenticated() - - .mvcMatchers(HttpMethod.GET, "/").permitAll() - .anyRequest().denyAll() .and() .exceptionHandling() From 31ddbc16754576edf0d2ccd8ba10dade78c19503 Mon Sep 17 00:00:00 2001 From: aesperer Date: Thu, 8 Aug 2024 19:23:55 +0900 Subject: [PATCH 8/9] =?UTF-8?q?chore=20::=20indicator=20=EC=A3=BC=EC=84=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dotori/v2/indicator/ReservationIndicatorAspect.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/dotori/v2/indicator/ReservationIndicatorAspect.kt b/src/main/kotlin/com/dotori/v2/indicator/ReservationIndicatorAspect.kt index 5e09c420..f7aa9148 100644 --- a/src/main/kotlin/com/dotori/v2/indicator/ReservationIndicatorAspect.kt +++ b/src/main/kotlin/com/dotori/v2/indicator/ReservationIndicatorAspect.kt @@ -10,8 +10,8 @@ import org.springframework.stereotype.Component import java.time.Duration import java.time.LocalDateTime -@Aspect -@Component +//@Aspect +//@Component class ReservationIndicatorAspect( private val reservationIndicatorsRepository: ReservationIndicatorsRepository ) { From c6149c14074e0ea7d7bc1a611b614b673642fa82 Mon Sep 17 00:00:00 2001 From: aesperer Date: Thu, 8 Aug 2024 19:30:30 +0900 Subject: [PATCH 9/9] chore :: logging aspect substring --- src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt b/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt index 4ccc9456..3ac8022c 100644 --- a/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt +++ b/src/main/kotlin/com/dotori/v2/aop/HttpLoggingAspect.kt @@ -55,7 +55,12 @@ class HttpLoggingAspect { val result = proceedingJoinPoint.proceed() when (result) { is ResponseEntity<*> -> { - val body = result.body.toString().substring(0, 55) + var body = result.body.toString() + + if(body.length > 55) { + body = body.substring(0, 55) + } + log.info( "At {}#{} [Response:{}] IP: {}, Session-ID: {}, Headers: {}, Response: {}, Status-Code: {}, Code: {}", className, methodName, method, ip, sessionId, result.headers, body, result.statusCode, code