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 {@link MatchFunctor} that logical ANDs the results of contained functors.
27   */
28  public class AndMatchFunctor 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 AndMatchFunctor(List<MatchFunctor> rules){
39          targetRules = rules;
40      }
41      
42      /**
43       * Gets the functors whose results will be ANDed.
44       * 
45       * @return functors whose results will be ANDed
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              targetRules.isEmpty()) {
57              //
58              // we should treat the null case the same as the empty list. 
59              // Based on a "default deny" we make AND(null) false, (just like
60              // if (null))
61              //
62              return false;
63          }
64  
65          for (MatchFunctor child : targetRules) {
66              if (!child.evaluatePolicyRequirement(filterContext)) {
67                  return false;
68              }
69          }
70  
71          return true;
72      }
73  
74      /** {@inheritDoc} */
75      protected boolean doEvaluateValue(ShibbolethFilteringContext filterContext, String attributeId,
76              Object attributeValue) throws FilterProcessingException {
77          if (targetRules == null ||
78              targetRules.isEmpty()) {
79              //
80              // Treat the null case the same as the empty list. 
81              //
82              return false;
83          }
84  
85          for (MatchFunctor child : targetRules) {
86              if (!child.evaluatePermitValue(filterContext, attributeId, attributeValue)) {
87                  return false;
88              }
89          }
90  
91          return true;
92      }
93  }