View Javadoc

1   /*
2    * $Id: CustomSecurityFilterTestCase.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.test.integration.security;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertNull;
16  
17  import org.mule.api.MuleMessage;
18  import org.mule.client.DefaultLocalMuleClient;
19  import org.mule.tck.junit4.FunctionalTestCase;
20  
21  import java.util.HashMap;
22  
23  import org.junit.Test;
24  import org.springframework.security.authentication.BadCredentialsException;
25  
26  /**
27   * See MULE-4916: spring beans inside a security filter
28   */
29  public class CustomSecurityFilterTestCase extends FunctionalTestCase
30  {
31      @Override
32      protected String getConfigResources()
33      {
34          return "org/mule/test/integration/security/custom-security-filter-test.xml";
35      }
36  
37      @Test
38      public void testOutboundAutenticationSend() throws Exception
39      {
40          DefaultLocalMuleClient client = new DefaultLocalMuleClient(muleContext);
41  
42          HashMap<String, Object> props = new HashMap<String, Object>();
43          props.put("username", "ross");
44          props.put("pass", "ross");
45          MuleMessage result = client.send("vm://test", "hi", props);
46          assertNull(result.getExceptionPayload());
47  
48          props.put("pass", "badpass");
49  
50          MuleMessage resultMessage = client.send("vm://test", "hi", props);
51          assertNotNull(resultMessage);
52          assertNotNull(resultMessage.getExceptionPayload());
53          assertEquals(BadCredentialsException.class, resultMessage.getExceptionPayload()
54              .getRootException()
55              .getClass());
56      }
57  }