Tuesday, December 10, 2013

Add username in apache logs with form authentication

If you use basic authentication the Apache log option "%u" will log the current logged in user. However if you use form authentication you will need to play with response headers. Below a typical custom log for your apache + Java/JEE:
LogFormat "%h %l %{USER}o %t \"%r\" %>s %b %{JSESSIONID}C" custom
CustomLog /var/log/apache2/sample.com.log custom
It will generate something like:
192.168.5.101 - myUser - [28/Sep/2013:18:09:40 -0400] "GET /my/path HTTP/1.1" 200 24292 6FCC544E05F7F5D31691C5907F99CFAA.node1
The user will only be logged if "USER" is set as response header in the Java / JEE server.

No comments:

Followers