View Javadoc

1   /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.acegisecurity.intercept.web;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  
21  import org.acegisecurity.ConfigAttributeDefinition;
22  import org.acegisecurity.SecurityConfig;
23  
24  /**
25   * <p>
26   * Decorator of {@link FilterInvocationDefinition} for easier configuration,
27   * using {@link FilterInvocationDefinitionSourceMapping}.
28   * </p>
29   * 
30   * <p>
31   * Delegates all calls to decorated object set in constructor
32   * {@link #FilterInvocationDefinitionDecorator(FilterInvocationDefinition)} or
33   * by calling {@link #setDecorated(FilterInvocationDefinition)}
34   * </p>
35   * 
36   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
37   * @version $Id: FilterInvocationDefinitionDecorator.java 1570 2006-07-06 17:05:08Z carlossg $
38   * @since 1.1
39   */
40  public class FilterInvocationDefinitionDecorator implements FilterInvocationDefinition {
41  
42      private FilterInvocationDefinition decorated;
43  
44      private List mappings;
45  
46      public FilterInvocationDefinitionDecorator() {
47      }
48  
49      public FilterInvocationDefinitionDecorator(FilterInvocationDefinition decorated) {
50          this.setDecorated(decorated);
51      }
52  
53      /**
54       * Set the decorated object
55       * 
56       * @param decorated
57       *            the decorated {@link FilterInvocationDefinition}
58       */
59      public void setDecorated(FilterInvocationDefinition decorated) {
60          this.decorated = decorated;
61      }
62  
63      /**
64       * Get decorated object
65       * 
66       * @return the decorated {@link FilterInvocationDefinition}
67       */
68      public FilterInvocationDefinition getDecorated() {
69          return decorated;
70      }
71  
72      /**
73       * Configures the decorated {@link FilterInvocationDefinitionMap} easier,
74       * using {@link FilterInvocationDefinitionSourceMapping}.
75       * 
76       * @param mappings
77       *            {@link List} of
78       *            {@link FilterInvocationDefinitionSourceMapping} objects.
79       */
80      public void setMappings(List mappings) {
81  
82          if (decorated == null) {
83              throw new IllegalStateException("decorated object has not been set");
84          }
85  
86          this.mappings = mappings;
87          Iterator it = mappings.iterator();
88          while (it.hasNext()) {
89              FilterInvocationDefinitionSourceMapping mapping = (FilterInvocationDefinitionSourceMapping) it.next();
90              ConfigAttributeDefinition configDefinition = new ConfigAttributeDefinition();
91  
92              Iterator configAttributesIt = mapping.getConfigAttributes().iterator();
93              while (configAttributesIt.hasNext()) {
94                  String s = (String) configAttributesIt.next();
95                  configDefinition.addConfigAttribute(new SecurityConfig(s));
96              }
97  
98              decorated.addSecureUrl(mapping.getUrl(), configDefinition);
99          }
100     }
101 
102     /**
103      * Get the mappings used for configuration.
104      * 
105      * @return {@link List} of {@link FilterInvocationDefinitionSourceMapping}
106      *         objects.
107      */
108     public List getMappings() {
109         return mappings;
110     }
111 
112     /**
113      * Delegate to decorated object
114      */
115     public void addSecureUrl(String expression, ConfigAttributeDefinition attr) {
116         getDecorated().addSecureUrl(expression, attr);
117     }
118 
119     /**
120      * Delegate to decorated object
121      */
122     public boolean isConvertUrlToLowercaseBeforeComparison() {
123         return getDecorated().isConvertUrlToLowercaseBeforeComparison();
124     }
125 
126     /**
127      * Delegate to decorated object
128      */
129     public void setConvertUrlToLowercaseBeforeComparison(boolean convertUrlToLowercaseBeforeComparison) {
130         getDecorated().setConvertUrlToLowercaseBeforeComparison(convertUrlToLowercaseBeforeComparison);
131     }
132 
133     /**
134      * Delegate to decorated object
135      */
136     public ConfigAttributeDefinition getAttributes(Object object) throws IllegalArgumentException {
137         return getDecorated().getAttributes(object);
138     }
139 
140     /**
141      * Delegate to decorated object
142      */
143     public Iterator getConfigAttributeDefinitions() {
144         return getDecorated().getConfigAttributeDefinitions();
145     }
146 
147     /**
148      * Delegate to decorated object
149      */
150     public boolean supports(Class clazz) {
151         return getDecorated().supports(clazz);
152     }
153 }