Class BaseAsValidator<V,A>

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
net.shibboleth.metadata.validate.BaseValidator
net.shibboleth.metadata.validate.BaseAsValidator<V,A>
Type Parameters:
V - type of the original value
A - type of the new value to which validators should be applied
All Implemented Interfaces:
Validator<V>, net.shibboleth.shared.component.Component, net.shibboleth.shared.component.DestructableComponent, net.shibboleth.shared.component.IdentifiableComponent, net.shibboleth.shared.component.IdentifiedComponent, net.shibboleth.shared.component.InitializableComponent
Direct Known Subclasses:
AsDomainNameStringValidator, AsLiteralTailStringValidator, AsURLStringValidator

@ThreadSafe public abstract class BaseAsValidator<V,A> extends BaseValidator implements Validator<V>
An abstract base class for Validator implementations which validate a value of one type "as" another type: for example, to validate a String "as" an InternetDomainName.

The implementation calls a template method in the implementation subclass to perform the conversion. If the conversion succeeds, a sequence of Validators are applied to that new value.

If the value cannot be converted to the new type, the template method is expected to throw IllegalArgumentException. In this case, behaviour depends on the conversionRequired property.

If conversionRequired is true (the default) then an error status will be applied to the Item, and the validator will return Validator.Action.DONE.

If conversionRequired is false then the validator will simply return 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.

Since:
0.10.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.shibboleth.metadata.validate.Validator

    Validator.Action
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    Whether conversion to the new type must succeed.
    The validator sequence to apply.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract A
    convert(V from)
    Convert from the old value type to the new.
    protected void
     
    protected void
     
    Gets the list of validators being applied to each item.
    boolean
    Returns whether conversion to the new type is required to succeed.
    void
    setConversionRequired(boolean required)
    Set whether conversion to the new type is required to succeed.
    void
    setValidators(List<Validator<A>> newValidators)
    Set the list of validators to apply to each item.
    validate(V t, Item<?> item, String callerId, String valueContext)
    Apply the validator to a value in the context of the given Item.

    Methods inherited from class net.shibboleth.metadata.validate.BaseValidator

    addError, addErrorMessage, addErrorMessage, addErrorMessage, addStatus, addWarning, getMessage, makeComponentId, setMessage

    Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent

    setId

    Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent

    ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException

    Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

    checkComponentActive, checkSetterPreconditions, destroy, initialize, isDestroyed, isInitialized

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.shibboleth.shared.component.DestructableComponent

    destroy, isDestroyed

    Methods inherited from interface net.shibboleth.shared.component.IdentifiableComponent

    setId

    Methods inherited from interface net.shibboleth.shared.component.IdentifiedComponent

    getId

    Methods inherited from interface net.shibboleth.shared.component.InitializableComponent

    initialize, isInitialized

    Methods inherited from interface net.shibboleth.metadata.validate.Validator

    validate
  • Field Details

    • validators

      @Nonnull private ValidatorSequence<A> validators
      The validator sequence to apply.
    • conversionRequired

      private boolean conversionRequired
      Whether conversion to the new type must succeed. Default: true
  • Constructor Details

    • BaseAsValidator

      public BaseAsValidator()
  • Method Details

    • setValidators

      public void setValidators(@Nonnull List<Validator<A>> newValidators)
      Set the list of validators to apply to each item.
      Parameters:
      newValidators - the list of validators to set
    • getValidators

      @Nonnull public List<Validator<A>> getValidators()
      Gets the list of validators being applied to each item.
      Returns:
      list of validators
    • setConversionRequired

      public void setConversionRequired(boolean required)
      Set whether conversion to the new type is required to succeed.
      Parameters:
      required - true if the conversion is required to succeed
    • isConversionRequired

      public boolean isConversionRequired()
      Returns whether conversion to the new type is required to succeed.
      Returns:
      true if the conversion is required to succeed
    • convert

      @Nonnull protected abstract A convert(@Nonnull V from) throws IllegalArgumentException
      Convert from the old value type to the new.
      Parameters:
      from - a value of the old type
      Returns:
      a value of the new type
      Throws:
      IllegalArgumentException - if a conversion can not be performed
    • validate

      @Nonnull public Validator.Action validate(@Nonnull V t, @Nonnull Item<?> item, @Nonnull String callerId, @Nullable String valueContext) throws StageProcessingException
      Description copied from interface: Validator
      Apply the validator to a value in the context of the given Item.

      The validator influences future processing by adding item metadata to the Item.

      A common case is that the validator will add a StatusMetadata to the Item, for example a ErrorStatus. In this case, the convention is that the componentId of the ErrorStatus would be created by combining the callerId with a / and the validator's own identifier. For example, a validator val called by a stage stage would normally use a componentId of stage/val.

      The valueContext makes the original context of the value available to help in constructing meaningful error messages. For example, the validation of a complex structured value such as a URI might be broken down into multiple sub-validations of its components: scheme, for example. When relevant, the valueContext provides a representation of the original complex value while value is the component currently being validated.

      Specified by:
      validate in interface Validator<V>
      Parameters:
      t - the value to be validated
      item - the Item context for the validation
      callerId - a String identifying the caller
      valueContext - an additional String indicating the value context, or null
      Returns:
      an indication of whether to process additional validators
      Throws:
      StageProcessingException - if an error occurs during validation
    • doDestroy

      protected void doDestroy()
      Overrides:
      doDestroy in class net.shibboleth.shared.component.AbstractInitializableComponent
    • doInitialize

      protected void doInitialize() throws net.shibboleth.shared.component.ComponentInitializationException
      Overrides:
      doInitialize in class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
      Throws:
      net.shibboleth.shared.component.ComponentInitializationException