-
Notifications
You must be signed in to change notification settings - Fork 34
User id isn't shown in log message for some errors #1106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The first case doesn't work because Spring Security filters are being executed before But it's not clear why the second case isn't work either. As far I understand, not found page is generated by Spring servlet that should be executed after our filter and should have MDC already. I've tried to print stacktrace in this case and I saw that it was executed on another thread. So, it seems that this is related to ASYNC processing. Also, it's related to ERROR pages. I've tried to map a filter to such dispatcher types, but without luck. Here is my attempt, for history and next attempts: --- src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java
+++ src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java
@@ -54,6 +54,7 @@ import ru.mystamps.web.feature.series.importing.sale.SeriesSalesImportUrl;
import ru.mystamps.web.feature.site.SiteService;
import ru.mystamps.web.feature.site.SiteUrl;
+import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import java.util.Collections;
@@ -209,6 +210,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
new UserMdcLoggingFilter()
);
bean.addUrlPatterns("/*");
+ bean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ERROR, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC);
return bean;
}
diff --git src/main/java/ru/mystamps/web/support/spring/security/UserMdcLoggingFilter.java src/main/java/ru/mystamps/web/support/spring/security/UserMdcLoggingFilter.java
index 72475630..5a30e6a5 100644
--- src/main/java/ru/mystamps/web/support/spring/security/UserMdcLoggingFilter.java
+++ src/main/java/ru/mystamps/web/support/spring/security/UserMdcLoggingFilter.java
@@ -48,4 +48,14 @@ public class UserMdcLoggingFilter extends OncePerRequestFilter {
}
}
+ @Override
+ protected boolean shouldNotFilterAsyncDispatch() {
+ return false;
+ }
+
+ @Override
+ protected boolean shouldNotFilterErrorDispatch() {
+ return false;
+ }
+
} |
More cases (perhaps, they are different):
Because an image preview is generated on another thread, the user id is missing. |
Another case: duplicate key exception after a series creation
|
There at least 2 cases when userId isn't logged for logged in user:
//404
In this case we got RequestRejectedException (that shouldn't be there actually, see RequestRejectedExceptions pollute logs #1068)Example:
Example:
Tech debt for: 742ca80 (#1102)
The text was updated successfully, but these errors were encountered: