1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.example.notifications; |
11 | |
|
12 | |
import org.mule.api.MuleEvent; |
13 | |
import org.mule.api.lifecycle.InitialisationException; |
14 | |
import org.mule.api.security.CryptoFailureException; |
15 | |
import org.mule.api.security.EncryptionStrategyNotFoundException; |
16 | |
import org.mule.api.security.SecurityException; |
17 | |
import org.mule.api.security.SecurityProviderNotFoundException; |
18 | |
import org.mule.api.security.UnauthorisedException; |
19 | |
import org.mule.api.security.UnknownAuthenticationTypeException; |
20 | |
import org.mule.config.i18n.CoreMessages; |
21 | |
import org.mule.security.AbstractEndpointSecurityFilter; |
22 | |
import org.mule.transformer.types.DataTypeFactory; |
23 | |
|
24 | |
import java.util.Map; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 0 | public class DummySecurityFilter extends AbstractEndpointSecurityFilter |
30 | |
{ |
31 | |
@Override |
32 | |
protected void authenticateInbound(MuleEvent event) throws org.mule.api.security.SecurityException, CryptoFailureException, SecurityProviderNotFoundException, EncryptionStrategyNotFoundException, UnknownAuthenticationTypeException |
33 | |
{ |
34 | 0 | doAuthenticate(event); |
35 | 0 | } |
36 | |
|
37 | |
@Override |
38 | |
protected void authenticateOutbound(MuleEvent event) throws SecurityException, SecurityProviderNotFoundException, CryptoFailureException |
39 | |
{ |
40 | 0 | doAuthenticate(event); |
41 | 0 | } |
42 | |
|
43 | |
protected void doAuthenticate(MuleEvent event) throws UnauthorisedException |
44 | |
{ |
45 | |
try |
46 | |
{ |
47 | 0 | Map<?, ?> payload = event.getMessage().getPayload(DataTypeFactory.create(Map.class)); |
48 | 0 | String user = (String) payload.get("user"); |
49 | 0 | if (user == null) |
50 | |
{ |
51 | 0 | throw new UnauthorisedException(CoreMessages.authNoCredentials()); |
52 | |
} |
53 | 0 | if ("anonymous".equals(user)) |
54 | |
{ |
55 | 0 | throw new UnauthorisedException(CoreMessages.authFailedForUser("anonymous")); |
56 | |
} |
57 | |
} |
58 | 0 | catch (Exception e) |
59 | |
{ |
60 | 0 | throw new UnauthorisedException(CoreMessages.authFailedForUser("anonymous"), e); |
61 | 0 | } |
62 | |
|
63 | 0 | } |
64 | |
|
65 | |
@Override |
66 | |
protected void doInitialise() throws InitialisationException |
67 | |
{ |
68 | |
|
69 | 0 | } |
70 | |
} |