1   /*
2    * $Id: AxisWsSecurityOnInboundTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.extras.wssecurity.testcases;
12  
13  import org.mule.extras.client.MuleClient;
14  import org.mule.tck.FunctionalTestCase;
15  import org.mule.umo.UMOMessage;
16  
17  import java.util.Properties;
18  
19  import org.apache.ws.security.handler.WSHandlerConstants;
20  
21  public class AxisWsSecurityOnInboundTestCase extends FunctionalTestCase
22  {
23      public void testGoodUserNameEncrypted () throws Exception
24      {
25          MuleClient client = new MuleClient();
26          Properties props = new Properties();
27  
28          // Action to perform : user token
29          props.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
30          // User name to send
31          props.setProperty(WSHandlerConstants.USER, "mulealias");
32          // Callback used to retrive password for given user.
33          props.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, "org.mule.extras.wssecurity.callbackhandlers.MuleWsSecurityCallbackHandler");
34          // Property file containing the Encryption properties
35          props.setProperty(WSHandlerConstants.ENC_PROP_FILE, "out-encrypted-security.properties");
36  
37          UMOMessage m = client.send("axis:http://localhost:8282/MySecuredUMO?method=echo", "Test", props);
38          assertNotNull(m);
39          assertTrue(m.getPayload() instanceof String);
40          assertTrue(m.getPayload().equals("Test"));
41      }
42  
43      public void testBadUserNameEncrypted () throws Exception
44      {
45          MuleClient client = new MuleClient();
46          Properties props = new Properties();
47  
48          // Action to perform : user token
49          props.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
50          // User name to send
51          props.setProperty(WSHandlerConstants.USER, "myBadAlias");
52          // Callback used to retrive password for given user.
53          props.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, "org.mule.extras.wssecurity.callbackhandlers.MuleWsSecurityCallbackHandler");
54          // Property file containing the Encryption properties
55          props.setProperty(WSHandlerConstants.ENC_PROP_FILE, "out-encrypted-security.properties");
56  
57          UMOMessage m = null;
58          try
59          {
60              m = client.send("axis:http://localhost:8282/MySecuredUMO?method=echo", "Test", props);
61          }
62          catch (Exception e)
63          {
64              assertNotNull(e);
65          }
66          assertNull(m);
67      }
68  
69      protected String getConfigResources ()
70      {
71          return "axis-wssecurity-mule-config.xml";
72      }
73  }