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