Package com.unboundid.util.args
Class DNSHostNameArgumentValueValidator
- java.lang.Object
-
- com.unboundid.util.args.ArgumentValueValidator
-
- com.unboundid.util.args.DNSHostNameArgumentValueValidator
-
- All Implemented Interfaces:
java.io.Serializable
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class DNSHostNameArgumentValueValidator extends ArgumentValueValidator implements java.io.Serializable
This class provides an implementation of an argument value validator that ensures that values can be parsed as valid DNS host names. As per RFC 952 and RFC 1123, valid DNS host names must satisfy the following constraints:- Host names are split into one or more components, which are separated by periods.
- Each component may contain only ASCII letters, digits, and hyphens. While host names may contain non-ASCII characters in some contexts, they are not valid in all contexts, and host names with non-ASCII characters should be represented in an ASCII-only encoding called punycode (as described in RFC 3492). This implementation expects any hostnames with non-ASCII characters to use the punycode representation, but it does not currently attempt to validate the punycode representation.
- Components must not start with a hyphen.
- Each component of a hostname must be between 1 and 63 characters.
- The entire hostname (including the periods between components) must not exceed 255 characters.
- Host names must not contain consecutive periods, as that would indicate an empty internal component.
- Host names must not start with a period, as that would indicate an empty initial component.
- Host names may end with a period as a way of explicitly indicating that it is fully qualified. This is primarily used for host names that only contain a single component (for example, "localhost."), but it is allowed for any fully qualified host name.
- This implementation may optionally require fully qualified host names.
- This implementation may optionally reject host names that cannot be resolved to IP addresses.
- This implementation may optionally reject values that are numeric IP addresses rather than host names.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DNSHostNameArgumentValueValidator()
Creates a new DNS host name argument value validator with the default settings.DNSHostNameArgumentValueValidator(boolean allowIPAddresses, boolean allowUnqualifiedNames, boolean allowUnresolvableNames, NameResolver nameResolver)
Creates a new DNS host name argument value validator with the provided settings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allowIPAddresses()
Indicates whether this validator will allow values that represent valid numeric IP addresses rather than DNS host names.boolean
allowUnqualifiedNames()
Indicates whether this validator will allow unqualified DNS host names (that is, host names that do not include a domain component).boolean
allowUnresolvableNames()
Indicates whether this validator will allow DNS host names that cannot be resolved to IP addresses.NameResolver
getNameResolver()
Retrieves the name resolver that will be used when attempting to resolve host names to IP addresses.java.lang.String
toString()
Retrieves a string representation of this argument value validator.void
toString(java.lang.StringBuilder buffer)
Appends a string representation of this argument value validator to the provided buffer.void
validateArgumentValue(Argument argument, java.lang.String valueString)
Examines the value(s) assigned to the provided argument to determine whether they are acceptable.static void
validateDNSHostName(java.lang.String name)
Ensures that the provided name represents a valid DNS host name using the default settings.static void
validateDNSHostName(java.lang.String name, boolean allowIPAddresses, boolean allowUnqualifiedNames, boolean allowUnresolvableNames, NameResolver nameResolver)
Ensures that the provided name represents a valid DNS host name using the provided settings.
-
-
-
Constructor Detail
-
DNSHostNameArgumentValueValidator
public DNSHostNameArgumentValueValidator()
Creates a new DNS host name argument value validator with the default settings. It will allow IP addresses in addition to host names, it will allow unqualified names, and it will allow unresolvable names.
-
DNSHostNameArgumentValueValidator
public DNSHostNameArgumentValueValidator(boolean allowIPAddresses, boolean allowUnqualifiedNames, boolean allowUnresolvableNames, @Nullable NameResolver nameResolver)
Creates a new DNS host name argument value validator with the provided settings.- Parameters:
allowIPAddresses
- Indicates whether this validator will allow values that represent numeric IP addresses rather than DNS host names. If this istrue
, then valid IP addresses will be accepted as well as valid DNS host names. If this isfalse
, then only valid DNS host names will be accepted.allowUnqualifiedNames
- Indicates whether this validator will allow values that represent unqualified host names. If this istrue
, then unqualified names will be accepted as long as they are otherwise acceptable. If this isfalse
, then only fully qualified host names will be accepted.allowUnresolvableNames
- Indicates whether this validator will allow host name values that do not resolve to IP addresses. If this istrue
, then this validator will not attempt to resolve host names. If this isfalse
, then this validator will reject any host name that cannot be resolved to an IP address.nameResolver
- The name resolver that will be used when attempting to resolve host names to IP addresses. If this isnull
, then the LDAP SDK's default name resolver will be used.
-
-
Method Detail
-
allowIPAddresses
public boolean allowIPAddresses()
Indicates whether this validator will allow values that represent valid numeric IP addresses rather than DNS host names.- Returns:
true
if this validator will accept values that represent either valid numeric IP addresses or numeric DNS host names, orfalse
if it will reject values that represent numeric IP addresses.
-
allowUnqualifiedNames
public boolean allowUnqualifiedNames()
Indicates whether this validator will allow unqualified DNS host names (that is, host names that do not include a domain component).- Returns:
true
if this validator will allow both unqualified and fully qualified host names, orfalse
if it will only accept fully qualified host names.
-
allowUnresolvableNames
public boolean allowUnresolvableNames()
Indicates whether this validator will allow DNS host names that cannot be resolved to IP addresses.- Returns:
true
if this validator will only validate the syntax for DNS host names and will not make any attempt to resolve them to IP addresses, orfalse
if it will attempt to resolve host names to IP addresses and will reject any names that cannot be resolved.
-
getNameResolver
@NotNull public NameResolver getNameResolver()
Retrieves the name resolver that will be used when attempting to resolve host names to IP addresses.- Returns:
- The name resolver that will be used when attempting to resolve host names to IP addresses.
-
validateArgumentValue
public void validateArgumentValue(@NotNull Argument argument, @NotNull java.lang.String valueString) throws ArgumentException
Examines the value(s) assigned to the provided argument to determine whether they are acceptable.- Specified by:
validateArgumentValue
in classArgumentValueValidator
- Parameters:
argument
- The argument to which the value is being provided.valueString
- The string representation of the value to be validated. This value will have already passed any normal validation performed by the argument.- Throws:
ArgumentException
- If the provided value is determined to be unacceptable.
-
validateDNSHostName
public static void validateDNSHostName(@NotNull java.lang.String name) throws ArgumentException
Ensures that the provided name represents a valid DNS host name using the default settings. IP addresses, unqualified names, and unresolvable names will all be allowed as long as the provided name is otherwise syntactically valid.- Parameters:
name
- The name to validate as a DNS host name. It must not benull
or empty.- Throws:
ArgumentException
- If the provided name is not considered valid.
-
validateDNSHostName
public static void validateDNSHostName(@Nullable java.lang.String name, boolean allowIPAddresses, boolean allowUnqualifiedNames, boolean allowUnresolvableNames, @Nullable NameResolver nameResolver) throws ArgumentException
Ensures that the provided name represents a valid DNS host name using the provided settings.- Parameters:
name
- The name to validate as a DNS host name.allowIPAddresses
- Indicates whether this validator will allow values that represent numeric IP addresses rather than DNS host names. If this istrue
, then valid IP addresses will be accepted as well as valid DNS host names. If this isfalse
, then only valid DNS host names will be accepted.allowUnqualifiedNames
- Indicates whether this validator will allow values that represent unqualified host names. If this istrue
, then unqualified names will be accepted as long as they are otherwise acceptable. If this isfalse
, then only fully qualified host names will be accepted.allowUnresolvableNames
- Indicates whether this validator will allow host name values that do not resolve to IP addresses. If this istrue
, then this validator will not attempt to resolve host names. If this isfalse
, then this validator will reject any host name that cannot be resolved to an IP address.nameResolver
- The name resolver that will be used when attempting to resolve host names to IP addresses. If this isnull
, then the LDAP SDK's default name resolver will be used.- Throws:
ArgumentException
- If the provided name is not considered valid.
-
toString
@NotNull public java.lang.String toString()
Retrieves a string representation of this argument value validator.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representation of this argument value validator.
-
-