View Javadoc

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