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