View Javadoc

1   /*
2    * $Id: AbstractJaasFunctionalTestCase.java 22526 2011-07-22 11:13:49Z justin.calleja $
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.module.jaas;
12  
13  import java.util.HashMap;
14  import java.util.Map;
15  
16  import org.mule.api.EncryptionStrategy;
17  import org.mule.api.config.MuleProperties;
18  import org.mule.api.security.CryptoFailureException;
19  import org.mule.security.MuleCredentials;
20  import org.mule.tck.AbstractServiceAndFlowTestCase;
21  
22  public abstract class AbstractJaasFunctionalTestCase extends AbstractServiceAndFlowTestCase
23  {
24      public AbstractJaasFunctionalTestCase(ConfigVariant variant, String configResources)
25      {
26          super(variant, configResources);
27      }
28  
29      protected Map<String, Object> createMessagePropertiesWithCredentials(String username, String password)
30          throws CryptoFailureException
31      {
32          Map<String, Object> props = new HashMap<String, Object>();
33          String header = createEncryptedHeader(username, password);
34          props.put(MuleProperties.MULE_USER_PROPERTY, header);
35          return props;
36      }
37  
38      private String createEncryptedHeader(String username, String password) throws CryptoFailureException
39      {
40          EncryptionStrategy strategy = muleContext.getSecurityManager().getEncryptionStrategy("PBE");
41          return MuleCredentials.createHeader(username, password, "PBE", strategy);
42      }
43  }