Tuesday, February 20, 2018

Enabling Apache CXF Fediz plugin logging in Apache Tomcat

The Apache CXF Fediz subproject provides an easy way to secure your web applications via the WS-Federation Passive Requestor Profile. An earlier tutorial I wrote covers how to deploy and secure a "simpleWebapp" project that ships with Fediz in Apache Tomcat. One of the questions that came up recently on that article was how to enable logging for the Fediz plugin itself (as opposed to the IdP/STS). My colleague Jan Bernhardt has covered this topic using Apache Log4j. Here we will show a simple alternative way to enable logging using java.util.logging.

Please follow the earlier tutorial to set up and secure the "simpleWebapp" in Apache Tomcat. Note that after a successful test, the IdP logs appear in "logs/idp.log" and the STS logs appear in "logs/sts.log". However no logs exist for the plugin itself. To rectify this, copy the "slf4j-jdk14" jar into "lib/fediz" (for example from here). Then edit 'webapps/fedizhelloworld/WEB-INF/classes/logging.properties' with the following content:

handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
.level= INFO
java.util.logging.FileHandler.level = FINE
java.util.logging.FileHandler.pattern = ${catalina.base}/logs/rp.log
java.util.logging.FileHandler.limit = 500000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format="HEL %1$tc %2$s%n%4$s: %5$s%6$s%n"
org.apache.cxf.fediz.level = FINE
This configuration logs "INFO" level messages to the Console (catalina.out) and logs "FINE" level messages to the log file "logs/rp.log" in XML Format. For example:

<record>
<date>2018-02-20T15:11:10</date>
<millis>1519139470749</millis>
<sequence>182</sequence>
<logger>org.apache.cxf.fediz.tomcat8.handler.TomcatSigninHandler</logger>
<level>FINE</level>
<class>org.apache.cxf.fediz.tomcat8.handler.TomcatSigninHandler</class>
<method>createPrincipal</method>
<thread>36</thread>
<message>UserPrincipal was created successfully for GenericPrincipal[alice(User,)]</message>
</record>
view raw rp.log hosted with ❤ by GitHub

No comments:

Post a Comment