View Javadoc

1   /*
2    * Copyright 2011 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.saml;
18  
19  import java.util.regex.Matcher;
20  import java.util.regex.Pattern;
21  
22  import org.opensaml.xml.util.DatatypeHelper;
23  
24  /**
25   * Base class for match functors that perform an regular expression match of a given attribute string value against
26   * entity attribute value.
27   */
28  public abstract class AbstractEntityAttributeRegexMatchFunctor extends AbstractEntityAttributeMatchFunctor {
29  
30      /** The value of the entity attribute the entity must have. */
31      private Pattern valueRegex;
32  
33      /**
34       * Gets the value of the entity attribute the entity must have.
35       * 
36       * @return value of the entity attribute the entity must have
37       */
38      public Pattern getValueRegex() {
39          return valueRegex;
40      }
41  
42      /**
43       * Sets the value of the entity attribute the entity must have.
44       * 
45       * @param attributeValueRegex value of the entity attribute the entity must have
46       */
47      public void setValueRegex(Pattern attributeValueRegex) {
48          valueRegex = attributeValueRegex;
49      }
50  
51      /** {@inheritDoc} */
52      protected boolean entityAttributeValueMatches(String entityAttributeValue) {
53          Matcher valueMatcher = valueRegex.matcher(DatatypeHelper.safeTrim(entityAttributeValue));
54          return valueMatcher.matches();
55      }
56  }