View Javadoc

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