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.acegi;
8   
9   import org.mule.api.config.MuleProperties;
10  import org.mule.api.endpoint.ImmutableEndpoint;
11  import org.mule.api.security.SecurityProvider;
12  import org.mule.api.service.Service;
13  import org.mule.module.acegi.filters.http.HttpBasicAuthenticationFilter;
14  import org.mule.security.MuleSecurityManager;
15  import org.mule.service.ServiceCompositeMessageSource;
16  import org.mule.tck.junit4.FunctionalTestCase;
17  
18  import java.util.Collection;
19  
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  
25  public class AcegiAuthenticationNamespaceHandlerTestCase extends FunctionalTestCase
26  {
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "acegi-authentication-config.xml";
32      }
33  
34      @Test
35      public void testSecurityManagerConfigured()
36      {
37          MuleSecurityManager securityManager = 
38              (MuleSecurityManager) muleContext.getRegistry().lookupObject(MuleProperties.OBJECT_SECURITY_MANAGER);
39          assertNotNull(securityManager);
40          
41          Collection providers = securityManager.getProviders();
42          assertEquals(1, providers.size());
43          SecurityProvider provider = (SecurityProvider) providers.iterator().next();
44          assertEquals(AcegiProviderAdapter.class, provider.getClass());
45      }
46      
47      @Test
48      public void testEndpointConfiguration()
49      {
50          Service service = muleContext.getRegistry().lookupService("echo");
51          assertNotNull(service);
52          assertEquals(1, ((ServiceCompositeMessageSource) service.getMessageSource()).getEndpoints().size());
53  
54          ImmutableEndpoint endpoint = (ImmutableEndpoint) ((ServiceCompositeMessageSource) service.getMessageSource()).getEndpoints().get(0);
55          assertNotNull(endpoint.getSecurityFilter());
56          assertEquals(HttpBasicAuthenticationFilter.class, endpoint.getSecurityFilter().getClass());
57      }
58  
59  }