[java-identity-provider] 03/04: IDP-1429 Add caseSensitive to all regexp filters
Rod Widdowson
rdw at steadingsoftware.com
Thu Apr 11 11:19:40 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=f51bd4268969cb4e4573be70874f882f2d780e10
commit f51bd4268969cb4e4573be70874f882f2d780e10
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Apr 11 16:09:47 2019 +0100
IDP-1429 Add caseSensitive to all regexp filters
https://issues.shibboleth.net/jira/browse/IDP-1429
As per the regexp split attribute resolver the heavy lifting is done in the parsers.
---
.../matcher/impl/AbstractRegexMatcherParser.java | 12 +++++++++-
.../impl/AbstractRegexPolicyRuleParser.java | 12 +++++++++-
.../matcher/AttributeRegexMatcherParserTest.java | 24 ++++++++++++++++++-
.../AttributeRequesterRegexRuleParserTest.java | 27 ++++++++++++++++++++++
.../attribute/filter/matcher/attributeRegex.xml | 2 +-
...Regex.xml => attributeRegexCaseInsensitive.xml} | 3 +--
.../filter/policyrule/attributeRegexRequester.xml | 2 +-
... => attributeRegexRequesterCaseInsensitive.xml} | 2 +-
.../src/main/resources/schema/shibboleth-afp.xsd | 5 ++++
9 files changed, 81 insertions(+), 8 deletions(-)
diff --git a/idp-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/matcher/impl/AbstractRegexMatcherParser.java b/idp-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/matcher/impl/AbstractRegexMatcherParser.java
index 73487c6..8ce9851 100644
--- a/idp-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/matcher/impl/AbstractRegexMatcherParser.java
+++ b/idp-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/matcher/impl/AbstractRegexMatcherParser.java
@@ -19,6 +19,7 @@ package net.shibboleth.idp.attribute.filter.spring.matcher.impl;
import javax.annotation.Nonnull;
+import net.shibboleth.ext.spring.factory.PatternFactoryBean;
import net.shibboleth.idp.attribute.filter.spring.matcher.BaseAttributeValueMatcherParser;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
@@ -42,7 +43,16 @@ public abstract class AbstractRegexMatcherParser extends BaseAttributeValueMatch
if (null == regexp) {
throw new BeanCreationException("Regexp Attribute filter: No text provided to 'regex' attribute.");
}
+
+ final BeanDefinitionBuilder pattern = BeanDefinitionBuilder.genericBeanDefinition(PatternFactoryBean.class);
- builder.addPropertyValue("regularExpression", regexp);
+ pattern.addPropertyValue("regexp", regexp);
+
+ if (config.hasAttributeNS(null, "caseSensitive")) {
+ pattern.addPropertyValue("caseSensitive",
+ StringSupport.trimOrNull(config.getAttributeNS(null, "caseSensitive")));
+ }
+
+ builder.addPropertyValue("pattern", pattern.getBeanDefinition());
}
}
\ No newline at end of file
diff --git a/idp-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/policyrule/impl/AbstractRegexPolicyRuleParser.java b/idp-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/policyrule/impl/AbstractRegexPolicyRuleParser.java
index 3e26d49..11d2939 100644
--- a/idp-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/policyrule/impl/AbstractRegexPolicyRuleParser.java
+++ b/idp-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/policyrule/impl/AbstractRegexPolicyRuleParser.java
@@ -19,6 +19,7 @@ package net.shibboleth.idp.attribute.filter.spring.policyrule.impl;
import javax.annotation.Nonnull;
+import net.shibboleth.ext.spring.factory.PatternFactoryBean;
import net.shibboleth.idp.attribute.filter.spring.policyrule.BasePolicyRuleParser;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
@@ -43,6 +44,15 @@ public abstract class AbstractRegexPolicyRuleParser extends BasePolicyRuleParser
throw new BeanCreationException("Regexp Attribute filter: No text provided to 'regex' attribute.");
}
- builder.addPropertyValue("regularExpression", regexp);
+ final BeanDefinitionBuilder pattern = BeanDefinitionBuilder.genericBeanDefinition(PatternFactoryBean.class);
+
+ pattern.addPropertyValue("regexp", regexp);
+
+ if (config.hasAttributeNS(null, "caseSensitive")) {
+ pattern.addPropertyValue("caseSensitive",
+ StringSupport.trimOrNull(config.getAttributeNS(null, "caseSensitive")));
+ }
+
+ builder.addPropertyValue("pattern", pattern.getBeanDefinition());
}
}
\ No newline at end of file
diff --git a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/matcher/AttributeRegexMatcherParserTest.java b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/matcher/AttributeRegexMatcherParserTest.java
index 6174edf..39298e3 100644
--- a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/matcher/AttributeRegexMatcherParserTest.java
+++ b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/matcher/AttributeRegexMatcherParserTest.java
@@ -18,9 +18,13 @@
package net.shibboleth.idp.attribute.filter.spring.matcher;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
+import net.shibboleth.idp.attribute.IdPAttributeValue;
+import net.shibboleth.idp.attribute.StringAttributeValue;
import net.shibboleth.idp.attribute.filter.matcher.impl.AttributeValueRegexpMatcher;
import net.shibboleth.idp.attribute.filter.spring.BaseAttributeFilterParserTest;
import net.shibboleth.idp.attribute.filter.spring.matcher.impl.AttributeValueRegexMatcherParser;
@@ -30,11 +34,29 @@ import net.shibboleth.utilities.java.support.component.ComponentInitializationEx
* test for {@link AttributeValueRegexMatcherParser}.
*/
public class AttributeRegexMatcherParserTest extends BaseAttributeFilterParserTest {
+
+ private void testMatcher(final AttributeValueRegexpMatcher what, boolean caseSensitive) {
+ IdPAttributeValue<String> upper = new StringAttributeValue("JSMITH");
+ IdPAttributeValue<String> lower = new StringAttributeValue("jsmith");
+ IdPAttributeValue<String> nonmatch = new StringAttributeValue("NONONONO");
+
+ assertTrue(what.compareAttributeValue(lower));
+ assertFalse(what.compareAttributeValue(nonmatch));
+ assertEquals(what.compareAttributeValue(upper), !caseSensitive);
+ }
@Test public void matcher() throws ComponentInitializationException {
AttributeValueRegexpMatcher what = (AttributeValueRegexpMatcher) getMatcher("attributeRegex.xml");
assertEquals(what.getRegularExpression(), "^jsmit.*$");
-
+ testMatcher(what, true);
}
+
+ @Test public void testCase() throws ComponentInitializationException {
+ AttributeValueRegexpMatcher what = (AttributeValueRegexpMatcher) getMatcher("attributeRegexCaseInsensitive.xml");
+
+ assertEquals(what.getRegularExpression(), "^jsmit.*$");
+ testMatcher(what, false);
+ }
+
}
diff --git a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/policy/AttributeRequesterRegexRuleParserTest.java b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/policy/AttributeRequesterRegexRuleParserTest.java
index 1cc4481..bab7d7b 100644
--- a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/policy/AttributeRequesterRegexRuleParserTest.java
+++ b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/policy/AttributeRequesterRegexRuleParserTest.java
@@ -21,17 +21,44 @@ import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
+import net.shibboleth.idp.attribute.filter.PolicyRequirementRule.Tristate;
+import net.shibboleth.idp.attribute.filter.context.AttributeFilterContext;
import net.shibboleth.idp.attribute.filter.policyrule.filtercontext.impl.AttributeRequesterRegexpPolicyRule;
import net.shibboleth.idp.attribute.filter.spring.BaseAttributeFilterParserTest;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
public class AttributeRequesterRegexRuleParserTest extends BaseAttributeFilterParserTest {
+
+ private void testPolicy(final AttributeRequesterRegexpPolicyRule what, boolean caseSensitive) {
+ final AttributeFilterContext context = new AttributeFilterContext();
+ context.setAttributeRecipientID("urn:example:test:thing");
+ assertEquals(what.matches(context), Tristate.TRUE);
+ context.setAttributeRecipientID("NONONONO");
+ assertEquals(what.matches(context), Tristate.FALSE);
+
+ context.setAttributeRecipientID("URN:EXAMPLE:TEST:example:test:thing");
+ if (caseSensitive) {
+ assertEquals(what.matches(context), Tristate.FALSE);
+ } else {
+ assertEquals(what.matches(context), Tristate.TRUE);
+ }
+ }
@Test public void policy() throws ComponentInitializationException {
AttributeRequesterRegexpPolicyRule arRule = (AttributeRequesterRegexpPolicyRule) getPolicyRule("attributeRegexRequester.xml");
assertEquals(arRule.getRegularExpression(), "^urn:example:.*$");
+ testPolicy(arRule, true);
+ }
+
+
+ @Test public void testCase() throws ComponentInitializationException {
+
+ AttributeRequesterRegexpPolicyRule arRule = (AttributeRequesterRegexpPolicyRule) getPolicyRule("attributeRegexRequesterCaseInsensitive.xml");
+ assertEquals(arRule.getRegularExpression(), "^urn:example:.*$");
+ testPolicy(arRule, false);
}
+
}
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegex.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegex.xml
index 280bded..0b7f242 100644
--- a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegex.xml
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegex.xml
@@ -2,6 +2,6 @@
xmlns="urn:mace:shibboleth:2.0:afp"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
- <PermitValueRule xsi:type="ValueRegex"
+ <PermitValueRule xsi:type="ValueRegex" caseSensitive="true"
regex="^jsmit.*$" />
</AttributeRule>
\ No newline at end of file
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegex.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegexCaseInsensitive.xml
similarity index 71%
copy from idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegex.xml
copy to idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegexCaseInsensitive.xml
index 280bded..476d7ad 100644
--- a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegex.xml
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeRegexCaseInsensitive.xml
@@ -2,6 +2,5 @@
xmlns="urn:mace:shibboleth:2.0:afp"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
- <PermitValueRule xsi:type="ValueRegex"
- regex="^jsmit.*$" />
+ <PermitValueRule xsi:type="ValueRegex" regex="^jsmit.*$" caseSensitive="false" />
</AttributeRule>
\ No newline at end of file
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequester.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequester.xml
index ac8d799..ed82e50 100644
--- a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequester.xml
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequester.xml
@@ -1,4 +1,4 @@
<AttributeFilterPolicy id="MostBasicExample" xmlns="urn:mace:shibboleth:2.0:afp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
- <PolicyRequirementRule xsi:type="RequesterRegex" regex="^urn:example:.*$" />
+ <PolicyRequirementRule xsi:type="RequesterRegex" regex="^urn:example:.*$" caseSensitive="true" />
</AttributeFilterPolicy>
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequester.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequesterCaseInsensitive.xml
similarity index 89%
copy from idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequester.xml
copy to idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequesterCaseInsensitive.xml
index ac8d799..07c0dae 100644
--- a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequester.xml
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/attributeRegexRequesterCaseInsensitive.xml
@@ -1,4 +1,4 @@
<AttributeFilterPolicy id="MostBasicExample" xmlns="urn:mace:shibboleth:2.0:afp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
- <PolicyRequirementRule xsi:type="RequesterRegex" regex="^urn:example:.*$" />
+ <PolicyRequirementRule xsi:type="RequesterRegex" regex="^urn:example:.*$" caseSensitive="false" />
</AttributeFilterPolicy>
diff --git a/idp-schema/src/main/resources/schema/shibboleth-afp.xsd b/idp-schema/src/main/resources/schema/shibboleth-afp.xsd
index cddaf3c..a0041ce 100644
--- a/idp-schema/src/main/resources/schema/shibboleth-afp.xsd
+++ b/idp-schema/src/main/resources/schema/shibboleth-afp.xsd
@@ -497,6 +497,11 @@
<documentation>The regular expression values are matched against.</documentation>
</annotation>
</attribute>
+ <attribute name="caseSensitive" type="string">
+ <annotation>
+ <documentation>Whether the comparison is case sensitive, default TRUE</documentation>
+ </annotation>
+ </attribute>
</extension>
</complexContent>
</complexType>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list