1   /*
2    * $Id: AxisMultipleConnectorsWSSecurityTestCase.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 AxisMultipleConnectorsWSSecurityTestCase extends FunctionalTestCase
22  {
23      
24      public AxisMultipleConnectorsWSSecurityTestCase()
25      {
26          super();
27          this.setDisposeManagerPerSuite(true);
28      }
29      
30      public void testAxisAuthentication() throws Exception
31      {
32          // Action to perform : Signature
33          Properties props = new Properties();
34  
35          // Action to perform : user token
36          props.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
37          // User name to send
38          props.setProperty(WSHandlerConstants.USER, "mulealias");
39          // Callback used to retrive password for given user.
40          props.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, "org.mule.extras.wssecurity.callbackhandlers.MuleWsSecurityCallbackHandler");
41          // Property file containing the Encryption properties
42          props.setProperty(WSHandlerConstants.ENC_PROP_FILE, "out-encrypted-security.properties");
43  
44          // Set signature method to DirectReference
45          props.setProperty(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
46  
47          props.setProperty(WSHandlerConstants.USE_REQ_SIG_CERT, "false");
48  
49          UMOMessage result = null;
50  
51          MuleClient client = new MuleClient();
52          result = client.send("vm://secured", "Inputgot", props);
53          assertNotNull(result.getPayload());
54          assertTrue(result.getPayloadAsString().equalsIgnoreCase("inputgot"));
55          System.out.println("Message Echoed is: " + result.getPayload().toString());
56      }
57      
58      public void testUnsecuredWS1() throws Exception
59      {
60          unsecuredWS("vm://unsecured1", "unsecure1");
61      }
62      
63      public void testUnsecuredWS2() throws Exception
64      {
65          unsecuredWS("vm://unsecured2", "unsecure2");
66      }
67      
68      public void unsecuredWS(String endpoint, String message) throws Exception
69      {
70          MuleClient client = new MuleClient();
71          UMOMessage result = client.send(endpoint, message, null);
72          assertNotNull(result.getPayload());
73          assertTrue(result.getPayloadAsString().equalsIgnoreCase(message));
74      }
75  
76      protected String getConfigResources()
77      {
78          return "axis-multiple-connectors.xml";
79      }
80  
81  }
82  
83