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 edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.FilterProcessingException;
20  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.MatchFunctor;
21  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.ShibbolethFilteringContext;
22  
23  /**
24   * A match functor that performs a logical NOT on the result of another functor.
25   */
26  public class NotMatchFunctor extends AbstractMatchFunctor {
27  
28      /** Match functor to negate. */
29      private MatchFunctor targetRule;
30      
31      /**
32       * Constructor.
33       *
34       * @param rule rule to NOT
35       */
36      public NotMatchFunctor(MatchFunctor rule){
37          targetRule = rule;
38      }
39  
40      /**
41       * Gets the match functor that will be the target of the logical NOT.
42       * 
43       * @return match functor that will be the target of the logical NOT
44       */
45      public MatchFunctor getTargetRule() {
46          return targetRule;
47      }
48  
49      /**
50       * Sets the match functor that will be the target of the logical NOT.
51       * 
52       * @param target match functor that will be the target of the logical NOT
53       */
54      public void setTargetRule(MatchFunctor target) {
55          targetRule = target;
56      }
57  
58      /** {@inheritDoc} */
59      protected boolean doEvaluateValue(ShibbolethFilteringContext filterContext, String attributeId,
60              Object attributeValue) throws FilterProcessingException {
61          return !targetRule.evaluatePermitValue(filterContext, attributeId, attributeValue);
62      }
63  
64      /** {@inheritDoc} */
65      protected boolean doEvaluatePolicyRequirement(ShibbolethFilteringContext filterContext)
66              throws FilterProcessingException {
67          return !targetRule.evaluatePolicyRequirement(filterContext);
68      }
69  }