public class LdapUrl extends Object
ldapurl = scheme "://" [host [ ":" port]] ["/"
dn ["?" [attributes] ["?" [scope]
["?" [filter] ["?" extensions]]]]]
scheme = "ldap"
dn = Dn
attributes = attrdesc ["," attrdesc]*
attrdesc = selector ["," selector]*
selector = attributeSelector (from Section 4.5.1 of RFC4511)
scope = "base" / "one" / "sub"
extensions = extension ["," extension]*
extension = ["!"] extype ["=" exvalue]
extype = oid (from Section 1.4 of RFC4512)
exvalue = LDAPString (from Section 4.1.2 of RFC4511)
host = host from Section 3.2.2 of RFC3986
port = port from Section 3.2.3 of RFC3986
filter = filter from Section 3 of RFC 4515
From Section 3.2.1/2 of RFC3986
host = IP-literal / IPv4address / reg-name
port = *DIGIT
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
IPv6address = 6( h16 ":" ) ls32
| "::" 5( h16 ":" ) ls32
| [ h16 ] "::" 4( h16 ":" ) ls32
| [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
| [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
| [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
| [ *4( h16 ":" ) h16 ] "::" ls32
| [ *5( h16 ":" ) h16 ] "::" h16
| [ *6( h16 ":" ) h16 ] "::"
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT | [1-9] DIGIT | "1" 2DIGIT | "2" [0-4] DIGIT | "25" [0-5]
reg-name = *( unreserved / pct-encoded / sub-delims )
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "="
h16 = 1*4HEXDIG
ls32 = ( h16 ":" h16 ) / IPv4address
DIGIT = 0..9
ALPHA = A-Z / a-z
HEXDIG = DIGIT / A-F / a-f
| Modifier and Type | Class and Description |
|---|---|
static class |
LdapUrl.Extension
An inner bean to hold extension information.
|
| Modifier and Type | Field and Description |
|---|---|
private static Pattern |
ATTRIBUTE
A regexp for attributes
|
private List<String> |
attributes
The attributes
|
private byte[] |
bytes
Stores the LdapUrl as a byte array
|
private Dn |
dn
The Dn
|
static LdapUrl |
EMPTY_URL
A null LdapUrl
|
private List<LdapUrl.Extension> |
extensionList
The extensions.
|
private String |
filter
The filter as a string
|
private boolean |
forceScopeRendering
modal parameter that forces explicit scope rendering in toString
|
private String |
host
The host
|
private HostTypeEnum |
hostType
The type of host we use
|
static String |
LDAP_SCHEME
The constant for "ldap://" scheme.
|
static String |
LDAPS_SCHEME
The constant for "ldaps://" scheme.
|
private int |
port
The port
|
private String |
scheme
The scheme
|
private SearchScope |
scope
The scope
|
private String |
string
Stores the LdapUrl as a String
|
| Constructor and Description |
|---|
LdapUrl()
Construct an empty LdapUrl
|
LdapUrl(String string)
Create a new LdapUrl from a String after having parsed it.
|
| Modifier and Type | Method and Description |
|---|---|
private static String |
decode(String escaped)
From commons-httpclients.
|
private static byte[] |
decodeUrl(byte[] bytes)
From commons-codec.
|
boolean |
equals(Object obj) |
private static byte[] |
getAsciiBytes(String data)
Converts the specified string to byte array of ASCII characters.
|
List<String> |
getAttributes() |
byte[] |
getBytesCopy() |
byte[] |
getBytesReference() |
Dn |
getDn() |
LdapUrl.Extension |
getExtension(String type)
Gets the extension.
|
List<LdapUrl.Extension> |
getExtensions() |
String |
getExtensionValue(String type)
Gets the extension value.
|
String |
getFilter() |
String |
getHost() |
int |
getNbBytes() |
int |
getPort() |
String |
getScheme() |
SearchScope |
getScope()
|
String |
getString() |
int |
hashCode() |
boolean |
isValidInet4Address(String inet4Address)
Validates an IPv4 address.
|
boolean |
isValidInet6Address(String inet6Address)
This code source was taken from commons.validator 1.5.0
Validates an IPv6 address.
|
private void |
parse(char[] chars)
Parse a LdapUrl.
|
private int |
parseAttributes(char[] chars,
int pos)
Parse the attributes part
|
private int |
parseDecOctet(char[] chars,
int pos,
int[] ipElem,
int octetNb)
Parse this rule :
dec-octet = DIGIT | [1-9] DIGIT | "1" 2DIGIT | "2" [0-4] DIGIT | "25" [0-5]
|
private int |
parseDN(char[] chars,
int pos)
Parse a string and check that it complies with RFC 2253.
|
private int |
parseExtensions(char[] chars,
int pos)
Parse extensions and critical extensions.
|
private int |
parseFilter(char[] chars,
int pos)
Parse the filter part.
|
private int |
parseHost(char[] chars,
int pos)
Parse this rule :
host = IP-literal / IPv4address / reg-name port = *DIGIT <host> ::= <hostname> ':' <hostnumber> <hostname> ::= *[ <domainlabel> "." ] <toplabel> <domainlabel> ::= <alphadigit> | <alphadigit> *[<alphadigit> | "-" ] <alphadigit> <toplabel> ::= <alpha> | <alpha> *[ <alphadigit> | "-" ] <alphadigit> <hostnumber> ::= <digits> "." |
private int |
parseHostPort(char[] chars,
int pos)
Parse this rule :
<hostport> ::= <host> [':' <port>] |
private int |
parseIpLiteral(char[] chars,
int pos)
parse these rules :
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
IPv6address = 6( h16 ":" ) ls32
| "::" 5( h16 ":" ) ls32
| [ h16 ] "::" 4( h16 ":" ) ls32
| [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
| [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
| [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
| [ *4( h16 ":" ) h16 ] "::" ls32
| [ *5( h16 ":" ) h16 ] "::" h16
| [ *6( h16 ":" ) h16 ] "::"
h16 = 1*4HEXDIG
ls32 = ( h16 ":" h16 ) / IPv4address
|
private int |
parseIPV4(char[] chars,
int pos)
Parse these rules :
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT | [1-9] DIGIT | "1" 2DIGIT | "2" [0-4] DIGIT | "25" [0-5]
|
private int |
parseIPV6(char[] chars,
int pos)
Parse the following rules :
IPv6address = 6( h16 ":" ) ls32
| "::" 5( h16 ":" ) ls32
| [ h16 ] "::" 4( h16 ":" ) ls32
| [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
| [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
| [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
| [ *4( h16 ":" ) h16 ] "::" ls32
| [ *5( h16 ":" ) h16 ] "::" h16
| [ *6( h16 ":" ) h16 ] "::"
h16 = 1*4HEXDIG
ls32 = ( h16 ":" h16 ) / IPv4address
|
private int |
parseIPvFuture(char[] chars,
int pos)
Parse these rules :
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
(the "v" has already been parsed)
|
private int |
parsePort(char[] chars,
int pos)
Parse this rule :
<port> ::= <digit>+ <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 The port must be between 0 and 65535. |
private int |
parseRegName(char[] chars,
int pos)
parse these rules :
reg-name = *( unreserved / pct-encoded / sub-delims )
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!"
|
private int |
parseScope(char[] chars,
int pos)
Parse the scope part.
|
void |
setAttributes(List<String> attributes)
Sets the attributes, null removes all existing attributes.
|
void |
setDn(Dn dn)
Sets the dn.
|
void |
setFilter(String filter)
Sets the filter.
|
void |
setForceScopeRendering(boolean forceScopeRendering)
If set to true forces the toString method to render the scope
regardless of optional nature.
|
void |
setHost(String host)
Sets the host.
|
void |
setPort(int port)
Sets the port.
|
void |
setScheme(String scheme)
Sets the scheme.
|
void |
setScope(int scope)
Sets the scope.
|
void |
setScope(SearchScope scope)
Sets the scope.
|
String |
toString()
Get a string representation of a LdapUrl.
|
static String |
urlEncode(String url,
boolean doubleEncode)
Encode a String to avoid special characters.
|
private void |
validateAttribute(String attribute)
Parse the following rule :
oid ::= numericOid | descr
descr ::= keystring
keystring ::= leadkeychar *keychar
leadkeychar ::= [a-zA-Z]
keychar ::= [a-zA-Z0-0-]
numericOid ::= number 1*( DOT number )
number ::= 0 | [1-9][0-9]*
|
public static final String LDAPS_SCHEME
public static final String LDAP_SCHEME
public static final LdapUrl EMPTY_URL
private String scheme
private String host
private int port
private Dn dn
private SearchScope scope
private String filter
private List<LdapUrl.Extension> extensionList
private String string
private byte[] bytes
private boolean forceScopeRendering
private HostTypeEnum hostType
private static final Pattern ATTRIBUTE
public LdapUrl()
public LdapUrl(String string) throws LdapURLEncodingException
string - TheString that contains the LdapUrlLdapURLEncodingException - If the String does not comply with RFC 2255private void parse(char[] chars)
throws LdapURLEncodingException
chars - The chars containing the URLLdapURLEncodingException - If the URL is invalidprivate int parseHost(char[] chars,
int pos)
host = IP-literal / IPv4address / reg-name port = *DIGIT <host> ::= <hostname> ':' <hostnumber> <hostname> ::= *[ <domainlabel> "." ] <toplabel> <domainlabel> ::= <alphadigit> | <alphadigit> *[<alphadigit> | "-" ] <alphadigit> <toplabel> ::= <alpha> | <alpha> *[ <alphadigit> | "-" ] <alphadigit> <hostnumber> ::= <digits> "." <digits> "." <digits> "." <digits>
chars - The buffer to parsepos - The current position in the byte bufferprivate int parseIpLiteral(char[] chars,
int pos)
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
IPv6address = 6( h16 ":" ) ls32
| "::" 5( h16 ":" ) ls32
| [ h16 ] "::" 4( h16 ":" ) ls32
| [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
| [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
| [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
| [ *4( h16 ":" ) h16 ] "::" ls32
| [ *5( h16 ":" ) h16 ] "::" h16
| [ *6( h16 ":" ) h16 ] "::"
h16 = 1*4HEXDIG
ls32 = ( h16 ":" h16 ) / IPv4address
chars - The chars to parsepos - The position in the charspublic boolean isValidInet4Address(String inet4Address)
inet4Address - the IPv4 address to validatepublic boolean isValidInet6Address(String inet6Address)
inet6Address - the IPv6 address to validateprivate int parseIPV6(char[] chars,
int pos)
IPv6address = 6( h16 ":" ) ls32
| "::" 5( h16 ":" ) ls32
| [ h16 ] "::" 4( h16 ":" ) ls32
| [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
| [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
| [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
| [ *4( h16 ":" ) h16 ] "::" ls32
| [ *5( h16 ":" ) h16 ] "::" h16
| [ *6( h16 ":" ) h16 ] "::"
h16 = 1*4HEXDIG
ls32 = ( h16 ":" h16 ) / IPv4address
chars - The chars to parsepos - The position in the charsprivate int parseIPvFuture(char[] chars,
int pos)
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )(the "v" has already been parsed)
chars - The chars to parsepos - The position in the charsprivate int parseRegName(char[] chars,
int pos)
reg-name = *( unreserved / pct-encoded / sub-delims )
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "="
HEXDIG = DIGIT / A-F / a-f
chars - The chars to parsepos - The position in the charsprivate int parseIPV4(char[] chars,
int pos)
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet dec-octet = DIGIT | [1-9] DIGIT | "1" 2DIGIT | "2" [0-4] DIGIT | "25" [0-5]
chars - The buffer to parsepos - The current position in the byte bufferprivate int parseDecOctet(char[] chars,
int pos,
int[] ipElem,
int octetNb)
dec-octet = DIGIT | [1-9] DIGIT | "1" 2DIGIT | "2" [0-4] DIGIT | "25" [0-5]
chars - The chars to parsepos - The position in the charsipElem - The IP elements to updateoctetNb - The IP octet being processedprivate int parsePort(char[] chars,
int pos)
<port> ::= <digit>+ <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9The port must be between 0 and 65535.
chars - The buffer to parsepos - The current position in the byte bufferprivate int parseHostPort(char[] chars,
int pos)
<hostport> ::= <host> [':' <port>]
chars - The char array to parsepos - The current position in the byte bufferprivate static byte[] getAsciiBytes(String data)
data - the string to be encodedprivate static byte[] decodeUrl(byte[] bytes)
throws UrlDecoderException
bytes - array of URL safe charactersUrlDecoderException - Thrown if URL decoding is unsuccessfulprivate static String decode(String escaped) throws LdapUriException
escaped - a stringLdapUriException - if the string cannot be decoded (invalid)private int parseDN(char[] chars,
int pos)
chars - The char array to be checkedpos - the starting positionprivate void validateAttribute(String attribute) throws LdapURLEncodingException
oid ::= numericOid | descr descr ::= keystring keystring ::= leadkeychar *keychar leadkeychar ::= [a-zA-Z] keychar ::= [a-zA-Z0-0-] numericOid ::= number 1*( DOT number ) number ::= 0 | [1-9][0-9]*
attribute - The attribute to validateLdapURLEncodingException - If teh attribute is invalidprivate int parseAttributes(char[] chars,
int pos)
chars - The char array to be checkedpos - the starting positionprivate int parseFilter(char[] chars,
int pos)
chars - The char array to be checkedpos - the starting positionprivate int parseScope(char[] chars,
int pos)
chars - The char array to be checkedpos - the starting positionprivate int parseExtensions(char[] chars,
int pos)
chars - The char array to be checkedpos - the starting positionpublic static String urlEncode(String url, boolean doubleEncode)
RFC 4516, section 2.1. (Percent-Encoding)
A generated LDAP URL MUST consist only of the restricted set of
characters included in one of the following three productions defined
in [RFC3986]:
<reserved>
<unreserved>
<pct-encoded>
Implementations SHOULD accept other valid UTF-8 strings [RFC3629] as
input. An octet MUST be encoded using the percent-encoding mechanism
described in section 2.1 of [RFC3986] in any of these situations:
The octet is not in the reserved set defined in section 2.2 of
[RFC3986] or in the unreserved set defined in section 2.3 of
[RFC3986].
It is the single Reserved character '?' and occurs inside a <dn>,
<filter>, or other element of an LDAP URL.
It is a comma character ',' that occurs inside an <exvalue>.
RFC 3986, section 2.2 (Reserved Characters)
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
RFC 3986, section 2.3 (Unreserved Characters)
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
url - The String to encodedoubleEncode - Set if we need to encode the commapublic String toString()
public Dn getDn()
public List<LdapUrl.Extension> getExtensions()
public LdapUrl.Extension getExtension(String type)
type - the extension type, case-insensitivepublic String getExtensionValue(String type)
type - the extension type, case-insensitivepublic String getFilter()
public String getHost()
public int getPort()
public SearchScope getScope()
public String getScheme()
public int getNbBytes()
public byte[] getBytesReference()
public byte[] getBytesCopy()
public String getString()
public void setScheme(String scheme)
scheme - the new schemepublic void setHost(String host)
host - the new hostpublic void setPort(int port)
port - the new portpublic void setDn(Dn dn)
dn - the new dnpublic void setAttributes(List<String> attributes)
attributes - the new attributespublic void setScope(int scope)
SearchScope.OBJECT,
SearchScope.ONELEVEL or SearchScope.SUBTREE,
otherwise SearchScope.OBJECT is assumed as default.scope - the new scopepublic void setScope(SearchScope scope)
SearchScope.OBJECT,
SearchScope.ONELEVEL or SearchScope.SUBTREE,
otherwise SearchScope.OBJECT is assumed as default.scope - the new scopepublic void setFilter(String filter)
filter - the new filterpublic void setForceScopeRendering(boolean forceScopeRendering)
forceScopeRendering - the forceScopeRendering to setCopyright © 2003–2022 The Apache Software Foundation. All rights reserved.