Skip to content

Commit

Permalink
fix: referer 로깅 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
cookienc committed Jul 10, 2024
1 parent 4eb6643 commit 168232b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class LoggerAspect {
- Method: ${request.method}
- URI: ${getURI(request)}
- IP: ${getClientIP(request)}
- Referer: ${request.getHeader(HttpHeaders.REFERER)}
- Signature: ${getSignature(joinPoint)}
""".trimIndent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import backend.itracker.tracker.oauth.OauthServerType
import backend.itracker.tracker.oauth.RedirectType
import backend.itracker.tracker.oauth.service.LoginFacade
import backend.itracker.tracker.oauth.service.OauthService
import io.github.oshai.kotlinlogging.KotlinLogging
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.slf4j.MDC
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*

private val logger = KotlinLogging.logger { }
@RestController
@RequestMapping("/api/v1/oauth")
class OauthController(
Expand All @@ -25,11 +28,13 @@ class OauthController(
response: HttpServletResponse
): ResponseEntity<Unit> {
if (request.getHeader(HttpHeaders.REFERER).contains("localhost")) {
logger.info { "${MDC.get("request_id")} -> code local" }
oauthService.getAuthCodeRequestUrl(oauthServerType, RedirectType.LOCAL).let {
response.sendRedirect(it)
}
return ResponseEntity.status(HttpStatus.FOUND).build()
}
logger.info { "${MDC.get("request_id")} -> code prod" }
oauthService.getAuthCodeRequestUrl(oauthServerType, RedirectType.PROD).let {
response.sendRedirect(it)
}
Expand All @@ -44,13 +49,15 @@ class OauthController(
request: HttpServletRequest,
): ResponseEntity<Long> {
if (request.getHeader(HttpHeaders.REFERER).contains("localhost")) {
logger.info { "${MDC.get("request_id")} -> token local" }
val accessToken = loginFacade.login(oauthServerType, code, RedirectType.LOCAL)

return ResponseEntity.ok()
.header(HttpHeaders.AUTHORIZATION, accessToken)
.build()
}

logger.info { "${MDC.get("request_id")} -> token prod" }
val accessToken = loginFacade.login(oauthServerType, code, RedirectType.PROD)

return ResponseEntity.ok()
Expand Down

0 comments on commit 168232b

Please sign in to comment.