1   /*
2    * $Id: XfireWsSecurityOnInboundTestCase.java 10165 2007-12-28 11:34:33Z marie.rizzo $ 
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.WSConstants;
20  import org.apache.ws.security.handler.WSHandlerConstants;
21  
22  public class XfireWsSecurityOnInboundTestCase extends FunctionalTestCase
23  {
24      public void testGoodUserNameTokenAuthentication () throws Exception
25      {
26          MuleClient client = new MuleClient();
27          Properties props = new Properties();
28  
29          // Password type : text or digest
30          props.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
31          // User name to send
32          props.setProperty(WSHandlerConstants.USER, "gooduser");
33  
34          UMOMessage m = client.send("Test1", "Test", props);
35          assertNotNull(m);
36          assertTrue(m.getPayload() instanceof String);
37          assertTrue(m.getPayload().equals("Test"));
38      }
39  
40      public void testBadUserNameTokenAuthentication () throws Exception
41      {
42          MuleClient client = new MuleClient();
43          Properties props = new Properties();
44  
45          // Password type : text or digest
46          props.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
47          // User name to send
48          props.setProperty(WSHandlerConstants.USER, "baduser");
49  
50          UMOMessage m = null;
51          try
52          {
53              m = client.send("xfire:http://localhost:8282/MySecuredUMO?connector=WsSecurity&method=echo", "Test", props);
54          }
55          catch (Exception e)
56          {
57              assertNotNull(e);
58          }
59          assertNull(m);
60      }
61  
62      public void testGoodUserNameEncrypted () throws Exception
63      {
64          MuleClient client = new MuleClient();
65          Properties props = new Properties();
66  
67          // User name to send
68          props.setProperty(WSHandlerConstants.USER, "mulealias");
69          // Property file containing the Encryption properties
70          props.setProperty(WSHandlerConstants.ENC_PROP_FILE, "out-encrypted-security.properties");
71  
72          UMOMessage m = client.send("Test3", "Test", props);
73          assertNotNull(m);
74          assertTrue(m.getPayload() instanceof String);
75          assertTrue(m.getPayload().equals("Test"));
76      }
77  
78      public void testBadUserNameEncrypted () throws Exception
79      {
80          MuleClient client = new MuleClient();
81          Properties props = new Properties();
82  
83          // User name to send
84          props.setProperty(WSHandlerConstants.USER, "myBadAlias");
85          // Property file containing the Encryption properties
86          props.setProperty(WSHandlerConstants.ENC_PROP_FILE, "out-encrypted-security.properties");
87  
88          UMOMessage m = null;
89          try
90          {
91              m = client.send("xfire:http://localhost:8282/MySecuredUMO?method=echo", "Test", props);
92          }
93          catch (Exception e)
94          {
95              assertNotNull(e);
96          }
97          assertNull(m);
98      }
99  
100     public void testSignedSoapMessage () throws Exception
101     {
102         MuleClient client = new MuleClient();
103         Properties props = new Properties();
104 
105         // User in keystore
106         props.setProperty(WSHandlerConstants.USER, "mulealias");
107         // Configuration for accessing private key in keystore
108         props.setProperty(WSHandlerConstants.SIG_PROP_FILE, "out-signed-security.properties");
109 
110         UMOMessage m = client.send("Test5", "Test", props);
111         assertNotNull(m);
112         assertTrue(m.getPayload() instanceof String);
113         assertTrue(m.getPayload().equals("Test"));
114     }
115 
116     protected String getConfigResources ()
117     {
118         return "wssecurity-mule-config-for-inbound.xml";
119     }
120 }