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