Class BaseValidator

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
net.shibboleth.metadata.validate.BaseValidator
All Implemented Interfaces:
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:
AbstractX509Validator, AcceptAllValidator, BaseAsValidator, BaseStringRegexValidator, BaseStringValueValidator, EmptyPortURLValidator, HTTPSProtocolURLValidator, MissingHostURLValidator, RejectAllValidator, RejectDomainNameNotUnderPublicSuffixValidator, RejectDomainNamePublicSuffixValidator, ValidatorSequence, X509DSADetector

@ThreadSafe public abstract class BaseValidator extends net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
Base class for validator implementations.

Encapsulates the notion of an identifier for each validator class, and helper methods for constructing status metadata.

Since:
0.9.0
  • Field Details

    • message

      @Nonnull private String message
      Message format string.

      The generated message is formatted using this with the value being validated passed as an argument.

      Defaults to "value rejected: '%s'". May be overwritten by a subclass via its constructor, or by setting the message property explicitly as configuration.

      Since:
      0.10.0
  • Constructor Details

    • BaseValidator

      protected BaseValidator()
      Constructor.
      Since:
      0.10.0
    • BaseValidator

      protected BaseValidator(@Nonnull String message)
      Constructor.
      Parameters:
      message - default value for the message property
      Since:
      0.10.0
  • Method Details

    • getMessage

      @Nonnull public final String getMessage()
      Returns the message format string.
      Returns:
      the message format string
      Since:
      0.10.0
    • setMessage

      public final void setMessage(@Nonnull String newMessage)
      Set the message format string.
      Parameters:
      newMessage - the new message format string
      Since:
      0.10.0
    • makeComponentId

      @Nonnull protected String makeComponentId(@Nonnull String callerId)
      Construct a modified component identifier by combining the identifier for the caller with the validator's own identifier.
      Parameters:
      callerId - a String identifying the caller
      Returns:
      composite component identifier
    • addError

      protected void addError(@Nonnull String mess, @Nonnull Item<?> item, @Nonnull String callerId)
      Add an ErrorStatus to the given Item.
      Parameters:
      mess - message to include in the status metadata
      item - Item to add the status metadata to
      callerId - a String identifying the caller
    • addWarning

      protected void addWarning(@Nonnull String mess, @Nonnull Item<?> item, @Nonnull String callerId)
      Add a WarningStatus to the given Item.
      Parameters:
      mess - message to include in the status metadata
      item - Item to add the status metadata to
      callerId - a String identifying the caller
    • addStatus

      protected void addStatus(boolean error, @Nonnull String mess, @Nonnull Item<?> item, @Nonnull String callerId)
      Add a WarningStatus or ErrorStatus to the given Item.
      Parameters:
      error - true if an ErrorStatus should be added
      mess - message to include in the status metadata
      item - Item to add the status metadata to
      callerId - a String identifying the caller
    • formatValueContext

      @Nonnull private String formatValueContext(@Nullable String valueContext)
      Formats a value context for presentation as a message prefix.

      If there is no explicit value context, returns an empty string.

      Parameters:
      valueContext - value context string, or null
      Returns:
      formatted value context prefix
      Since:
      0.10.0
    • formatMessage

      @Nonnull private String formatMessage(@Nonnull Object subject)
      Formats the message with the given subject.
      Parameters:
      subject - subject of the validation, to be provided as an argument to the formatting string.
      Returns:
      formatted message
      Since:
      0.10.0
    • formatMessage

      @Nonnull private String formatMessage(@Nonnull Object subject, @Nonnull Throwable cause)
      Formats the message with the given subject.

      If the supplied Throwable has a non-null detail message, this is added to the resulting formatted string.

      Parameters:
      subject - subject of the validation, to be provided as an argument to the formatting string.
      cause - a Throwable which is to be interpreted as the cause of the validation failure.
      Returns:
      formatted message
      Since:
      0.10.0
    • addErrorMessage

      protected void addErrorMessage(@Nonnull Object extra, @Nonnull Item<?> item, @Nonnull String callerId, @Nullable String valueContext)
      Add an ErrorStatus to the given Item.

      The status message included in the ErrorStatus is generated by formatting the provided value with the message field.

      If a valueContext has been provided, it will be included in the resulting message as a prefix.

      Parameters:
      extra - extra value to include in the status metadata
      item - Item to add the status metadata to
      callerId - a String identifying the caller
      valueContext - the context of the validation, or null
      Since:
      0.10.0
    • addErrorMessage

      protected void addErrorMessage(@Nonnull Object extra, @Nonnull Item<?> item, @Nonnull String callerId)
      Add an ErrorStatus to the given Item.

      The status message included in the ErrorStatus is generated by formatting the provided value with the message field.

      Parameters:
      extra - extra value to include in the status metadata
      item - Item to add the status metadata to
      callerId - a String identifying the caller
      Since:
      0.10.0
    • addErrorMessage

      protected void addErrorMessage(@Nonnull Object extra, @Nonnull Item<?> item, @Nonnull String callerId, @Nonnull Throwable cause)
      Add an ErrorStatus to the given Item.

      The status message included in the ErrorStatus is generated by formatting the provided value with the message field.

      Parameters:
      extra - extra value to include in the status metadata
      item - Item to add the status metadata to
      callerId - a String identifying the caller
      cause - reason for the validation failure, as a Throwable
      Since:
      0.10.0