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.attribute.filtering.provider.match.basic;
19  
20  import java.util.List;
21  
22  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.FilterProcessingException;
23  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.MatchFunctor;
24  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.ShibbolethFilteringContext;
25  
26  /**
27   * A match function that logical ORs the results of contained functors.
28   */
29  public class OrMatchFunctor extends AbstractMatchFunctor {
30  
31      /** Contained functors. */
32      private List<MatchFunctor> targetRules;
33      
34      /**
35       * Constructor.
36       *
37       * @param rules rules to AND together
38       */
39      public OrMatchFunctor(List<MatchFunctor> rules){
40          targetRules = rules;
41      }
42  
43      /**
44       * Gets the functors whose results will be ORed.
45       * 
46       * @return functors whose results will be ORed
47       */
48      public List<MatchFunctor> getTargetRules() {
49          return targetRules;
50      }
51  
52      /** {@inheritDoc} */
53      protected boolean doEvaluatePolicyRequirement(ShibbolethFilteringContext filterContext)
54              throws FilterProcessingException {
55  
56          if (targetRules == null) {
57              //
58              // we should treat the null case the same as the empty list OR(null == OR({}) == FALSE
59              //
60              return false;
61          }
62  
63          for (MatchFunctor child : targetRules) {
64              if (child.evaluatePolicyRequirement(filterContext)) {
65                  return true;
66              }
67          }
68  
69          return false;
70      }
71  
72      /** {@inheritDoc} */
73      protected boolean doEvaluateValue(ShibbolethFilteringContext filterContext, String attributeId,
74              Object attributeValue) throws FilterProcessingException {
75          if (targetRules == null) {
76              return false;
77          }
78  
79          for (MatchFunctor child : targetRules) {
80              if (child.evaluatePermitValue(filterContext, attributeId, attributeValue)) {
81                  return true;
82              }
83          }
84  
85          return false;
86      }
87  }