Package com.example.blogs.app.logging
Class MdcPopulatingFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
com.example.blogs.app.logging.MdcPopulatingFilter
- All Implemented Interfaces:
jakarta.servlet.Filter,Aware,BeanNameAware,DisposableBean,InitializingBean,EnvironmentAware,EnvironmentCapable,ServletContextAware
Populates MDC with authenticated user information for request-scoped logging context.
-
Field Summary
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIXFields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) Extracts authenticated user ID from security context and populates MDC for use in log messages.Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatchMethods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Constructor Details
-
MdcPopulatingFilter
public MdcPopulatingFilter()
-
-
Method Details
-
doFilterInternal
protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) throws jakarta.servlet.ServletException, IOException Extracts authenticated user ID from security context and populates MDC for use in log messages. Runs after authentication is established but before business logic executes.- Specified by:
doFilterInternalin classOncePerRequestFilter- Parameters:
request- the HTTP requestresponse- the HTTP responsefilterChain- the filter chain to continue processing- Throws:
jakarta.servlet.ServletException- if request processing failsIOException- if an I/O error occurs during filtering
-