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