1
2
3
4
5
6
7
8
9
10
11 package org.mule.tck.security;
12
13 import org.mule.api.MuleEvent;
14 import org.mule.api.lifecycle.InitialisationException;
15 import org.mule.api.security.CryptoFailureException;
16 import org.mule.api.security.EncryptionStrategyNotFoundException;
17 import org.mule.api.security.SecurityException;
18 import org.mule.api.security.SecurityProviderNotFoundException;
19 import org.mule.api.security.UnauthorisedException;
20 import org.mule.api.security.UnknownAuthenticationTypeException;
21 import org.mule.security.AbstractEndpointSecurityFilter;
22
23 public class TestSecurityFilter extends AbstractEndpointSecurityFilter
24 {
25 private boolean accept;
26 private boolean called;
27
28 public static final String SECURITY_EXCEPTION_MESSAGE = "unauthorized!!";
29
30 public TestSecurityFilter(boolean accept)
31 {
32 this.accept = accept;
33 }
34
35 @Override
36 protected void authenticateInbound(MuleEvent event)
37 throws SecurityException, CryptoFailureException, SecurityProviderNotFoundException,
38 EncryptionStrategyNotFoundException, UnknownAuthenticationTypeException
39 {
40 called = true;
41 if (!accept)
42 {
43 throw new StaticMessageUnauthorisedException();
44 }
45 }
46
47 @Override
48 protected void authenticateOutbound(MuleEvent event)
49 throws SecurityException, SecurityProviderNotFoundException, CryptoFailureException
50 {
51 if (!accept)
52 {
53 throw new StaticMessageUnauthorisedException();
54 }
55 }
56
57 @Override
58 protected void doInitialise() throws InitialisationException
59 {
60 }
61
62 public boolean wasCalled()
63 {
64 return called;
65 }
66
67 public static class StaticMessageUnauthorisedException extends UnauthorisedException
68 {
69 public StaticMessageUnauthorisedException()
70 {
71 super(null);
72 }
73
74 @Override
75 public String getLocalizedMessage()
76 {
77 return SECURITY_EXCEPTION_MESSAGE;
78 }
79 }
80
81 }