Skip to content

Commit

Permalink
Reenable auditing, excluding request body
Browse files Browse the repository at this point in the history
  • Loading branch information
Pozo committed Jun 9, 2024
1 parent b8c45ed commit 819aa71
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ open class AuditConfig : WebMvcConfigurer {

override fun addInterceptors(registry: InterceptorRegistry) {
// Register the audit interceptor to intercept all incoming requests
// registry.addInterceptor(auditInterceptor)
registry.addInterceptor(auditInterceptor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor
import java.io.IOException
import java.util.stream.Collectors


/**
Expand All @@ -19,16 +18,7 @@ class AuditInterceptor : HandlerInterceptor {

@Throws(IOException::class)
override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
// Wrap the request to cache the body for multiple reads
val cachedRequest = CachedBodyHttpServletRequest(request)

// Extract and log request details
val requestURI = cachedRequest.requestURI
val method = cachedRequest.method
val params = getParameters(cachedRequest)
val body = getBody(cachedRequest)

logger.info("Request URL: $requestURI, Method: $method, Parameters: $params, Body: $body")
logger.info("Request URL: ${request.requestURI}, Method: ${request.method}, Parameters: ${getParameters(request)}")

return true
}
Expand All @@ -40,11 +30,4 @@ class AuditInterceptor : HandlerInterceptor {
return request.parameterMap.entries.joinToString("&") { "${it.key}=${it.value.joinToString(",")}" }
}

/**
* Reads the request body and converts it to a string.
*/
@Throws(IOException::class)
private fun getBody(request: HttpServletRequest): String {
return request.reader.lines().collect(Collectors.joining(System.lineSeparator()))
}
}

This file was deleted.

0 comments on commit 819aa71

Please sign in to comment.