0
votes

I created a web app with basic auth function ( using spring mvc and tomcat ).

Now I want to log every basic auth attempts a user makes (both successful and failed ).

How can I achieve that ?

PS:

Cannot find the info on this page: https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Logging

Inside server.xml I tried <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>

And this creates following file /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

It just logs every request, but I just want to log the basic auth attempts ( and I want to know how many were successful or failed ). My goal is to make a reporting, if too many failed.

Thanks in advance

1

1 Answers

0
votes

Solved using : pattern="%h %l %u %t &quot;%r&quot; %s %b %{Authorization}i"

%{Authorization}i: Logs http header with name 'Authorization' which is included in every Basic Auth request