View Javadoc

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