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.config.spring.parsers.specific;
8   
9   import org.mule.api.security.SecurityFilter;
10  import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
11  import org.mule.config.spring.parsers.delegate.ParentContextDefinitionParser;
12  import org.mule.config.spring.parsers.generic.MuleOrphanDefinitionParser;
13  import org.mule.config.spring.parsers.generic.OrphanDefinitionParser;
14  import org.mule.config.spring.parsers.generic.WrappingChildDefinitionParser;
15  import org.mule.processor.SecurityFilterMessageProcessor;
16  
17  import org.w3c.dom.Element;
18  
19  /**
20   * This allows a security filter to be defined globally, or embedded within an endpoint. The filter is
21   * always wrapped in a SecurityFilterMessageProcessorBuilder instance before being injected into the parent.
22   */
23  public class SecurityFilterDefinitionParser extends ParentContextDefinitionParser  implements WrappingChildDefinitionParser.WrappingController
24  {
25  
26      public static final String SECURITY_FILTER = "filter";
27      public static final String ATTRIBUTE_NAME = AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME;
28  
29      public SecurityFilterDefinitionParser(Class filter)
30      {
31          super(MuleOrphanDefinitionParser.ROOT_ELEMENT, new OrphanDefinitionParser(filter, false));
32          otherwise(
33              new WrappingChildDefinitionParser(
34                  "messageProcessor", filter, SecurityFilter.class, false, SecurityFilterMessageProcessor.class,
35                  SECURITY_FILTER, SECURITY_FILTER, this));
36          addIgnored(ATTRIBUTE_NAME);
37      }
38  
39      public SecurityFilterDefinitionParser()
40      {
41          super(MuleOrphanDefinitionParser.ROOT_ELEMENT, new OrphanDefinitionParser(false));
42          otherwise(
43              new WrappingChildDefinitionParser(
44                  "messageProcessor", null, SecurityFilter.class, true, SecurityFilterMessageProcessor.class,
45                  SECURITY_FILTER, SECURITY_FILTER, this));
46          addIgnored(ATTRIBUTE_NAME);
47      }
48  
49      public boolean shouldWrap(Element elm)
50      {
51          return true;
52      }
53  }