View Javadoc

1   /*
2    * $Id$
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.test.config;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.endpoint.EndpointBuilder;
15  import org.mule.api.endpoint.InboundEndpoint;
16  import org.mule.api.lifecycle.InitialisationException;
17  import org.mule.api.processor.MessageProcessor;
18  import org.mule.processor.SecurityFilterMessageProcessor;
19  import org.mule.security.AbstractEndpointSecurityFilter;
20  import org.mule.security.filters.MuleEncryptionEndpointSecurityFilter;
21  import org.mule.tck.FunctionalTestCase;
22  
23  import java.util.List;
24  
25  /**
26   * Test configuration of security filters
27   */
28  public class SecurityFilterTestCase extends FunctionalTestCase
29  {
30      @Override
31      protected String getConfigResources()
32      {
33          return "org/mule/test/config/security-filter-config.xml";
34      }
35  
36      public void testConfig() throws Exception
37      {
38          EndpointBuilder epb = muleContext.getRegistry().lookupEndpointBuilder("testEndpoint1");
39          assertNotNull(epb);
40          InboundEndpoint iep = epb.buildInboundEndpoint();
41          List<MessageProcessor> mps =iep.getMessageProcessors();
42          int count = 0;
43          SecurityFilterMessageProcessor securityMp = null;
44          for (MessageProcessor mp : mps)
45          {
46              if (mp instanceof SecurityFilterMessageProcessor)
47              {
48                  count++;
49                  securityMp = (SecurityFilterMessageProcessor) mp;
50              }
51          }
52          assertEquals(1, count);
53          assertEquals(CustomSecurityFilter.class, securityMp.getFilter().getClass());
54  
55          epb = muleContext.getRegistry().lookupEndpointBuilder("testEndpoint2");
56          assertNotNull(epb);
57          iep = epb.buildInboundEndpoint();
58          mps =iep.getMessageProcessors();
59          count = 0;
60          securityMp = null;
61          for (MessageProcessor mp : mps)
62          {
63              if (mp instanceof SecurityFilterMessageProcessor)
64              {
65                  count++;
66                  securityMp = (SecurityFilterMessageProcessor) mp;
67              }
68          }
69          assertEquals(1, count);
70          assertEquals(MuleEncryptionEndpointSecurityFilter.class, securityMp.getFilter().getClass());        
71      }
72  
73      /**
74       * Custom security filter class that does nothing at all
75       */
76      public static class CustomSecurityFilter extends AbstractEndpointSecurityFilter
77      {
78          @Override
79          protected void authenticateInbound(MuleEvent event)
80          {
81          }
82  
83          @Override
84          protected void authenticateOutbound(MuleEvent event)
85          {
86          }
87  
88          @Override
89          protected void doInitialise() throws InitialisationException
90          {
91          }
92      }
93  
94  }