View Javadoc

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