1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.acegi;
12
13 import org.mule.api.EncryptionStrategy;
14 import org.mule.api.MuleMessage;
15 import org.mule.api.config.MuleProperties;
16 import org.mule.module.client.MuleClient;
17 import org.mule.security.MuleCredentials;
18 import org.mule.tck.FunctionalTestCase;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.acegisecurity.context.SecurityContextHolder;
24 import org.acegisecurity.context.SecurityContextImpl;
25
26 public class AuthComponentAsynchFunctionalTestCase extends FunctionalTestCase
27 {
28
29 protected String getConfigResources()
30 {
31 return "auth-component-asynch-test.xml";
32 }
33
34 @Override
35
36 public void doTearDown()
37 {
38 SecurityContextHolder.setContext(new SecurityContextImpl());
39 }
40
41 public void testCaseGoodAuthenticationGoodAuthorisation() throws Exception
42 {
43 MuleClient client = new MuleClient(muleContext);
44 Map props = new HashMap();
45
46 EncryptionStrategy strategy = muleContext
47 .getSecurityManager()
48 .getEncryptionStrategy("PBE");
49 String header = MuleCredentials.createHeader("marie", "marie", "PBE", strategy);
50 props.put(MuleProperties.MULE_USER_PROPERTY, header);
51 client.dispatch("vm://test", "Marie", props);
52 MuleMessage m = client.request("vm://output", 3000);
53 assertNotNull(m);
54 assertEquals(m.getPayloadAsString(), "Marie");
55 }
56
57 public void testCaseGoodAuthenticationBadAuthorisation() throws Exception
58 {
59 MuleClient client = new MuleClient(muleContext);
60 Map props = new HashMap();
61
62 EncryptionStrategy strategy = muleContext
63 .getSecurityManager()
64 .getEncryptionStrategy("PBE");
65 String header = MuleCredentials.createHeader("anon", "anon", "PBE", strategy);
66 props.put(MuleProperties.MULE_USER_PROPERTY, header);
67 client.dispatch("vm://test", "Marie", props);
68 MuleMessage m = client.request("vm://output", 3000);
69 assertNull(m);
70 }
71
72 public void testCaseBadAuthentication() throws Exception
73 {
74 MuleClient client = new MuleClient(muleContext);
75 Map props = new HashMap();
76
77 EncryptionStrategy strategy = muleContext
78 .getSecurityManager()
79 .getEncryptionStrategy("PBE");
80 String header = MuleCredentials.createHeader("anonX", "anonX", "PBE", strategy);
81 props.put(MuleProperties.MULE_USER_PROPERTY, header);
82 client.dispatch("vm://test", "USD,MTL", props);
83 MuleMessage m = client.request("vm://output", 3000);
84 assertNull(m);
85 }
86
87 }