[java-identity-provider COMMIT] in /trunk: idp-saml-api/src/main/java/net/shibboleth/idp/saml/xmlobject/Scope.java id...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Jan 13 21:35:37 EST 2016
Author: putmanb
Date: Wed Jan 13 21:35:37 2016
New Revision: 8075
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=8075&view=rev
Log:
IDP-904: Metadata Scope extension XMLObject impl fails on invalid regular expression value
Modified:
trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/xmlobject/Scope.java
trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeImpl.java
trunk/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeTest.java
Modified: trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/xmlobject/Scope.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/xmlobject/Scope.java?rev=8075&r1=8074&r2=8075&view=diff
==============================================================================
--- trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/xmlobject/Scope.java (original)
+++ trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/xmlobject/Scope.java Wed Jan 13 21:35:37 2016
@@ -66,11 +66,25 @@
public void setRegexp(XSBooleanValue newRegexp);
/**
- * Gets the match pattern used to evaluate if a scope matches the scope criteria given by this extension. If regular
- * expressions are not used in the scope criteria then this pattern must simply perform a direct match of the
- * string.
+ * Convenience method which returns a match {@link Pattern} that <b>may</b> be used to evaluate whether
+ * a candidate scope matches the scope criteria given by this extension, when the value is indicated to
+ * be a regular expression.
*
- * @return match pattern used to evaluate if a scope matches the scope criteria
+ * <p>
+ * This may only be called when {@link #getRegexp()} evaluates to <code>true</code>. Otherwise an
+ * {@link IllegalStateException} is thrown.
+ * </p>
+ *
+ * <p>
+ * The scope value supplied to {@link #setValue(String)} <b>MUST</b> be a valid Java regular expression
+ * as defined by {@link Pattern}, else a fatal error will result.
+ * </p>
+ *
+ * @return match pattern used to evaluate if a scope matches a regular expression scope criteria
+ *
+ * @deprecated No replacement. The caller should instead evaluate the scope value supplied by
+ * {@link #getValue()} in an implementation-specific manner
*/
+ @Deprecated
public Pattern getMatchPattern();
}
Modified: trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeImpl.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeImpl.java?rev=8075&r1=8074&r2=8075&view=diff
==============================================================================
--- trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeImpl.java (original)
+++ trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeImpl.java Wed Jan 13 21:35:37 2016
@@ -88,14 +88,20 @@
/** {@inheritDoc} */
public void setValue(String newScopeValue) {
scopeValue = prepareForAssignment(scopeValue, newScopeValue);
- matchPattern = Pattern.compile(scopeValue);
+ matchPattern = null;
}
/** {@inheritDoc} */
public Pattern getMatchPattern() {
+ if (getRegexp() != Boolean.TRUE) {
+ throw new IllegalStateException("Scope value is not indicated to be a regex");
+ }
+ if (matchPattern == null) {
+ matchPattern = Pattern.compile(scopeValue);
+ }
return matchPattern;
}
-
+
/** {@inheritDoc} */
public List<XMLObject> getOrderedChildren() {
return null;
Modified: trunk/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeTest.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeTest.java?rev=8075&r1=8074&r2=8075&view=diff
==============================================================================
--- trunk/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeTest.java (original)
+++ trunk/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/xmlobject/impl/ScopeTest.java Wed Jan 13 21:35:37 2016
@@ -16,6 +16,8 @@
*/
package net.shibboleth.idp.saml.xmlobject.impl;
+
+import java.util.regex.Pattern;
import net.shibboleth.idp.saml.xmlobject.Scope;
@@ -114,4 +116,34 @@
Assert.assertEquals(scope.getRegexp(), Boolean.FALSE, "Unexpected default value for boolean attribute found");
Assert.assertNull(scope.getRegexpXSBoolean(), "XSBooleanValue was not null");
}
+
+ /**
+ * Test behavior related to {@link Scope#getMatchPattern()}.
+ */
+ @Test
+ public void testMatchPattern() {
+ Scope scope = (Scope) buildXMLObject(Scope.DEFAULT_ELEMENT_NAME);
+
+ try {
+ scope.setRegexp(false);
+ scope.setValue("example.org");
[... 21 lines stripped ...]
More information about the commits
mailing list