1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.processor; |
8 | |
|
9 | |
import org.mule.api.MuleEvent; |
10 | |
import org.mule.api.MuleException; |
11 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
12 | |
import org.mule.api.security.SecurityException; |
13 | |
import org.mule.api.security.SecurityFilter; |
14 | |
import org.mule.config.ExceptionHelper; |
15 | |
import org.mule.context.notification.SecurityNotification; |
16 | |
import org.mule.endpoint.EndpointAware; |
17 | |
import org.mule.message.DefaultExceptionPayload; |
18 | |
import org.mule.transport.AbstractConnector; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class SecurityFilterMessageProcessor extends AbstractInterceptingMessageProcessor implements EndpointAware |
27 | |
{ |
28 | |
private SecurityFilter filter; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public SecurityFilterMessageProcessor() |
35 | |
{ |
36 | 0 | super(); |
37 | 0 | } |
38 | |
|
39 | |
public SecurityFilterMessageProcessor(SecurityFilter filter) |
40 | 0 | { |
41 | 0 | this.filter = filter; |
42 | 0 | } |
43 | |
|
44 | |
public SecurityFilter getFilter() |
45 | |
{ |
46 | 0 | return filter; |
47 | |
} |
48 | |
|
49 | |
public MuleEvent process(MuleEvent event) throws MuleException |
50 | |
{ |
51 | 0 | if (filter != null) |
52 | |
{ |
53 | |
try |
54 | |
{ |
55 | 0 | filter.doFilter(event); |
56 | |
} |
57 | 0 | catch (SecurityException e) |
58 | |
{ |
59 | 0 | e = (SecurityException) ExceptionHelper.sanitizeIfNeeded(e); |
60 | 0 | logger.warn("Outbound Request was made but was not authenticated: " + e.getMessage(), e); |
61 | |
|
62 | 0 | AbstractConnector connector = (AbstractConnector) event.getEndpoint().getConnector(); |
63 | 0 | connector.fireNotification(new SecurityNotification(e, |
64 | |
SecurityNotification.SECURITY_AUTHENTICATION_FAILED)); |
65 | |
|
66 | 0 | event.getFlowConstruct().getExceptionListener().handleException(e, event); |
67 | |
|
68 | 0 | event.getMessage().setPayload(e.getLocalizedMessage()); |
69 | 0 | event.getMessage().setExceptionPayload(new DefaultExceptionPayload(e)); |
70 | 0 | return event; |
71 | 0 | } |
72 | |
} |
73 | 0 | return processNext(event); |
74 | |
} |
75 | |
|
76 | |
public void setFilter(SecurityFilter filter) |
77 | |
{ |
78 | 0 | this.filter = filter; |
79 | 0 | } |
80 | |
|
81 | |
public void setEndpoint(ImmutableEndpoint ep) |
82 | |
{ |
83 | 0 | if (filter instanceof EndpointAware) |
84 | |
{ |
85 | 0 | ((EndpointAware) filter).setEndpoint(ep); |
86 | |
} |
87 | 0 | } |
88 | |
} |