View Javadoc

1   /*
2    * $Id: JaasAutenticationWithJaasConfigFileTestCase.java 22735 2011-08-25 16:02:35Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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 JaasAutenticationWithJaasConfigFileTestCase extends AbstractJaasFunctionalTestCase
29  {
30      public JaasAutenticationWithJaasConfigFileTestCase(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[][]{{ConfigVariant.SERVICE, "mule-conf-for-jaas-conf-file-service.xml"},
39              {ConfigVariant.FLOW, "mule-conf-for-jaas-conf-file-flow.xml"}});
40      }
41  
42      @Test
43      public void goodAuthentication() throws Exception
44      {
45          Map<String, Object> props = createMessagePropertiesWithCredentials("Marie.Rizzo", "dragon");
46          MuleMessage m = muleContext.getClient().send("vm://test", "Test", props);
47  
48          assertNotNull(m);
49          assertTrue(m.getPayload() instanceof String);
50          assertEquals("Test Received", m.getPayloadAsString());
51      }
52  
53      @Test
54      public void anotherGoodAuthentication() throws Exception
55      {
56          Map<String, Object> props = createMessagePropertiesWithCredentials("anon", "anon");
57          MuleMessage m = muleContext.getClient().send("vm://test", "Test", props);
58  
59          assertNotNull(m);
60          assertTrue(m.getPayload() instanceof String);
61          assertEquals("Test Received", m.getPayloadAsString());
62      }
63  
64      @Test
65      public void wrongCombinationOfCorrectUsernameAndPassword() throws Exception
66      {
67          Map<String, Object> props = createMessagePropertiesWithCredentials("Marie.Rizzo", "anon");
68  
69          MuleMessage message = muleContext.getClient().send("vm://test", "Test", props);
70          assertNotNull(message);
71          assertNotNull(message.getExceptionPayload());
72          assertTrue(ExceptionUtils.containsType(message.getExceptionPayload().getException(),
73              UnauthorisedException.class));
74      }
75  
76      @Test
77      public void badUserName() throws Exception
78      {
79          Map<String, Object> props = createMessagePropertiesWithCredentials("Evil", "dragon");
80  
81          MuleMessage message = muleContext.getClient().send("vm://test", "Test", props);
82          assertNotNull(message);
83          assertNotNull(message.getExceptionPayload());
84          assertTrue(ExceptionUtils.containsType(message.getExceptionPayload().getException(),
85              UnauthorisedException.class));
86      }
87  
88      @Test
89      public void badPassword() throws Exception
90      {
91          Map<String, Object> props = createMessagePropertiesWithCredentials("Marie.Rizzo", "evil");
92  
93          MuleMessage message = muleContext.getClient().send("vm://test", "Test", props);
94          assertNotNull(message);
95          assertNotNull(message.getExceptionPayload());
96          assertTrue(ExceptionUtils.containsType(message.getExceptionPayload().getException(),
97              UnauthorisedException.class));
98  
99      }
100 }