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.AbstractServiceAndFlowTestCase;
20
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.junit.Ignore;
27 import org.junit.Test;
28 import org.junit.runners.Parameterized.Parameters;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertNotNull;
32
33
34
35
36
37
38
39
40 @Ignore
41 public class MultiuserSecurityTestCase extends AbstractServiceAndFlowTestCase
42 {
43 @Parameters
44 public static Collection<Object[]> parameters()
45 {
46 return Arrays.asList(new Object[][]{
47 {ConfigVariant.SERVICE, "multiuser-security-test-service.xml, singleuser-security-provider.xml"},
48 {ConfigVariant.FLOW, "multiuser-security-test-flow.xml, singleuser-security-provider.xml"}});
49 }
50
51 public MultiuserSecurityTestCase(ConfigVariant variant, String configResources)
52 {
53 super(variant, configResources);
54 }
55
56 @Test
57 public void testMultipleAuthentications() throws Exception
58 {
59 MuleClient client = new MuleClient(muleContext);
60 SessionHandler sessionHandler = new MuleSessionHandler();
61 MuleMessage reply;
62 Map<String, Object> props;
63
64 EncryptionStrategy strategy = muleContext.getSecurityManager().getEncryptionStrategy("PBE");
65
66 props = new HashMap<String, Object>();
67 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("marie", "marie", "PBE", strategy));
68 reply = client.send("vm://test", "Data1", props);
69 assertNotNull(reply);
70 assertEquals("user = marie, logins = 1, color = bright red", reply.getPayload());
71
72 props = new HashMap<String, Object>();
73 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("stan", "stan", "PBE", strategy));
74 reply = client.send("vm://test", "Data2", props);
75 assertNotNull(reply);
76 assertEquals("user = stan, logins = 1, color = metallic blue", reply.getPayload());
77
78 props = new HashMap<String, Object>();
79 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("cindy", "cindy", "PBE", strategy));
80 reply = client.send("vm://test", "Data3", props);
81 assertEquals("user = cindy, logins = 1, color = dark violet", reply.getPayload());
82
83 props = new HashMap<String, Object>();
84 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("marie", "marie", "PBE", strategy));
85 reply = client.send("vm://test", "Data4", props);
86 assertNotNull(reply);
87 assertEquals("user = marie, logins = 2, color = bright red", reply.getPayload());
88
89 props = new HashMap<String, Object>();
90 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("marie", "marie", "PBE", strategy));
91 reply = client.send("vm://test", "Data4", props);
92 assertNotNull(reply);
93 assertEquals("user = marie, logins = 3, color = bright red", reply.getPayload());
94
95 props = new HashMap<String, Object>();
96 props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("stan", "stan", "PBE", strategy));
97 reply = client.send("vm://test", "Data2", props);
98 assertNotNull(reply);
99 assertEquals("user = stan, logins = 2, color = metallic blue", reply.getPayload());
100 }
101 }