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