tomcat - 如何禁用 Spring 安全日志记录

标签 tomcat logging spring-security

我正在使用 Tomcat 作为 servlet 容器,我必须每天检查 catalina.out 日志以进行调试。但是当匿名用户尝试登录时,Spring Security 拦截器抛出异常,它会淹没 catalina.out 日志文件。日志是这样的:

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:327)
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:197)
at org.springframework.flex.security3.EndpointInterceptor.preProcess(EndpointInterceptor.java:97)
at org.springframework.flex.core.MessageInterceptionAdvice.invoke(MessageInterceptionAdvice.java:62)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:124)
... 52 more

如何在 Tomcat 中禁用 Spring Security 日志记录?

最佳答案

当日志级别设置为 DEBUG 并且您的过滤器链中没有 AnonymousAuthenticationFilter 时,您将在日志中看到 AuthenticationCredentialsNotFoundException。

参见 FAQ .

所以我假设您在安全应用程序上下文中使用传统的 bean 配置而不是命名空间配置。如果您想摆脱异常,您可以按照 documentation 中的描述将一个 anonymousAuthenticationFilter 添加到您的应用程序上下文中。

或者,您可以将日志级别设置为

org.springframework.security.level=INFO

在这个 question 中提到的 tomcat 中.

关于tomcat - 如何禁用 Spring 安全日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11715381/

相关文章:

spring - 如何在单页应用程序(spring security)中提供 CSRF Token?

java - Swagger 找不到服务器错误

java - 尝试在 java .war 之外读取 .properties 文件时出错

java - 日志语句导致简单 Java 代码死锁?

ruby-on-rails - 如何像调试 Rails 应用程序一样调试 Sinatra 应用程序?

SVN - 获取文件的所有提交消息?

java - 带有 AcceptHeaderLocaleResolver 和 i18n 的 Spring Security

java - 登录成功后重定向到原始页面返回原始数据而不是 URL 名称

java - 如何将 log4j 日志记录从 catalina.out 重定向到单独的文件?

tomcat - 部署项目war时出现Tomcat错误