View Javadoc

1   /*
2    * $Id: MultiuserSecurityTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.security;
12  
13  import org.mule.api.EncryptionStrategy;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.config.MuleProperties;
16  import org.mule.api.transport.SessionHandler;
17  import org.mule.module.client.MuleClient;
18  import org.mule.session.MuleSessionHandler;
19  import org.mule.tck.FunctionalTestCase;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  /**
25   * Tests multi-user security against a security provider which only authenticates 
26   * a single user at a time (i.e., authentication of a new user overwrites the 
27   * previous authentication).  
28   * 
29   * see EE-979
30   */
31  public class MultiuserSecurityTestCase extends FunctionalTestCase
32  {
33      protected String getConfigResources()
34      {
35          return "multiuser-security-test.xml, singleuser-security-provider.xml";
36      }
37  
38      public void testMultipleAuthentications() throws Exception
39      {
40          MuleClient client = new MuleClient(muleContext);
41          SessionHandler sessionHandler = new MuleSessionHandler();
42          MuleMessage reply;
43          Map props;
44  
45          EncryptionStrategy strategy = muleContext.getSecurityManager().getEncryptionStrategy("PBE");
46          
47          props = new HashMap();
48          props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("marie", "marie", "PBE", strategy));
49          reply = client.send("vm://test", "Data1", props);
50          assertNotNull(reply);
51          assertEquals("user = marie, logins = 1, color = bright red", reply.getPayload());
52  
53          props = new HashMap();
54          props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("stan", "stan", "PBE", strategy));
55          reply = client.send("vm://test", "Data2", props);
56          assertNotNull(reply);
57          assertEquals("user = stan, logins = 1, color = metallic blue", reply.getPayload());
58          
59          props = new HashMap();
60          props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("cindy", "cindy", "PBE", strategy));
61          reply = client.send("vm://test", "Data3", props);
62          assertEquals("user = cindy, logins = 1, color = dark violet", reply.getPayload());
63  
64          props = new HashMap();
65          props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("marie", "marie", "PBE", strategy));
66          reply = client.send("vm://test", "Data4", props);
67          assertNotNull(reply);
68          assertEquals("user = marie, logins = 2, color = bright red", reply.getPayload());
69  
70          props = new HashMap();
71          props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("marie", "marie", "PBE", strategy));
72          reply = client.send("vm://test", "Data4", props);
73          assertNotNull(reply);
74          assertEquals("user = marie, logins = 3, color = bright red", reply.getPayload());
75  
76          props = new HashMap();
77          props.put(MuleProperties.MULE_USER_PROPERTY, MuleCredentials.createHeader("stan", "stan", "PBE", strategy));
78          reply = client.send("vm://test", "Data2", props);
79          assertNotNull(reply);
80          assertEquals("user = stan, logins = 2, color = metallic blue", reply.getPayload());        
81      }
82  }