【问题标题】:How to log basic auth attempts on tomcat如何在 tomcat 上记录基本身份验证尝试
【发布时间】:2020-02-24 14:40:45
【问题描述】:

我创建了一个具有基本身份验证功能的网络应用程序(使用 spring mvc 和 tomcat)。

现在我想记录用户进行的每一次基本身份验证尝试(成功和失败)。

我怎样才能做到这一点?

PS:

在此页面上找不到信息:https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Logging

server.xml里面我试过<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>

这会创建以下文件/logs/localhost_access_log.2020-02-24.txt

127.0.0.1 - - [24/Feb/2020:15:12:35 +0100] "GET /spring-rest-demo/test/hello HTTP/1.1" 200 12
127.0.0.1 - - [24/Feb/2020:15:13:31 +0100] "GET /spring-rest-demo/test/hello HTTP/1.1" 200 12
127.0.0.1 - - [24/Feb/2020:15:13:37 +0100] "GET /spring-rest-demo/test/hello HTTP/1.1" 401 35

它只记录每个请求,但我只想记录基本的身份验证尝试(我想知道有多少成功或失败)。如果太多失败,我的目标是进行报告。

提前致谢

【问题讨论】:

    标签: tomcat logging basic-authentication


    【解决方案1】:

    已解决:pattern="%h %l %u %t "%r" %s %b %{Authorization}i"

    %{Authorization}i: 记录名称为“授权”的 http 标头,该标头包含在每个基本身份验证请求中

    【讨论】:

    • 需要注意的是,这个方案是以明文形式记录客户端的密码,因此这个模式不应该在生产系统中使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    • 2016-01-04
    • 2018-04-16
    • 2014-11-11
    • 2012-09-16
    • 1970-01-01
    • 2015-11-04
    相关资源
    最近更新 更多