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