View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.jaas;
8   
9   import org.mule.api.EncryptionStrategy;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.config.MuleProperties;
12  import org.mule.module.client.MuleClient;
13  import org.mule.security.MuleCredentials;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  import org.mule.util.SystemUtils;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  
25  public class JaasAuthenticationWithNtLoginModule extends FunctionalTestCase
26  {
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "mule-conf-with-NTLoginModule.xml";
32      }
33  
34      @Override
35      protected boolean isDisabledInThisEnvironment()
36      {
37          return SystemUtils.IS_OS_UNIX;
38      }
39  
40      @Test
41      public void testCaseAuthentication() throws Exception
42      {
43          MuleClient client = new MuleClient(muleContext);
44  
45          Map props = new HashMap();
46          EncryptionStrategy strategy = muleContext
47              .getSecurityManager()
48              .getEncryptionStrategy("PBE");
49          String header = MuleCredentials.createHeader("Marie.Rizzo", "dragon", "PBE", strategy);
50          props.put(MuleProperties.MULE_USER_PROPERTY, header);
51          MuleMessage m = client.send("vm://test", "Test", props);
52  
53          assertNotNull(m);
54          assertTrue(m.getPayload() instanceof String);
55          assertTrue(m.getPayloadAsString().equals("Test Received"));
56      }
57  
58  }