1
2
3
4
5
6
7
8
9
10
11 package org.mule.security;
12
13 import org.mule.api.EncryptionStrategy;
14 import org.mule.api.MuleMessage;
15 import org.mule.api.config.MuleProperties;
16 import org.mule.api.transport.SessionHandler;
17 import org.mule.module.client.MuleClient;
18 import org.mule.session.MuleSessionHandler;
19 import org.mule.tck.FunctionalTestCase;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24
25
26
27
28
29
30
31 public class MultiuserSecurityTestCase extends FunctionalTestCase
32 {
33 protected String getConfigResources()
34 {
35 return "multiuser-security-test.xml, singleuser-security-provider.xml";
36 }
37
38 public void testMultipleAuthentications() throws Exception
39 {
40 MuleClient client = new MuleClient(muleContext);
41 SessionHandler sessionHandler = new MuleSessionHandler();
42 MuleMessage reply;
43 Map props;
44
45 EncryptionStrategy strategy = muleContext.getSecurityManager().getEncryptionStrategy("PBE");
46
47 props = new HashMap();
48 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("marie", "marie", "PBE", strategy));
49 reply = client.send("vm://test", "Data1", props);
50 assertNotNull(reply);
51 assertEquals("user = marie, logins = 1, color = bright red", reply.getPayload());
52
53 props = new HashMap();
54 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("stan", "stan", "PBE", strategy));
55 reply = client.send("vm://test", "Data2", props);
56 assertNotNull(reply);
57 assertEquals("user = stan, logins = 1, color = metallic blue", reply.getPayload());
58
59 props = new HashMap();
60 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("cindy", "cindy", "PBE", strategy));
61 reply = client.send("vm://test", "Data3", props);
62 assertEquals("user = cindy, logins = 1, color = dark violet", reply.getPayload());
63
64 props = new HashMap();
65 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("marie", "marie", "PBE", strategy));
66 reply = client.send("vm://test", "Data4", props);
67 assertNotNull(reply);
68 assertEquals("user = marie, logins = 2, color = bright red", reply.getPayload());
69
70 props = new HashMap();
71 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("marie", "marie", "PBE", strategy));
72 reply = client.send("vm://test", "Data4", props);
73 assertNotNull(reply);
74 assertEquals("user = marie, logins = 3, color = bright red", reply.getPayload());
75
76 props = new HashMap();
77 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("stan", "stan", "PBE", strategy));
78 reply = client.send("vm://test", "Data2", props);
79 assertNotNull(reply);
80 assertEquals("user = stan, logins = 2, color = metallic blue", reply.getPayload());
81 }
82 }