1   /*
2    * $Id: XfireSamlTestCase.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.WSConstants;
20  import org.apache.ws.security.handler.WSHandlerConstants;
21  
22  public class XfireSamlTestCase extends FunctionalTestCase
23  {
24      // The test cases have been suppressed because for JDK 1.4, the Xerces parser
25      // must be in an endorsed file for SAML to work. Everything works fine on JDK 1.5
26  
27      public void testBogus () throws Exception
28      {
29          // no test
30      }
31  
32      public void _testGoodUnsignedSamlTokenAuthentication () throws Exception
33      {
34          MuleClient client = new MuleClient();
35          Properties props = new Properties();
36  
37          // Action to perform : saml token
38          props.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.SAML_TOKEN_UNSIGNED);
39          // saml configuration file
40          props.setProperty(WSHandlerConstants.SAML_PROP_FILE, "saml.properties");
41          // Password type : text or digest
42          props.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
43          // User name to send
44          props.setProperty(WSHandlerConstants.USER, "mulealias");
45          // Callback used to retrive password for given user.
46          props.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
47                            "org.mule.extras.wssecurity.callbackhandlers.MuleWsSecurityCallbackHandler");
48  
49          UMOMessage m = client.send("xfire:http://localhost:8282/MySecuredUMO?method=echo", "Test",
50                                     props);
51          assertNotNull(m);
52          assertTrue(m.getPayload() instanceof String);
53          assertTrue(m.getPayload().equals("Test"));
54      }
55  
56      public void _testBadUnsignedSamlTokenAuthentication () throws Exception
57      {
58          MuleClient client = new MuleClient();
59          Properties props = new Properties();
60  
61          // Action to perform : user token
62          props.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
63          // Password type : text or digest
64          props.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
65          // User name to send
66          props.setProperty(WSHandlerConstants.USER, "baduser");
67          // Callback used to retrive password for given user.
68          props.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
69                            "org.mule.extras.wssecurity.callbackhandlers.MuleWsSecurityCallbackHandler");
70  
71          UMOMessage m = null;
72          try
73          {
74              m = client.send("xfire:http://localhost:8282/MySecuredUMO?method=echo", "Test", props);
75          }
76          catch (Exception e)
77          {
78              assertNotNull(e);
79          }
80          assertNull(m);
81      }
82  
83      public void _testGoodSignedSamlTokenAuthentication () throws Exception
84      {
85          MuleClient client = new MuleClient();
86          Properties props = new Properties();
87  
88          // Action to perform : saml token
89          props.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.SAML_TOKEN_SIGNED);
90          // saml configuration file
91          props.setProperty(WSHandlerConstants.SAML_PROP_FILE, "saml.properties");
92          // Password type : text or digest
93          props.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
94          // User name to send
95          props.setProperty(WSHandlerConstants.USER, "mulealias");
96          // Callback used to retrive password for given user.
97          props.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
98                            "org.mule.extras.wssecurity.callbackhandlers.MuleWsSecurityCallbackHandler");
99          // Configuration for accessing private key in keystore
100         props.setProperty(WSHandlerConstants.SIG_PROP_FILE, "out-signed-security.properties");
101         // "IssuerSerial" is not supported
102         props.setProperty(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
103 
104         UMOMessage m = client.send("xfire:http://localhost:8282/MySecuredUMO?method=echo", "Test",
105                                    props);
106         assertNotNull(m);
107         assertTrue(m.getPayload() instanceof String);
108         assertTrue(m.getPayload().equals("Test"));
109     }
110 
111     protected String getConfigResources ()
112     {
113         return "wssecurity-mule-config-for-inbound.xml";
114     }
115 }