Class BaseAsValidator<V,A>
- Type Parameters:
V- type of the original valueA- 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
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
FieldsModifier and TypeFieldDescriptionprivate booleanWhether conversion to the new type must succeed.private ValidatorSequence<A>The validator sequence to apply. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract AConvert from the old value type to the new.protected voidprotected voidGets the list of validators being applied to each item.booleanReturns whether conversion to the new type is required to succeed.voidsetConversionRequired(boolean required) Set whether conversion to the new type is required to succeed.voidsetValidators(List<Validator<A>> newValidators) Set the list of validators to apply to each item.Apply the validator to a value in the context of the givenItem.Methods inherited from class net.shibboleth.metadata.validate.BaseValidator
addError, addErrorMessage, addErrorMessage, addErrorMessage, addStatus, addWarning, getMessage, makeComponentId, setMessageMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
setIdMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentExceptionMethods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, initialize, isDestroyed, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.shibboleth.shared.component.DestructableComponent
destroy, isDestroyedMethods inherited from interface net.shibboleth.shared.component.IdentifiableComponent
setIdMethods inherited from interface net.shibboleth.shared.component.IdentifiedComponent
getIdMethods inherited from interface net.shibboleth.shared.component.InitializableComponent
initialize, isInitialized
-
Field Details
-
validators
The validator sequence to apply. -
conversionRequired
private boolean conversionRequiredWhether conversion to the new type must succeed. Default:true
-
-
Constructor Details
-
BaseAsValidator
public BaseAsValidator()
-
-
Method Details
-
setValidators
Set the list of validators to apply to each item.- Parameters:
newValidators- the list of validators to set
-
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-trueif the conversion is required to succeed
-
isConversionRequired
public boolean isConversionRequired()Returns whether conversion to the new type is required to succeed.- Returns:
trueif the conversion is required to succeed
-
convert
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:ValidatorApply the validator to a value in the context of the givenItem.The validator influences future processing by adding item metadata to the
Item.A common case is that the validator will add a
StatusMetadatato theItem, for example aErrorStatus. In this case, the convention is that thecomponentIdof theErrorStatuswould be created by combining thecallerIdwith a/and the validator's own identifier. For example, a validatorvalcalled by a stagestagewould normally use acomponentIdofstage/val.The
valueContextmakes the original context of thevalueavailable 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, thevalueContextprovides a representation of the original complex value whilevalueis the component currently being validated.- Specified by:
validatein interfaceValidator<V>- Parameters:
t- the value to be validateditem- theItemcontext for the validationcallerId- aStringidentifying the callervalueContext- an additionalStringindicating the value context, ornull- Returns:
- an indication of whether to process additional validators
- Throws:
StageProcessingException- if an error occurs during validation
-
doDestroy
protected void doDestroy()- Overrides:
doDestroyin classnet.shibboleth.shared.component.AbstractInitializableComponent
-
doInitialize
protected void doInitialize() throws net.shibboleth.shared.component.ComponentInitializationException- Overrides:
doInitializein classnet.shibboleth.shared.component.AbstractIdentifiedInitializableComponent- Throws:
net.shibboleth.shared.component.ComponentInitializationException
-