[java-identity-provider] 05/10: IDP-1429 Deprecate ignoreCase for StringMatcher

Rod Widdowson rdw at steadingsoftware.com
Thu Apr 11 08:59:57 EDT 2019


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=8aa58e78ee51b6dd080ef55fe3c6a42579c8652c

commit 8aa58e78ee51b6dd080ef55fe3c6a42579c8652c
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Apr 9 16:24:11 2019 +0100

    IDP-1429 Deprecate ignoreCase for StringMatcher
    
    https://issues.shibboleth.net/jira/browse/IDP-1429
    
    replacement is caseSensitive
---
 .../filter/matcher/impl/AbstractStringMatcher.java | 39 +++++++++++++----
 .../impl/TargettedAttributeValueFilterTest.java    |  2 +-
 .../impl/UntargettedAttributeValueFilterTest.java  |  2 +-
 .../matcher/impl/AbstractStringMatcherTest.java    | 49 ++++++++++++++++++++--
 .../impl/AttributeScopeStringMatcherTest.java      |  2 +-
 .../impl/AttributeValueStringMatcherTest.java      |  2 +-
 6 files changed, 82 insertions(+), 14 deletions(-)

diff --git a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractStringMatcher.java b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractStringMatcher.java
index bc1685d..683b738 100644
--- a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractStringMatcher.java
+++ b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractStringMatcher.java
@@ -20,6 +20,8 @@ package net.shibboleth.idp.attribute.filter.matcher.impl;
 import javax.annotation.Nullable;
 
 import net.shibboleth.idp.attribute.filter.Matcher;
+import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
+import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
 
 /**
  * General {@link Matcher} for {@link String} comparison of strings in Attribute Filters.   
@@ -30,7 +32,7 @@ public abstract class AbstractStringMatcher extends AbstractMatcher implements M
     private String matchString;
 
     /** Whether the match evaluation is case sensitive. */
