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 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 doAuthenticate(event);
35 }
36
37 @Override
38 protected void authenticateOutbound(MuleEvent event) throws SecurityException, SecurityProviderNotFoundException, CryptoFailureException
39 {
40 doAuthenticate(event);
41 }
42
43 protected void doAuthenticate(MuleEvent event) throws UnauthorisedException
44 {
45 try
46 {
47 Map<?, ?> payload = event.getMessage().getPayload(DataTypeFactory.create(Map.class));
48 String user = (String) payload.get("user");
49 if (user == null)
50 {
51 throw new UnauthorisedException(CoreMessages.authNoCredentials());
52 }
53 if ("anonymous".equals(user))
54 {
55 throw new UnauthorisedException(CoreMessages.authFailedForUser("anonymous"));
56 }
57 }
58 catch (Exception e)
59 {
60 throw new UnauthorisedException(CoreMessages.authFailedForUser("anonymous"), e);
61 }
62
63 }
64
65 @Override
66 protected void doInitialise() throws InitialisationException
67 {
68
69 }
70 }