|
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 |
| |
|
21 |
| import org.springframework.context.ApplicationEvent; |
|
22 |
| import org.springframework.context.ApplicationListener; |
|
23 |
| |
|
24 |
| import org.springframework.util.ClassUtils; |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| public class LoggerListener implements ApplicationListener { |
|
38 |
| |
|
39 |
| |
|
40 |
| private static final Log logger = LogFactory.getLog(LoggerListener.class); |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
25
| public void onApplicationEvent(ApplicationEvent event) {
|
|
45 |
25
| if (event instanceof AbstractAuthenticationEvent) {
|
|
46 |
1
| AbstractAuthenticationEvent authEvent = (AbstractAuthenticationEvent) event;
|
|
47 |
| |
|
48 |
1
| if (logger.isWarnEnabled()) {
|
|
49 |
1
| String message = "Authentication event "
|
|
50 |
| + ClassUtils.getShortName(authEvent.getClass()) + ": " |
|
51 |
| + authEvent.getAuthentication().getName() + "; details: " |
|
52 |
| + authEvent.getAuthentication().getDetails(); |
|
53 |
| |
|
54 |
1
| if (event instanceof AbstractAuthenticationFailureEvent) {
|
|
55 |
1
| message = message + "; exception: "
|
|
56 |
| + ((AbstractAuthenticationFailureEvent) event).getException() |
|
57 |
| .getMessage(); |
|
58 |
| } |
|
59 |
| |
|
60 |
1
| logger.warn(message);
|
|
61 |
| } |
|
62 |
| } |
|
63 |
| } |
|
64 |
| } |