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.AbstractAuthenticationFilter;
22
23 public class TestSecurityFilter extends AbstractAuthenticationFilter
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 public void authenticate(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 doInitialise() throws InitialisationException
49 {
50 }
51
52 public boolean wasCalled()
53 {
54 return called;
55 }
56
57 public static class StaticMessageUnauthorisedException extends UnauthorisedException
58 {
59 public StaticMessageUnauthorisedException()
60 {
61 super(null);
62 }
63
64 @Override
65 public String getLocalizedMessage()
66 {
67 return SECURITY_EXCEPTION_MESSAGE;
68 }
69 }
70
71 }