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