SEC-476: Provide support for not logging interactive authentication events.

This commit is contained in:
Ben Alex 2007-05-23 06:31:32 +00:00
parent 9864ef0a4a
commit 72a7d06ad1
1 changed files with 17 additions and 3 deletions

View File

@ -17,10 +17,8 @@ package org.acegisecurity.event.authentication;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
@ -35,12 +33,19 @@ public class LoggerListener implements ApplicationListener {
//~ Static fields/initializers ===================================================================================== //~ Static fields/initializers =====================================================================================
private static final Log logger = LogFactory.getLog(LoggerListener.class); private static final Log logger = LogFactory.getLog(LoggerListener.class);
/** If set to true, {@link InteractiveAuthenticationSuccessEvent} will be logged (defaults to true) */
private boolean logInteractiveAuthenticationSuccessEvents = true;
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
public void onApplicationEvent(ApplicationEvent event) { public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof AbstractAuthenticationEvent) { if (event instanceof AbstractAuthenticationEvent) {
AbstractAuthenticationEvent authEvent = (AbstractAuthenticationEvent) event; AbstractAuthenticationEvent authEvent = (AbstractAuthenticationEvent) event;
if (!logInteractiveAuthenticationSuccessEvents && authEvent instanceof InteractiveAuthenticationSuccessEvent) {
return;
}
if (logger.isWarnEnabled()) { if (logger.isWarnEnabled()) {
String message = "Authentication event " + ClassUtils.getShortName(authEvent.getClass()) + ": " String message = "Authentication event " + ClassUtils.getShortName(authEvent.getClass()) + ": "
@ -56,4 +61,13 @@ public class LoggerListener implements ApplicationListener {
} }
} }
} }
public boolean isLogInteractiveAuthenticationSuccessEvents() {
return logInteractiveAuthenticationSuccessEvents;
}
public void setLogInteractiveAuthenticationSuccessEvents(
boolean logInteractiveAuthenticationSuccessEvents) {
this.logInteractiveAuthenticationSuccessEvents = logInteractiveAuthenticationSuccessEvents;
}
} }