| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.acegisecurity.event.authentication; |
| 17 |
|
|
| 18 |
|
import org.apache.commons.logging.Log; |
| 19 |
|
import org.apache.commons.logging.LogFactory; |
| 20 |
|
import org.springframework.context.ApplicationEvent; |
| 21 |
|
import org.springframework.context.ApplicationListener; |
| 22 |
|
import org.springframework.util.ClassUtils; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
20 |
public class LoggerListener implements ApplicationListener { |
| 33 |
|
|
| 34 |
|
|
| 35 |
2 |
private static final Log logger = LogFactory.getLog(LoggerListener.class); |
| 36 |
|
|
| 37 |
|
|
| 38 |
20 |
private boolean logInteractiveAuthenticationSuccessEvents = true; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
public void onApplicationEvent(ApplicationEvent event) { |
| 43 |
24 |
if (event instanceof AbstractAuthenticationEvent) { |
| 44 |
1 |
AbstractAuthenticationEvent authEvent = (AbstractAuthenticationEvent) event; |
| 45 |
|
|
| 46 |
1 |
if (!logInteractiveAuthenticationSuccessEvents && authEvent instanceof InteractiveAuthenticationSuccessEvent) { |
| 47 |
0 |
return; |
| 48 |
|
} |
| 49 |
|
|
| 50 |
1 |
if (logger.isWarnEnabled()) { |
| 51 |
1 |
String message = "Authentication event " + ClassUtils.getShortName(authEvent.getClass()) + ": " |
| 52 |
|
+ authEvent.getAuthentication().getName() + "; details: " |
| 53 |
|
+ authEvent.getAuthentication().getDetails(); |
| 54 |
|
|
| 55 |
1 |
if (event instanceof AbstractAuthenticationFailureEvent) { |
| 56 |
1 |
message = message + "; exception: " |
| 57 |
|
+ ((AbstractAuthenticationFailureEvent) event).getException().getMessage(); |
| 58 |
|
} |
| 59 |
|
|
| 60 |
1 |
logger.warn(message); |
| 61 |
|
} |
| 62 |
|
} |
| 63 |
24 |
} |
| 64 |
|
|
| 65 |
|
public boolean isLogInteractiveAuthenticationSuccessEvents() { |
| 66 |
0 |
return logInteractiveAuthenticationSuccessEvents; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
public void setLogInteractiveAuthenticationSuccessEvents( |
| 70 |
|
boolean logInteractiveAuthenticationSuccessEvents) { |
| 71 |
0 |
this.logInteractiveAuthenticationSuccessEvents = logInteractiveAuthenticationSuccessEvents; |
| 72 |
0 |
} |
| 73 |
|
} |