-    private boolean ignoreCase = true;
+    private boolean caseSensitive;
 
     /**
      * Gets the string to match for a positive evaluation.
@@ -54,21 +56,44 @@ public abstract class AbstractStringMatcher extends AbstractMatcher implements M
      * Gets whether the match evaluation is case insensitive.
      * 
      * @return whether the match evaluation is case insensitive
+     * @deprecated in V4: Use isCaseSensitive
      */
     public boolean isIgnoreCase() {
-        return ignoreCase;
+        DeprecationSupport.warnOnce(ObjectType.METHOD, "isIgnoreCase", null, "isCaseSensitive");
+        return !isCaseSensitive();
     }
 
     /**
      * Sets whether the match evaluation is case insensitive.
      * 
-     * @param isCaseInsensitive whether the match evaluation is case sensitive
+     * @param isCaseInsensitive whether the match evaluation is case insensitive
+     * @deprecated in V4: Use setCaseSensitive
      */
     public void setIgnoreCase(final boolean isCaseInsensitive) {
-        ignoreCase = isCaseInsensitive;
+        DeprecationSupport.warnOnce(ObjectType.METHOD, "setIgnoreCase", null, "setCaseSensitive");
+        setCaseSensitive(!isCaseInsensitive);
     }
     
     /**
+     * Gets whether the match evaluation is case sensitive.
+     * 
+     * @return whether the match evaluation is case sensitive
+     */
+    public boolean isCaseSensitive() {
+        return caseSensitive;
+    }
+
+    /**
+     * Sets whether the match evaluation is case sensitive.
+     * 
+     * @param isCaseSensitive whether the match evaluation is case sensitive
+     */
+    public void setCaseSensitive(final boolean isCaseSensitive) {
+        caseSensitive = isCaseSensitive;
+    }
+
+    
+    /**
      * Matches the given value against the provided match string. 
      * 
      * @param value the value to evaluate
@@ -80,10 +105,10 @@ public abstract class AbstractStringMatcher extends AbstractMatcher implements M
             return matchString == null;
         }
 
-        if (ignoreCase) {
-            return value.equalsIgnoreCase(matchString);
-        } else {
+        if (isCaseSensitive()) {
             return value.equals(matchString);
+        } else {
+            return value.equalsIgnoreCase(matchString);
         }
     }
 }
diff --git a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/complex/impl/TargettedAttributeValueFilterTest.java b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/complex/impl/TargettedAttributeValueFilterTest.java
index ca99642..169d4c5 100644
--- a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/complex/impl/TargettedAttributeValueFilterTest.java
+++ b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/complex/impl/TargettedAttributeValueFilterTest.java
@@ -54,7 +54,7 @@ public class TargettedAttributeValueFilterTest extends BaseComplexAttributeFilte
     private Matcher valueMatcher() {
         AttributeValueStringMatcher retVal = new AttributeValueStringMatcher();
 
-        retVal.setIgnoreCase(false);
+        retVal.setCaseSensitive(true);
         retVal.setMatchString("jsmith");
         retVal.setId("Test");
         try {
diff --git a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/complex/impl/UntargettedAttributeValueFilterTest.java b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/complex/impl/UntargettedAttributeValueFilterTest.java
index 45c5cc9..abc0038 100644
--- a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/complex/impl/UntargettedAttributeValueFilterTest.java
+++ b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/complex/impl/UntargettedAttributeValueFilterTest.java
@@ -51,7 +51,7 @@ public class UntargettedAttributeValueFilterTest extends BaseComplexAttributeFil
     private Matcher valueMatcher() {
         AttributeValueStringMatcher retVal = new AttributeValueStringMatcher();
 
-        retVal.setIgnoreCase(false);
+        retVal.setCaseSensitive(true);
         retVal.setMatchString("jsmith");
         
         retVal.setId("valueMatcher");
diff --git a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractStringMatcherTest.java b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractStringMatcherTest.java
index 30e53c1..ba0ed09 100644
--- a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractStringMatcherTest.java
+++ b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractStringMatcherTest.java
@@ -22,6 +22,7 @@ import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
+import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import net.shibboleth.idp.attribute.IdPAttributeValue;
@@ -40,7 +41,48 @@ public class AbstractStringMatcherTest {
             }};
 
         assertNull(matcher.getMatchString());
-        assertFalse(!matcher.isIgnoreCase());
+        assertFalse(matcher.isCaseSensitive());
+
+        matcher.setCaseSensitive(true);
+        assertTrue(matcher.isCaseSensitive());
+        matcher.setCaseSensitive(false);
+        assertFalse(matcher.isCaseSensitive());
+
+        matcher.setMatchString(DataSources.TEST_STRING);
+        assertEquals(matcher.getMatchString(), DataSources.TEST_STRING);
+    }
+
+    @Test public void testApply() {
+        AbstractStringMatcher matcher = new AbstractStringMatcher() {
+
+            @Override
+            protected boolean compareAttributeValue(IdPAttributeValue value) {
+                return false;
+            }};
+        matcher.setCaseSensitive(true);
+        matcher.setMatchString(DataSources.TEST_STRING);
+
+        assertTrue(matcher.stringCompare(DataSources.TEST_STRING));
+        assertFalse(matcher.stringCompare(DataSources.TEST_STRING_UPPER));
+        matcher.setCaseSensitive(false);
+        assertTrue(matcher.stringCompare(DataSources.TEST_STRING));
+        assertTrue(matcher.stringCompare(DataSources.TEST_STRING_UPPER));
+        
+        assertFalse(matcher.stringCompare(null));
+    }
+
+    @SuppressWarnings("deprecation")
+    @Test public void testDeprecatedSettersGetters() {
+        AbstractStringMatcher matcher = new AbstractStringMatcher(){
+
+            @Override
+            protected boolean compareAttributeValue(IdPAttributeValue value) {
+                return false;
+            }};
+
+        Assert.assertNull(matcher.getMatchString());
+        Assert.assertFalse(!matcher.isIgnoreCase());
+        Assert.assertFalse(matcher.isCaseSensitive());
 
         matcher.setIgnoreCase(false);
         assertFalse(matcher.isIgnoreCase());
@@ -51,7 +93,8 @@ public class AbstractStringMatcherTest {
         assertEquals(matcher.getMatchString(), DataSources.TEST_STRING);
     }
 
-    @Test public void testApply() {
+    @SuppressWarnings("deprecation")
+    @Test public void testDeprecatedApply() {
         AbstractStringMatcher matcher = new AbstractStringMatcher() {
 
             @Override
@@ -69,6 +112,6 @@ public class AbstractStringMatcherTest {
         
         assertFalse(matcher.stringCompare(null));
     }
-    
+
 
 }
diff --git a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AttributeScopeStringMatcherTest.java b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AttributeScopeStringMatcherTest.java
index 0667049..d8bc1cc 100644
--- a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AttributeScopeStringMatcherTest.java
+++ b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AttributeScopeStringMatcherTest.java
@@ -31,7 +31,7 @@ public class AttributeScopeStringMatcherTest {
     
     @Test public void testApply() throws ComponentInitializationException {
         AttributeScopeStringMatcher matcher = new AttributeScopeStringMatcher();
-        matcher.setIgnoreCase(true);
+        matcher.setCaseSensitive(false);
         matcher.setMatchString(DataSources.TEST_STRING);
         matcher.setId("Test");
         matcher.initialize();
diff --git a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AttributeValueStringMatcherTest.java b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AttributeValueStringMatcherTest.java
index 9dd4bfd..546e02b 100644
--- a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AttributeValueStringMatcherTest.java
+++ b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/AttributeValueStringMatcherTest.java
@@ -32,7 +32,7 @@ public class AttributeValueStringMatcherTest {
     
     @Test public void testApply() throws ComponentInitializationException {
         AttributeValueStringMatcher matcher = new AttributeValueStringMatcher();
-        matcher.setIgnoreCase(true);
+        matcher.setCaseSensitive(false);
         matcher.setMatchString(DataSources.TEST_STRING);
         matcher.setId("Test");
         matcher.initialize();

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list