View Javadoc

1   /*
2    * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.internet2.middleware.shibboleth.common.config.attribute.filtering;
18  
19  import java.util.List;
20  
21  import org.springframework.beans.factory.config.AbstractFactoryBean;
22  
23  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.AttributeFilterPolicy;
24  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.AttributeRule;
25  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.MatchFunctor;
26  
27  /**
28   * Spring factory for {@link AttributeFilterPolicy}s.
29   */
30  public class AttributeFilterPolicyFactoryBean extends AbstractFactoryBean {
31  
32      /** Unique identifier for this policy. */
33      private String policyId;
34  
35      /** Requirement that must be met for this policy to apply. */
36      private MatchFunctor policyRequirement;
37  
38      /** Filters to be used on attribute values. */
39      private List<AttributeRule> attributeRules;
40  
41      /** {@inheritDoc} */
42      public Class getObjectType() {
43          return AttributeFilterPolicy.class;
44      }
45  
46      /**
47       * Gets the unique ID for this policy.
48       * 
49       * @return unique ID for this policy
50       */
51      public String getPolicyId() {
52          return policyId;
53      }
54  
55      /**
56       * Sets the unique ID for this policy.
57       * 
58       * @param id unique ID for this policy
59       */
60      public void setPolicyId(String id) {
61          policyId = id;
62      }
63  
64      /**
65       * Gets the requirement for this policy.
66       * 
67       * @return requirement for this policy
68       */
69      public MatchFunctor getPolicyRequirement() {
70          return policyRequirement;
71      }
72  
73      /**
74       * Sets the requirement for this policy.
75       * 
76       * @param requirement requirement for this policy
77       */
78      public void setPolicyRequirement(MatchFunctor requirement) {
79          policyRequirement = requirement;
80      }
81  
82      /**
83       * Gets the attribute rules that are in effect if this policy is in effect.
84       * 
85       * @return attribute rules that are in effect if this policy is in effect, never null
86       */
87      public List<AttributeRule> getAttributeRules() {
88          return attributeRules;
89      }
90  
91      /**
92       * Sets the attribute rules that are in effect if this policy is in effect.
93       * 
94       * @param rules attribute rules that are in effect if this policy is in effect
95       */
96      public void setAttributeRules(List<AttributeRule> rules) {
97          attributeRules = rules;
98      }
99  
100     /** {@inheritDoc} */
101     protected Object createInstance() throws Exception {
102         AttributeFilterPolicy policy = new AttributeFilterPolicy(policyId);
103         policy.setPolicyRequirementRule(policyRequirement);
104         policy.getAttributeRules().addAll(attributeRules);
105 
106         return policy;
107     }
108 }