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 edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.FilterProcessingException;
21  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.MatchFunctor;
22  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.ShibbolethFilteringContext;
23  
24  /**
25   * Base class for {@link MatchFunctor}s that delegate the evaluation and negate the result if necessary.
26   * 
27   * This class provides an extension point for functionality across all match functors.
28   */
29  public abstract class AbstractMatchFunctor implements MatchFunctor {
30  
31      /** {@inheritDoc} */
32      public boolean evaluatePolicyRequirement(ShibbolethFilteringContext filterContext) throws FilterProcessingException {
33          return doEvaluatePolicyRequirement(filterContext);
34      }
35  
36      /** {@inheritDoc} */
37      public boolean evaluatePermitValue(ShibbolethFilteringContext filterContext, String attributeId,
38              Object attributeValue) throws FilterProcessingException {
39          return doEvaluateValue(filterContext, attributeId, attributeValue);
40      }
41  
42      /** {@inheritDoc} */
43      public boolean evaluateDenyRule(ShibbolethFilteringContext filterContext, String attributeId, Object attributeValue)
44              throws FilterProcessingException {
45          return evaluatePermitValue(filterContext, attributeId, attributeValue);
46      }
47  
48      /**
49       * Evaluates this matching criteria. This evaluation is used while the filtering engine determines policy
50       * applicability.
51       * 
52       * @param filterContext current filtering context
53       * 
54       * @return true if the criteria for this matching function are meant
55       * 
56       * @throws FilterProcessingException thrown if the function can not be evaluated
57       */
58      protected abstract boolean doEvaluatePolicyRequirement(ShibbolethFilteringContext filterContext)
59              throws FilterProcessingException;
60  
61      /**
62       * Evaluates this matching criteria. This evaluation is used while the filtering engine is evaluating either a deny
63       * or permit value rule.
64       * 
65       * @param filterContext the current filtering context
66       * @param attributeId ID of the attribute being evaluated
67       * @param attributeValue value of the attribute being evaluated
68       * 
69       * @return true if the criteria for this matching function are meant
70       * 
71       * @throws FilterProcessingException thrown if the function can not be evaluated
72       */
73      protected abstract boolean doEvaluateValue(ShibbolethFilteringContext filterContext, String attributeId,
74              Object attributeValue) throws FilterProcessingException;
75  }