shibmd:Scope
- * values.
- *
- * A separate collection of validators is used for the case of the regexp
- * attribute being true and false.
- */
-public class ScopeValidationStage extends AbstractDOMValidationStageregexp scopes. */
- @Nonnull
- private ValidatorSequenceregexp scope.
- *
- * @param newValidators the list of validators to set
- */
- public void setRegexpValidators(@Nonnull final Listregexp scope.
- *
- * @return list of validators
- */
- @Nonnull
- public ListThe implementation calls a template method in the implementation subclass to perform the - * conversion. If the conversion succeeds, a sequence of {@link Validator}s are applied to - * that new value.
- * - *If the value cannot be converted to the new type, the template method is expected to - * throw {@link IllegalArgumentException}. In this case, behaviour depends on the - * {@link #conversionRequired} property.
- * - *If {@link #conversionRequired} is true (the default) then an error
- * status will be applied to the {@link Item}, and the validator will return
- * {@link net.shibboleth.metadata.validate.Validator.Action#DONE}.
If {@link #conversionRequired} is false then the validator
- * will simply return {@link net.shibboleth.metadata.validate.Validator.Action#CONTINUE}
- * so that subsequent validators may still be applied. This allows several "as" validators
- * to be applied in sequence, each taking a different approach.
true */
- private boolean conversionRequired = true;
-
- /**
- * Set the list of validators to apply to each item.
- *
- * @param newValidators the list of validators to set
- */
- public void setValidators(@Nonnull final Listtrue if the conversion is required to succeed
- */
- public void setConversionRequired(final boolean required) {
- conversionRequired = required;
- }
-
- /**
- * Returns whether conversion to the new type is required to succeed.
- *
- * @return true if the conversion is required to succeed
- */
- public boolean isConversionRequired() {
- return conversionRequired;
- }
-
- /**
- * Apply each of the configured validators in turn to the provided object.
- *
- * @param value object to be validated
- * @param item the {@link Item} context for the validation
- *
- * @return the result of applying the validators to the value
- *
- * @throws StageProcessingException if errors occur during processing
- */
- protected Action applyValidators(@Nonnull final A value, @Nonnull final Item> item)
- throws StageProcessingException {
- return validators.validate(value, item, getId());
- }
-
- /**
- * Convert from the old value type to the new.
- *
- * @param from a value of the old type
- * @return a value of the new type
- * @throws IllegalArgumentException if a conversion can not be performed
- */
- protected abstract @Nonnull A convert(@Nonnull final V from) throws IllegalArgumentException;
-
- @Override
- public @Nonnull Action validate(@Nonnull final V t, @Nonnull final Item> item, @Nonnull final String stageId)
- throws StageProcessingException {
- try {
- final A v = convert(t);
- return applyValidators(v, item);
- } catch (final IllegalArgumentException e) {
- if (isConversionRequired()) {
- addErrorMessage(t, item, stageId);
- return Action.DONE;
- } else {
- return Action.CONTINUE;
- }
- }
- }
-
- @Override
- protected void doDestroy() {
- validators.destroy();
- validators = null;
- super.doDestroy();
- }
-
- @Override
- protected void doInitialize() throws ComponentInitializationException {
- super.doInitialize();
- validators.setId(getId());
- validators.initialize();
- }
-
-}
diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/net/RejectDomainNameNotUnderPublicSuffixValidator.java b/src/main/java/uk/org/iay/incommon/mda/validate/net/RejectDomainNameNotUnderPublicSuffixValidator.java
deleted file mode 100644
index e54d3cf..0000000
--- a/src/main/java/uk/org/iay/incommon/mda/validate/net/RejectDomainNameNotUnderPublicSuffixValidator.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package uk.org.iay.incommon.mda.validate.net;
-
-import javax.annotation.Nonnull;
-
-import com.google.common.net.InternetDomainName;
-
-import net.shibboleth.metadata.Item;
-import net.shibboleth.metadata.validate.BaseValidator;
-import net.shibboleth.metadata.validate.Validator;
-
-/**
- * A validator that checks whether an {@link InternetDomainName} is under a public suffix.
- *
- * A domain name which is not under a public suffix might be a public suffix itself,
- * or might terminate in something which is not a public suffix.
- */
-public class RejectDomainNameNotUnderPublicSuffixValidator extends BaseValidator
- implements ValidatorValidator that checks {@link String} values as domain names by converting the
- * value to an {@link InternetDomainName} and applying a sequence of validators to that value.
- *
- * This validator fails (and returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE}) if the
- * value can not be converted to an {@link InternetDomainName}.
- *
- * Otherwise, the validator applies the sequence of validators to the {@link InternetDomainName} and returns
- * the value of that sequence.
- */
-public class AsDomainNameStringValidator extends BaseAsValidatorValidator that assists in the validation of regular-expression <shibmd:Scope>
- * values that include a literal tail.
- *
- * A literal tail is:
- *
- * '.' characters (encoded
- * in the regular expression as '\.''.'
- * For example, the literal tail in the regular expression
- * '^([a-zA-Z0-9-]{1,63}\.){0,2}ddd\.ccc\.bbb\.aa$' is 'ccc.bbb.aa'.
The literal tail is extracted from the regular expression, has its encoded '.'
- * characters converted to normal ones, and then validated as a {@link String} by a new sequence of
- * validators.
This validator fails (and returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE}) if the - * value does not possess a literal tail.
- * - *Otherwise, the validator applies the sequence of validators to the new value and returns - * the value of that sequence.
- */ -public class AsLiteralTailStringValidator extends BaseAsValidator.*? matches non-greedily any text at the start of the regular expression,
- * maximising the size of the later parts of the match\\\\. matches \. in the regular expression, which in turn
- * matches a literal . in the scope\\$ matches an end-string marker in the regular expression being matchedThe matching of DNS labels is not exact. For example, labels starting or ending with hyphens - * are accepted as part of a literal tail. This will normally be detected by the nested validator - * sequence applied to the result.
- * - *Similarly, upper-case characters are permitted in the literal tail although these would - * not normally be permitted in scopes. Again, these characters are permitted so that a more - * specific error can be reported, rather than just a generic failure to convert.
- */ - private final Pattern pattern = Pattern.compile(".*?\\\\.(([a-zA-Z0-9-]+\\\\.)+[a-zA-Z0-9-]+)\\$"); - - @Override - protected @Nonnull String convert(@Nonnull final String regex) throws IllegalArgumentException { - // Match against the regular expression - final Matcher matcher = pattern.matcher(regex); - - // If the pattern does not match, signal that the string does not have a literal tail - if (!matcher.matches()) { - throw new IllegalArgumentException(); - } - - // Remove all '\' characters from the result. - return matcher.group(1).replaceAll("\\\\", ""); - } - -} diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/string/BaseStringRegexValidator.java b/src/main/java/uk/org/iay/incommon/mda/validate/string/BaseStringRegexValidator.java deleted file mode 100644 index 12442d2..0000000 --- a/src/main/java/uk/org/iay/incommon/mda/validate/string/BaseStringRegexValidator.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.iay.incommon.mda.validate.string; - -import java.util.regex.Pattern; - -import javax.annotation.Nonnull; - -import net.shibboleth.metadata.validate.BaseValidator; -import net.shibboleth.shared.annotation.constraint.NonnullAfterInit; -import net.shibboleth.shared.component.ComponentInitializationException; -import net.shibboleth.shared.component.ComponentSupport; - -/** - * A base class forValidators that match {@link String} values against a regular expression.
- */
-public abstract class BaseStringRegexValidator extends BaseValidator {
-
- /** Regular expression to be accepted by this validator. */
- @NonnullAfterInit
- private String regex;
-
- /** Compiled regular expression to use in match operations. */
- @NonnullAfterInit
- private Pattern pattern;
-
- /**
- * Returns the regular expression.
- *
- * @return Returns the regular expression.
- */
- @NonnullAfterInit
- public String getRegex() {
- return regex;
- }
-
- /**
- * Sets the regular expression to be accepted.
- *
- * @param r the regular expression to set.
- */
- public void setRegex(@Nonnull final String r) {
- ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
- regex = r;
- }
-
- /**
- * Get the compiled regular expression for use in matching.
- *
- * @return the compiled {@link Pattern}
- */
- protected Pattern getPattern() {
- return pattern;
- }
-
- @Override
- protected void doInitialize() throws ComponentInitializationException {
- super.doInitialize();
-
- if (getRegex() == null) {
- throw new ComponentInitializationException("regular expression to be matched can not be null");
- }
-
- pattern = Pattern.compile(regex);
- }
-
-}
diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/string/package-info.java b/src/main/java/uk/org/iay/incommon/mda/validate/string/package-info.java
deleted file mode 100644
index 3c2101a..0000000
--- a/src/main/java/uk/org/iay/incommon/mda/validate/string/package-info.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Validation classes for {@link java.lang.String} values.
- */
-package uk.org.iay.incommon.mda.validate.string;
diff --git a/src/main/resources/uk/org/iay/incommon/mda/beans.xml b/src/main/resources/uk/org/iay/incommon/mda/beans.xml
index 3b733d4..51b9699 100644
--- a/src/main/resources/uk/org/iay/incommon/mda/beans.xml
+++ b/src/main/resources/uk/org/iay/incommon/mda/beans.xml
@@ -31,27 +31,4 @@
shibmd:Scope {@link Element}. */
- private Element buildScope(final Document document, final String value, final boolean isRegex) {
- final Element element = ElementSupport.constructElement(document, ShibbolethMetadataSupport.SCOPE_NAME);
- AttributeSupport.appendAttribute(element, ShibbolethMetadataSupport.REGEXP_ATTRIB_NAME,
- isRegex ? "true" : "false");
- element.setTextContent(value);
- return element;
- }
-
- /** Build a {@link Document} containing an appropriate shibmd:Scope {@link Element}. */
- private Document buildDocument(final String value, final boolean isRegex) {
- final Document document = dBuilder.newDocument();
- document.appendChild(buildScope(document, value, isRegex));
- return document;
- }
-
- /** Run the test stage on a single {@link Item}. */
- private List