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.BaseAttribute;
20  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.FilterProcessingException;
21  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.ShibbolethFilteringContext;
22  
23  /**
24   * A match function that evaluates an attribute's value against the provided regular expression.
25   */
26  public class AttributeValueRegexMatchFunctor extends AbstractAttributeTargetedRegexMatchFunctor {
27  
28      /**
29       * Evaluates to true if any value for the specified attribute matches the provided regular expression.
30       * 
31       * {@inheritDoc}
32       */
33      protected boolean doEvaluatePolicyRequirement(ShibbolethFilteringContext filterContext)
34              throws FilterProcessingException {
35          BaseAttribute attribute = filterContext.getUnfilteredAttributes().get(getAttributeId());
36          
37          if (attribute != null && attribute.getValues() != null) {
38              for (Object value : attribute.getValues()) {
39                  if (isMatch(value)) {
40                      return true;
41                  }
42              }
43          }
44          return false;
45      }
46  
47      /**
48       * Evaluates to true if the given attribute value matches the provided regular expression.
49       * 
50       * {@inheritDoc}
51       */
52      protected boolean doEvaluateValue(ShibbolethFilteringContext filterContext, String id, Object attributeValue)
53              throws FilterProcessingException {
54  
55          return isMatch(attributeValue);
56      }
57  }