Java Reference
In-Depth Information
Now that you have collected the audit data, it has to be logged. You can adopt various
strategies to store this data. It can be stored in a database, filesystem, Microsoft Windows
Event Log, or Unix syslog. Hence, this component needs to be pluggable. I will follow the
simple principle of program to interface for this purpose. The AuditLog interface just
defines the single method log , which accepts an AuditEvent object. You can implement
this interface to provide a custom implementation. I have used an Apache Commons
Logger-based implementation to log the messages to the console, as shown in Listing 6-22.
Listing 6-22. CommonsLoggingAuditLogImplt.java
public class CommonsLoggingAuditLogImpl implements AuditLog{
private final Log _LOG = LogFactory.getLog(getClass());
public void log(AuditEvent event) {
_LOG.info(event);
}
}
An instance of this logger is injected into the audit advices, as shown in Listing 6-23.
Listing 6-23. audit-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd ">
<!--advice -->
<bean name="auditAdvice"
class="com.apress.einsure.security.audit.AuditAdviseInterceptor">
<property name="auditLog" ref="auditLogger" />
<!- - other properties
-->
</bean>
<bean name="auditLogger" class="com.apress.einsure.security.audit.AuditRule" />
<!—other beans -->
</beans>
 
Search WWH ::




Custom Search