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.security.SecurityManager;
11  import org.mule.api.security.SecurityProvider;
12  import org.mule.security.PasswordBasedEncryptionStrategy;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertTrue;
20  
21  public class JaasNamespaceHandlerTestCase extends FunctionalTestCase
22  {
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "jaas-namespace-config.xml";
28      }
29      
30      @Test
31      public void testJaasProvider()
32      {
33          knownProperties(getProvider("jaasSecurityProvider"));
34      }
35  
36      @Test
37      public void testPasswordBasedEncryption()
38      {
39          knownProperties(getEncryptionStrategy("PBE"));
40      }
41      
42      protected SecurityProvider getProvider(String name)
43      {
44          SecurityManager securityManager = muleContext.getSecurityManager();
45          return securityManager.getProvider(name);
46      }
47      
48      protected void knownProperties(SecurityProvider provider)
49      {
50          assertNotNull(provider);
51          assertTrue(provider instanceof JaasSimpleAuthenticationProvider);
52          JaasSimpleAuthenticationProvider jaasProvider = (JaasSimpleAuthenticationProvider) provider;
53          assertNotNull(jaasProvider.getLoginContextName());
54          assertEquals("jaasTest", jaasProvider.getLoginContextName());
55          assertNotNull(jaasProvider.getLoginConfig());
56          assertEquals("jaas.conf", jaasProvider.getLoginConfig());
57      }
58      
59      protected EncryptionStrategy getEncryptionStrategy(String name)
60      {
61          SecurityManager securityManager = muleContext.getSecurityManager();
62          return securityManager.getEncryptionStrategy(name);
63      }
64      
65      protected void knownProperties(EncryptionStrategy encryptionStrategy)
66      {
67          assertNotNull(encryptionStrategy);
68          assertTrue(encryptionStrategy instanceof PasswordBasedEncryptionStrategy);
69          PasswordBasedEncryptionStrategy pbe = (PasswordBasedEncryptionStrategy) encryptionStrategy;
70          assertNotNull(pbe.getName());
71          assertEquals("PBE", pbe.getName());
72      }
73  
74  }
75  
76