1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.jaas;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import org.mule.api.MuleMessage;
18 import org.mule.api.security.UnauthorisedException;
19 import org.mule.util.ExceptionUtils;
20
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.Map;
24
25 import org.junit.Test;
26 import org.junit.runners.Parameterized.Parameters;
27
28 public class JaasAuthenticationNoJaasConfigFileTestCase extends AbstractJaasFunctionalTestCase
29 {
30 public JaasAuthenticationNoJaasConfigFileTestCase(ConfigVariant variant, String configResources)
31 {
32 super(variant, configResources);
33 }
34
35 @Parameters
36 public static Collection<Object[]> parameters()
37 {
38 return Arrays.asList(new Object[][]{
39 {ConfigVariant.SERVICE, "mule-conf-with-no-jaas-config-file-service.xml"},
40 {ConfigVariant.FLOW, "mule-conf-with-no-jaas-config-file-flow.xml"}
41 });
42 }
43
44 @Test
45 public void goodAuthentication() throws Exception
46 {
47 Map<String, Object> props = createMessagePropertiesWithCredentials("Marie.Rizzo", "dragon");
48 MuleMessage m = muleContext.getClient().send("vm://test", "Test", props);
49
50 assertNotNull(m);
51 assertTrue(m.getPayload() instanceof String);
52 assertEquals("Test Received", m.getPayloadAsString());
53 }
54
55 @Test
56 public void anotherGoodAuthentication() throws Exception
57 {
58 Map<String, Object> props = createMessagePropertiesWithCredentials("anon", "anon");
59 MuleMessage m = muleContext.getClient().send("vm://test", "Test", props);
60
61 assertNotNull(m);
62 assertTrue(m.getPayload() instanceof String);
63 assertEquals("Test Received", m.getPayloadAsString());
64 }
65
66 @Test
67 public void wrongCombinationOfCorrectUsernameAndPassword() throws Exception
68 {
69 Map<String, Object> props = createMessagePropertiesWithCredentials("Marie.Rizzo", "anon");
70
71 MuleMessage message = muleContext.getClient().send("vm://test", "Test", props);
72 assertNotNull(message);
73 assertNotNull(message.getExceptionPayload());
74 assertTrue(ExceptionUtils.containsType(message.getExceptionPayload().getException(),
75 UnauthorisedException.class));
76 }
77
78 @Test
79 public void badUserName() throws Exception
80 {
81 Map<String, Object> props = createMessagePropertiesWithCredentials("Evil", "dragon");
82
83 MuleMessage message = muleContext.getClient().send("vm://test", "Test", props);
84 assertNotNull(message);
85 assertNotNull(message.getExceptionPayload());
86 assertTrue(ExceptionUtils.containsType(message.getExceptionPayload().getException(),
87 UnauthorisedException.class));
88 }
89
90 @Test
91 public void badPassword() throws Exception
92 {
93 Map<String, Object> props = createMessagePropertiesWithCredentials("Marie.Rizzo", "evil");
94
95 MuleMessage message = muleContext.getClient().send("vm://test", "Test", props);
96 assertNotNull(message);
97 assertNotNull(message.getExceptionPayload());
98 assertTrue(ExceptionUtils.containsType(message.getExceptionPayload().getException(),
99 UnauthorisedException.class));
100 }
101 }